Skip to content
Merged
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
58 changes: 0 additions & 58 deletions .basedpyright/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2542,24 +2542,6 @@
}
}
],
"./pymbolic/geometric_algebra/primitives.py": [
{
"code": "reportUnknownParameterType",
"range": {
"startColumn": 26,
"endColumn": 49,
"lineCount": 1
}
},
{
"code": "reportMissingParameterType",
"range": {
"startColumn": 26,
"endColumn": 49,
"lineCount": 1
}
}
],
"./pymbolic/imperative/instruction.py": [
{
"code": "reportUnusedImport",
Expand Down Expand Up @@ -8455,14 +8437,6 @@
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 19,
"endColumn": 40,
"lineCount": 1
}
},
{
"code": "reportArgumentType",
"range": {
Expand Down Expand Up @@ -8709,38 +8683,6 @@
"lineCount": 1
}
},
{
"code": "reportUnknownParameterType",
"range": {
"startColumn": 31,
"endColumn": 54,
"lineCount": 1
}
},
{
"code": "reportMissingParameterType",
"range": {
"startColumn": 31,
"endColumn": 54,
"lineCount": 1
}
},
{
"code": "reportUnusedParameter",
"range": {
"startColumn": 31,
"endColumn": 54,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 15,
"endColumn": 36,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
Expand Down
18 changes: 13 additions & 5 deletions pymbolic/geometric_algebra/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,28 @@ def map_derivative_source(
return type(expr)(operand, expr.nabla_id)


class StringifyMapper(StringifyMapperBase[[]]):
class StringifyMapper(StringifyMapperBase[P]):
AXES: ClassVar[dict[int, str]] = {0: "x", 1: "y", 2: "z"}

def map_nabla(self, expr: gp.Nabla, /, enclosing_prec: int) -> str:
def map_nabla(self,
expr: gp.Nabla,
/, enclosing_prec: int,
*args: P.args, **kwargs: P.kwargs
) -> str:
return f"∇[{expr.nabla_id}]"

def map_nabla_component(
self, expr: gp.NablaComponent, /, enclosing_prec: int) -> str:
self, expr: gp.NablaComponent, /, enclosing_prec: int,
*args: P.args, **kwargs: P.kwargs,
) -> str:
axis = self.AXES.get(expr.ambient_axis, expr.ambient_axis)
return f"∇{axis}[{expr.nabla_id}]"

def map_derivative_source(
self, expr: gp.DerivativeSource, /, enclosing_prec: int) -> str:
operand = self.rec(expr.operand, PREC_NONE)
self, expr: gp.DerivativeSource, /, enclosing_prec: int,
*args: P.args, **kwargs: P.kwargs,
) -> str:
operand = self.rec(expr.operand, PREC_NONE, *args, **kwargs)
return f"D[{expr.nabla_id}]({operand})"


Expand Down
11 changes: 9 additions & 2 deletions pymbolic/geometric_algebra/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
# Consider yourself warned.

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, ClassVar, TypeAlias
from typing import TYPE_CHECKING, ClassVar, ParamSpec, TypeAlias

from typing_extensions import override

import pytools.obj_array as obj_array

Expand All @@ -38,6 +40,7 @@
if TYPE_CHECKING:
from collections.abc import Hashable

from pymbolic.mapper.stringifier import StringifyMapper
from pymbolic.typing import (
ArithmeticExpression,
ArithmeticExpressionContainerTc,
Expand All @@ -46,6 +49,7 @@


NablaId: TypeAlias = "Hashable"
P = ParamSpec("P")


class MultiVectorVariable(Variable):
Expand All @@ -55,7 +59,10 @@ class MultiVectorVariable(Variable):
# {{{ geometric calculus

class _GeometricCalculusExpression(ExpressionNode):
def stringifier(self, originating_stringifier=None):
@override
def make_stringifier(self,
originating_stringifier: StringifyMapper[P] | None = None
) -> StringifyMapper[P]:
from pymbolic.geometric_algebra.mapper import StringifyMapper
return StringifyMapper()

Expand Down
8 changes: 7 additions & 1 deletion pymbolic/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Any,
ClassVar,
NoReturn,
ParamSpec,
Protocol,
TypeAlias,
cast,
Expand All @@ -58,12 +59,15 @@
from .typing import ArithmeticExpression, Expression as _Expression, Number, Scalar


P = ParamSpec("P")

if TYPE_CHECKING:
from collections.abc import Callable, Iterable, Mapping

from _typeshed import DataclassInstance

from pymbolic.geometric_algebra import MultiVector
from pymbolic.mapper.stringifier import StringifyMapper


def _have_numpy() -> bool:
Expand Down Expand Up @@ -663,7 +667,9 @@ def __float__(self) -> float:
from pymbolic.mapper.evaluator import evaluate_to_float
return evaluate_to_float(self)

def make_stringifier(self, originating_stringifier=None):
def make_stringifier(self,
originating_stringifier: StringifyMapper[P] | None = None
) -> StringifyMapper[P]:
"""Return a :class:`pymbolic.mapper.Mapper` instance that can
be used to generate a human-readable representation of *self*. Usually
a subclass of :class:`pymbolic.mapper.stringifier.StringifyMapper`.
Expand Down
Loading