Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 14 additions & 5 deletions effectful/handlers/jax/monoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,21 @@


def _jax_args(args):
"""True iff ``args`` is non-empty and every arg is a concrete
:class:`jax.typing.ArrayLike` or named tensor.

"""True iff ``args`` is non-empty, every arg is a concrete
:class:`jax.typing.ArrayLike` or named tensor, and at least one of them is
an array rather than a Python scalar.

:class:`jax.typing.ArrayLike` is a union that includes ``bool``, ``int``,
``float`` and ``complex``, so admitting it alone would claim pure-Python
scalar arithmetic. These handlers extend ``EvaluateIntp`` after the scalar
implementations and so take precedence over them, which would silently
narrow a Python float to a ``float32`` array and leave downstream rules
treating a scalar body as array-valued.
"""
return args and all(
isinstance(a, jax.typing.ArrayLike) or is_eager_array(a) for a in args
return (
args
and all(isinstance(a, jax.typing.ArrayLike) or is_eager_array(a) for a in args)
and any(not isinstance(a, bool | int | float | complex) for a in args)
)


Expand Down
Loading
Loading