aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Bátora2023-10-10 15:00:25 +0200
committerGitHub2023-10-10 15:00:25 +0200
commit79ec70d0b1acf681f73d478e775825a6f35ae1e6 (patch)
tree77750148677c9168146a30a56350df8332ed144b
parent6cd42203f314650199ef1ef8764e8bfdd1aeb3ae (diff)
parent0e300b7b532d1796fc2dbea6f09e326b856f866a (diff)
downloadpyecsca-79ec70d0b1acf681f73d478e775825a6f35ae1e6.tar.gz
pyecsca-79ec70d0b1acf681f73d478e775825a6f35ae1e6.tar.zst
pyecsca-79ec70d0b1acf681f73d478e775825a6f35ae1e6.zip
Merge branch 'J08nY:master' into CPA_pyecsca
-rw-r--r--.pre-commit-config.yaml1
-rw-r--r--pyecsca/ec/curve.py3
-rw-r--r--pyecsca/ec/formula.py3
-rw-r--r--pyecsca/ec/params.py3
-rw-r--r--pyecsca/misc/cache.py12
-rw-r--r--pyproject.toml3
-rw-r--r--test/utils.py2
7 files changed, 23 insertions, 4 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 1969532..de79e4a 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -16,6 +16,7 @@ repos:
- id: mypy
additional_dependencies:
- "types-setuptools"
+ - "numpy"
args: [--ignore-missing-imports, --show-error-codes, --namespace-packages, --explicit-package-bases, --check-untyped-defs]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
diff --git a/pyecsca/ec/curve.py b/pyecsca/ec/curve.py
index 8cc7dba..b69bc9b 100644
--- a/pyecsca/ec/curve.py
+++ b/pyecsca/ec/curve.py
@@ -5,7 +5,8 @@ from copy import copy
from typing import MutableMapping, Union, List, Optional, Dict, Set
from public import public
-from sympy import FF, sympify
+from sympy import FF
+from ..misc.cache import sympify
from .coordinates import CoordinateModel, AffineCoordinateModel
from .error import raise_unsatisified_assumption
diff --git a/pyecsca/ec/formula.py b/pyecsca/ec/formula.py
index 3e825e4..ed3afb5 100644
--- a/pyecsca/ec/formula.py
+++ b/pyecsca/ec/formula.py
@@ -9,7 +9,8 @@ from typing import List, Set, Any, ClassVar, MutableMapping, Tuple, Union, Dict
from importlib_resources.abc import Traversable
from public import public
-from sympy import sympify, FF, symbols, Poly, Rational
+from sympy import FF, symbols, Poly, Rational
+from ..misc.cache import sympify
from .context import ResultAction
from . import context
diff --git a/pyecsca/ec/params.py b/pyecsca/ec/params.py
index 54656d4..3a6a54d 100644
--- a/pyecsca/ec/params.py
+++ b/pyecsca/ec/params.py
@@ -5,7 +5,7 @@ It also provides a domain parameter class and a class for a whole category of do
"""
import json
import csv
-from sympy import Poly, FF, symbols, sympify
+from sympy import Poly, FF, symbols
from astunparse import unparse
from io import RawIOBase, BufferedIOBase
from pathlib import Path
@@ -14,6 +14,7 @@ from importlib_resources import files
from public import public
+from ..misc.cache import sympify
from .coordinates import AffineCoordinateModel, CoordinateModel
from .curve import EllipticCurve
from .error import raise_unsatisified_assumption
diff --git a/pyecsca/misc/cache.py b/pyecsca/misc/cache.py
new file mode 100644
index 0000000..385ff4b
--- /dev/null
+++ b/pyecsca/misc/cache.py
@@ -0,0 +1,12 @@
+"""Cache some things."""
+from functools import lru_cache
+from sympy import sympify as _orig_sympify
+from public import public
+
+
+@public
+@lru_cache(maxsize=256, typed=True)
+def sympify(
+ a, locals=None, convert_xor=True, strict=False, rational=False, evaluate=None
+):
+ return _orig_sympify(a, locals, convert_xor, strict, rational, evaluate)
diff --git a/pyproject.toml b/pyproject.toml
index b95284c..db8f165 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -81,3 +81,6 @@ markers = [
filterwarnings = [
"ignore:Deprecated call to `pkg_resources.declare_namespace"
]
+
+[tool.mypy]
+plugins = "numpy.typing.mypy_plugin"
diff --git a/test/utils.py b/test/utils.py
index e125813..d4893eb 100644
--- a/test/utils.py
+++ b/test/utils.py
@@ -62,7 +62,7 @@ class Profiler:
if self._state != "out":
raise ValueError
if self._prof_type == "py":
- print(self._prof.output_text(unicode=True, color=True, show_all=True))
+ print(self._prof.output_text(unicode=True, color=True))
else:
self._prof.print_stats("cumtime")