From a99df5e420dc2fb37c1d3f279200805fb8315866 Mon Sep 17 00:00:00 2001 From: J08nY Date: Fri, 6 Oct 2023 15:43:59 +0200 Subject: Add numpy typing plugin to mypy. --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) 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" -- cgit v1.3.1 From 3f89136bfdd0bbfa5efe0c7e75d2fb587bc79e32 Mon Sep 17 00:00:00 2001 From: J08nY Date: Fri, 6 Oct 2023 19:23:14 +0200 Subject: Do not print full perf logs in pyinstrument. --- .pre-commit-config.yaml | 1 + test/utils.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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/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") -- cgit v1.3.1 From 0e300b7b532d1796fc2dbea6f09e326b856f866a Mon Sep 17 00:00:00 2001 From: J08nY Date: Fri, 6 Oct 2023 22:45:12 +0200 Subject: Cache sympify results to speedup formula exec. --- pyecsca/ec/curve.py | 3 ++- pyecsca/ec/formula.py | 3 ++- pyecsca/ec/params.py | 3 ++- pyecsca/misc/cache.py | 12 ++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 pyecsca/misc/cache.py 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) -- cgit v1.3.1