diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 93caa46..e6b80da 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -7654,72 +7654,80 @@ { "code": "reportUnknownArgumentType", "range": { - "startColumn": 36, - "endColumn": 40, + "startColumn": 16, + "endColumn": 20, "lineCount": 1 } }, { "code": "reportUnknownArgumentType", "range": { - "startColumn": 42, - "endColumn": 46, + "startColumn": 16, + "endColumn": 20, "lineCount": 1 } }, { "code": "reportUnknownArgumentType", "range": { - "startColumn": 20, - "endColumn": 48, - "lineCount": 3 + "startColumn": 16, + "endColumn": 82, + "lineCount": 1 + } + }, + { + "code": "reportUnknownArgumentType", + "range": { + "startColumn": 29, + "endColumn": 81, + "lineCount": 1 } }, { "code": "reportUnknownMemberType", "range": { - "startColumn": 24, - "endColumn": 30, + "startColumn": 30, + "endColumn": 36, "lineCount": 1 } }, { "code": "reportUnknownMemberType", "range": { - "startColumn": 32, - "endColumn": 40, + "startColumn": 38, + "endColumn": 46, "lineCount": 1 } }, { "code": "reportUnknownMemberType", "range": { - "startColumn": 41, - "endColumn": 49, + "startColumn": 47, + "endColumn": 55, "lineCount": 1 } }, { "code": "reportUnknownArgumentType", "range": { - "startColumn": 41, - "endColumn": 49, + "startColumn": 47, + "endColumn": 55, "lineCount": 1 } }, { "code": "reportUnknownVariableType", "range": { - "startColumn": 28, - "endColumn": 30, + "startColumn": 61, + "endColumn": 63, "lineCount": 1 } }, { "code": "reportUnknownMemberType", "range": { - "startColumn": 34, - "endColumn": 47, + "startColumn": 67, + "endColumn": 80, "lineCount": 1 } }, @@ -32099,14 +32107,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 4, - "endColumn": 9, - "lineCount": 1 - } - }, { "code": "reportUnknownVariableType", "range": { @@ -32132,7 +32132,7 @@ } }, { - "code": "reportAny", + "code": "reportUnknownVariableType", "range": { "startColumn": 8, "endColumn": 9, @@ -32142,7 +32142,7 @@ { "code": "reportAny", "range": { - "startColumn": 12, + "startColumn": 23, "endColumn": 24, "lineCount": 1 } @@ -32150,32 +32150,8 @@ { "code": "reportAny", "range": { - "startColumn": 12, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 38, - "endColumn": 50, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 38, - "endColumn": 55, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 18, - "endColumn": 19, + "startColumn": 42, + "endColumn": 43, "lineCount": 1 } }, @@ -32183,47 +32159,15 @@ "code": "reportUnknownVariableType", "range": { "startColumn": 8, - "endColumn": 10, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 23, - "endColumn": 27, + "endColumn": 11, "lineCount": 1 } }, { - "code": "reportAny", + "code": "reportUnknownVariableType", "range": { "startColumn": 8, - "endColumn": 17, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 20, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 20, - "endColumn": 33, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 23, - "endColumn": 36, + "endColumn": 10, "lineCount": 1 } }, @@ -32275,14 +32219,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 4, - "endColumn": 9, - "lineCount": 1 - } - }, { "code": "reportUnknownVariableType", "range": { @@ -32299,46 +32235,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 4, - "endColumn": 8, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 11, - "endColumn": 22, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 28, - "endColumn": 32, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 31, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 25, - "endColumn": 29, - "lineCount": 1 - } - }, { "code": "reportUnknownArgumentType", "range": { @@ -32611,6 +32507,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 8, + "lineCount": 1 + } + }, { "code": "reportUnknownArgumentType", "range": { @@ -32619,6 +32523,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 8, + "lineCount": 1 + } + }, { "code": "reportUnknownArgumentType", "range": { @@ -32627,6 +32539,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 8, + "lineCount": 1 + } + }, { "code": "reportUnknownArgumentType", "range": { @@ -32635,6 +32555,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 8, + "lineCount": 1 + } + }, { "code": "reportUnknownArgumentType", "range": { @@ -32643,6 +32571,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 8, + "lineCount": 1 + } + }, { "code": "reportUnknownArgumentType", "range": { @@ -32667,6 +32603,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 4, + "endColumn": 8, + "lineCount": 1 + } + }, { "code": "reportAny", "range": { @@ -32707,6 +32651,30 @@ "lineCount": 1 } }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 8, + "endColumn": 9, + "lineCount": 1 + } + }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 11, + "endColumn": 12, + "lineCount": 1 + } + }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 14, + "endColumn": 15, + "lineCount": 1 + } + }, { "code": "reportUnknownMemberType", "range": { @@ -32811,6 +32779,30 @@ "lineCount": 1 } }, + { + "code": "reportUnknownMemberType", + "range": { + "startColumn": 21, + "endColumn": 24, + "lineCount": 1 + } + }, + { + "code": "reportUnknownMemberType", + "range": { + "startColumn": 45, + "endColumn": 48, + "lineCount": 1 + } + }, + { + "code": "reportUnknownVariableType", + "range": { + "startColumn": 12, + "endColumn": 15, + "lineCount": 1 + } + }, { "code": "reportUnknownMemberType", "range": { @@ -32819,6 +32811,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownMemberType", + "range": { + "startColumn": 43, + "endColumn": 49, + "lineCount": 1 + } + }, { "code": "reportUnknownMemberType", "range": { @@ -32883,6 +32883,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownMemberType", + "range": { + "startColumn": 38, + "endColumn": 41, + "lineCount": 1 + } + }, { "code": "reportUnknownMemberType", "range": { @@ -32891,6 +32899,14 @@ "lineCount": 1 } }, + { + "code": "reportUnknownMemberType", + "range": { + "startColumn": 36, + "endColumn": 39, + "lineCount": 1 + } + }, { "code": "reportUnknownMemberType", "range": { diff --git a/pymbolic/interop/ast.py b/pymbolic/interop/ast.py index d2b599b..8057395 100644 --- a/pymbolic/interop/ast.py +++ b/pymbolic/interop/ast.py @@ -29,6 +29,7 @@ import ast from typing import TYPE_CHECKING, Any, ClassVar +from constantdict import constantdict from typing_extensions import override import pymbolic.primitives as p @@ -203,10 +204,10 @@ def map_Call(self, expr): func = self.rec(expr.func) args = tuple([self.rec(arg) for arg in expr.args]) if getattr(expr, "keywords", []): - return p.CallWithKwargs(func, args, - { - kw.arg: self.rec(kw.value) - for kw in expr.keywords}) + return p.CallWithKwargs( + func, + args, + constantdict({kw.arg: self.rec(kw.value) for kw in expr.keywords})) else: return p.Call(func, args) diff --git a/pyproject.toml b/pyproject.toml index 1bdd24a..f279f5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,12 +72,14 @@ extend-select = [ "G", # flake8-logging-format "I", # flake8-isort "N", # pep8-naming + "NPY", # numpy + "PGH", # pygrep-hooks "Q", # flake8-quotes "RUF", # ruff + "SIM", # flake8-simplify + "TC", # flake8-type-checking "UP", # pyupgrade "W", # pycodestyle - "TC", # type checking - "SIM", ] extend-ignore = [ "C409", # remove comprehension within tuple call diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py index 850599b..32a606a 100644 --- a/test/test_pymbolic.py +++ b/test/test_pymbolic.py @@ -195,19 +195,21 @@ def test_sympy_interaction(): # {{{ fft def test_fft_with_floats(): - numpy = pytest.importorskip("numpy") - import numpy.linalg as la + pytest.importorskip("numpy") + + import numpy as np from pymbolic.algorithm import fft, ifft + rng = np.random.default_rng(seed=42) for n in [2**i for i in range(4, 10)]+[17, 12, 948]: - a = numpy.random.rand(n) + 1j*numpy.random.rand(n) - f_a = fft(a) - a2 = ifft(f_a) - assert la.norm(a-a2) < 1e-10 + a = rng.random(n) + 1j*rng.random(n) + f_a = fft(a, complex_dtype=np.complex128) + a2 = ifft(f_a, complex_dtype=np.complex128) + assert np.linalg.norm(a-a2) < 1e-10 - f_a_numpy = numpy.fft.fft(a) - assert la.norm(f_a-f_a_numpy) < 1e-10 + f_a_numpy = np.fft.fft(a) + assert np.linalg.norm(f_a-f_a_numpy) < 1e-10 class NearZeroKiller(IdentityMapper): @@ -225,15 +227,17 @@ def map_constant(self, expr): def test_fft(): - numpy = pytest.importorskip("numpy") + pytest.importorskip("numpy") + + import numpy as np from pymbolic import var from pymbolic.algorithm import fft, sym_fft - vars = numpy.array([var(chr(97+i)) for i in range(16)], dtype=object) + vars = np.array([var(chr(97+i)) for i in range(16)], dtype=object) logger.info("vars: %s", vars) - logger.info("fft: %s", fft(vars)) + logger.info("fft: %s", fft(vars, complex_dtype=np.complex128)) traced_fft = sym_fft(vars) from pymbolic.mapper.c_code import CCodeMapper @@ -420,11 +424,12 @@ def test_geometric_algebra(dims): from pymbolic.geometric_algebra import MultiVector as MV # noqa: N817 - vec1 = MV(np.random.randn(dims)) - vec2 = MV(np.random.randn(dims)) - vec3 = MV(np.random.randn(dims)) - vec4 = MV(np.random.randn(dims)) - vec5 = MV(np.random.randn(dims)) + rng = np.random.default_rng(seed=dims) + vec1 = MV(rng.normal(size=dims)) + vec2 = MV(rng.normal(size=dims)) + vec3 = MV(rng.normal(size=dims)) + vec4 = MV(rng.normal(size=dims)) + vec5 = MV(rng.normal(size=dims)) # Fundamental identity assert ((vec1 ^ vec2) + (vec1 | vec2)).close_to(vec1*vec2)