Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .basedpyright/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -9608,16 +9608,16 @@
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 39,
"endColumn": 49,
"startColumn": 33,
"endColumn": 43,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 51,
"endColumn": 61,
"startColumn": 45,
"endColumn": 55,
"lineCount": 1
}
},
Expand Down
2 changes: 1 addition & 1 deletion pymbolic/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
`Wikipedia article on the Euclidean algorithm
<https://en.wikipedia.org/wiki/Euclidean_algorithm>`__.
"""
import pymbolic.traits as traits
from pymbolic import traits

# see [Davenport], Appendix, p. 214

Expand Down Expand Up @@ -298,7 +298,7 @@
return x

return NearZeroKiller()(
fft(wrap_intermediate_with_level(0, x), sign=sign,

Check warning on line 301 in pymbolic/algorithm.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

Not supplying complex_dtype is deprecated, falling back to complex128 for now. This will stop working in 2023.

Check warning on line 301 in pymbolic/algorithm.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

Not supplying complex_dtype is deprecated, falling back to complex128 for now. This will stop working in 2023.
wrap_intermediate_with_level=wrap_intermediate_with_level))

# }}}
Expand Down
27 changes: 13 additions & 14 deletions pymbolic/geometric_algebra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
import numpy as np
from typing_extensions import Self, override

import pytools.obj_array as obj_array
from pytools import memoize, memoize_method
from pytools import memoize, memoize_method, obj_array
from pytools.obj_array import ObjectArray, ObjectArray1D, ShapeT

from pymbolic.primitives import expr_dataclass, is_zero
Expand Down Expand Up @@ -1103,10 +1102,10 @@ def project(self, r: int) -> MultiVector[CoeffT]:

Often written :math:`\langle A\rangle_r`.
"""
new_data: dict[int, CoeffT] = {}
for bits, coeff in self.data.items():
if bits.bit_count() == r:
new_data[bits] = coeff
new_data: dict[int, CoeffT] = {
bits: coeff for bits, coeff in self.data.items()
if bits.bit_count() == r
}

return MultiVector(new_data, self.space)

Expand Down Expand Up @@ -1161,19 +1160,19 @@ def get_pure_grade(self) -> int | None:

def odd(self) -> MultiVector[CoeffT]:
"""Extract the odd-grade blades."""
new_data: dict[int, CoeffT] = {}
for bits, coeff in self.data.items():
if bits.bit_count() % 2:
new_data[bits] = coeff
new_data: dict[int, CoeffT] = {
bits: coeff for bits, coeff in self.data.items()
if bits.bit_count() % 2 == 1
}

return MultiVector(new_data, self.space)

def even(self) -> MultiVector[CoeffT]:
"""Extract the even-grade blades."""
new_data: dict[int, CoeffT] = {}
for bits, coeff in self.data.items():
if bits.bit_count() % 2 == 0:
new_data[bits] = coeff
new_data: dict[int, CoeffT] = {
bits: coeff for bits, coeff in self.data.items()
if bits.bit_count() % 2 == 0
}

return MultiVector(new_data, self.space)

Expand Down
2 changes: 1 addition & 1 deletion pymbolic/geometric_algebra/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from typing_extensions import Self, override

import pytools.obj_array as obj_array
from pytools import obj_array

import pymbolic.geometric_algebra.primitives as gp
from pymbolic.geometric_algebra import MultiVector
Expand Down
2 changes: 1 addition & 1 deletion pymbolic/geometric_algebra/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from typing_extensions import override

import pytools.obj_array as obj_array
from pytools import obj_array

from pymbolic.geometric_algebra import MultiVector
from pymbolic.primitives import ExpressionNode, Variable, expr_dataclass
Expand Down
10 changes: 5 additions & 5 deletions pymbolic/interop/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
from pymbolic.geometric_algebra import MultiVector

# NOTE: these are removed in Python 3.14
if sys.version_info < (3, 14):
if sys.version_info >= (3, 14):
AstNum: TypeAlias = Any
AstStr: TypeAlias = Any
AstBytes: TypeAlias = Any
else:
from ast import (
Bytes as AstBytes, # pyright: ignore[reportDeprecated]
Num as AstNum, # pyright: ignore[reportDeprecated]
Str as AstStr, # pyright: ignore[reportDeprecated]
)
else:
AstNum: TypeAlias = Any
AstStr: TypeAlias = Any
AstBytes: TypeAlias = Any

__doc__ = r'''
An example:
Expand Down
2 changes: 1 addition & 1 deletion pymbolic/mapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
else:
return self.handle_unsupported_expression(expr, *args, **kwargs)
else:
return self.map_foreign(expr, *args, **kwargs)

Check warning on line 208 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 208 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 208 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 208 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

rec = __call__
"""Identical to :meth:`__call__`, but intended for use in recursive dispatch
Expand Down Expand Up @@ -1441,7 +1441,7 @@
if not self.visit(expr, *args, **kwargs):
return

for _bits, coeff in expr.data.items():
for coeff in expr.data.values():
self.rec(coeff, *args, **kwargs)

self.post_visit(expr, *args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions pymbolic/mapper/coefficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def map_quotient(self, expr: p.Quotient, /) -> CoeffsT:
if len(d_den) > 1 or 1 not in d_den:
raise RuntimeError("nonlinear expression")
val = d_den[1]
for k in d_num:
d_num[k] = p.flattened_product((d_num[k], p.Quotient(1, val)))
for k, v in d_num.items():
d_num[k] = p.flattened_product((v, p.Quotient(1, val)))
return d_num

@override
Expand Down
9 changes: 2 additions & 7 deletions pymbolic/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
from constantdict import constantdict
from typing_extensions import Self, TypeIs, dataclass_transform, override

import pytools.obj_array as obj_array
from pytools import T, module_getattr_for_deprecations, ndindex
from pytools import T, module_getattr_for_deprecations, ndindex, obj_array
from pytools.obj_array import (
ObjectArray,
ObjectArray1D,
Expand Down Expand Up @@ -909,7 +908,7 @@ def __iter__(self) -> NoReturn:
(?<=[A-Z]) # preceded by lowercase
(?=[A-Z][a-z]) # followed by uppercase, then lowercase
""",
re.X,
re.VERBOSE,
)


Expand Down Expand Up @@ -1123,14 +1122,12 @@ class AlgebraicLeaf(ExpressionNode):
"""An expression that serves as a leaf for arithmetic evaluation.
This may end up having child nodes still, but they're not reached by
ways of arithmetic."""
pass


@expr_dataclass()
class Leaf(AlgebraicLeaf):
"""An expression that is irreducible, i.e. has no Expression-type parts
whatsoever."""
pass


@expr_dataclass()
Expand Down Expand Up @@ -1807,8 +1804,6 @@ def quotient(numerator: ArithmeticExpression,

# {{{ tool functions

global VALID_CONSTANT_CLASSES
global VALID_OPERANDS
VALID_CONSTANT_CLASSES: tuple[type, ...] = (int, float, complex)
_BOOL_CLASSES: tuple[type, ...] = (bool,)
VALID_OPERANDS = (ExpressionNode,)
Expand Down
16 changes: 8 additions & 8 deletions pymbolic/rational.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

from sys import intern

import pymbolic.primitives as primitives
import pymbolic.traits as traits
import pymbolic.primitives as prim
from pymbolic import traits


class Rational(primitives.ExpressionNode):
class Rational(prim.ExpressionNode):
def __init__(self, numerator, denominator=1):
d_unit = traits.traits(denominator).get_unit(denominator)
numerator /= d_unit
Expand Down Expand Up @@ -67,11 +67,11 @@ def __add__(self, other):
newnum = self.Numerator * newden/self.Denominator + \
newother.Numerator * newden/newother.Denominator
gcd = t.gcd(newden, newnum)
return primitives.quotient(newnum/gcd, newden/gcd)
return prim.quotient(newnum/gcd, newden/gcd)
except traits.NoTraitsError:
return primitives.ExpressionNode.__add__(self, other)
return prim.Sum((self, other))
except traits.NoCommonTraitsError:
return primitives.ExpressionNode.__add__(self, other)
return prim.Sum((self, other))

__radd__ = __add__

Expand All @@ -98,9 +98,9 @@ def __mul__(self, other):

return Rational(new_num, new_denom)
except traits.NoTraitsError:
return primitives.ExpressionNode.__mul__(self, other)
return prim.Product((self, other))
except traits.NoCommonTraitsError:
return primitives.ExpressionNode.__mul__(self, other)
return prim.Product((self, other))

__rmul__ = __mul__

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exclude = [
preview = true

[tool.ruff.lint]
extend-select = [
select = [
"B", # flake8-bugbear
"C", # flake8-comprehensions
"E", # pycodestyle
Expand Down
6 changes: 3 additions & 3 deletions test/test_maxima.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def test_strict_round_trip(knl: MaximaKernel) -> None:
round_trips_correctly = result == expr
if not round_trips_correctly:
print("ORIGINAL:")
print("")
print()
print(expr)
print("")
print()
print("POST-MAXIMA:")
print("")
print()
print(result)
assert round_trips_correctly

Expand Down
Loading