Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RealNumber #167

Merged
merged 2 commits into from
Nov 28, 2024
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
2 changes: 2 additions & 0 deletions pymbolic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
Expression,
Expression as _TypingExpression,
Number,
RealNumber,
Scalar,
)
from pymbolic.version import VERSION_TEXT as __version__ # noqa
Expand All @@ -77,6 +78,7 @@
"Expression",
"ExpressionNode",
"Number",
"RealNumber",
"Scalar",
"Variable",
"compile",
Expand Down
3 changes: 2 additions & 1 deletion pymbolic/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ def disable_subscript_by_getitem():

# https://stackoverflow.com/a/13624858
class _classproperty(property): # noqa: N801
def __get__(self, owner_self, owner_cls):
def __get__(self, owner_self: Any, owner_cls: type | None = None) -> Any:
assert self.fget is not None
return self.fget(owner_cls)


Expand Down
16 changes: 12 additions & 4 deletions pymbolic/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

.. currentmodule:: pymbolic

.. autoclass:: Bool
.. autoclass:: Number
.. autoclass:: Scalar
.. autodata:: Bool
.. autodata:: RealNumber

Mainly distinguished from :data:`Number` by having a total ordering, i.e.
not including the complex numbers.

.. autodata:: Number
.. autodata:: Scalar
.. autodata:: ArithmeticExpression

A narrower type alias than :class:`~pymbolic.typing.Expression` that is returned
Expand Down Expand Up @@ -88,19 +93,22 @@
if TYPE_CHECKING:
# Yes, type-checking pymbolic will require numpy. That's OK.
import numpy as np
Bool = bool | np.bool_
Bool: TypeAlias = bool | np.bool_
Integer: TypeAlias = int | np.integer
RealNumber: TypeAlias = Integer | float | np.floating
InexactNumber: TypeAlias = _StdlibInexactNumberT | np.inexact
else:
try:
import numpy as np
except ImportError:
Bool = bool
Integer: TypeAlias = int
RealNumber: TypeAlias = Integer | float
InexactNumber: TypeAlias = _StdlibInexactNumberT
else:
Bool = bool | np.bool_
Integer: TypeAlias = int | np.integer
RealNumber: TypeAlias = Integer | float | np.floating
InexactNumber: TypeAlias = _StdlibInexactNumberT | np.inexact


Expand Down
Loading