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

Casted finfo attributes from np.float to float for Array API compliance #21424

Closed
wants to merge 1 commit into from
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
10 changes: 9 additions & 1 deletion jax/_src/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,15 @@ def coerce_to_array(x: Any, dtype: DTypeLike | None = None) -> np.ndarray:
return np.asarray(x, dtype)

iinfo = ml_dtypes.iinfo
finfo = ml_dtypes.finfo

# We cast finfo attributes from np.float to built-in python floats
# for Array API compliance
class finfo(ml_dtypes.finfo):
def __setattr__(self, name, value):
if isinstance(value, np.floating):
value = float(value)
object.__setattr__(self, name, value)


def _issubclass(a: Any, b: Any) -> bool:
"""Determines if ``a`` is a subclass of ``b``.
Expand Down
2 changes: 0 additions & 2 deletions jax/experimental/array_api/_data_type_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class FInfo(NamedTuple):
smallest_normal: float
dtype: jnp.dtype

# TODO(micky774): Update jax.numpy.finfo so that its attributes are python
# floats
def finfo(type, /) -> FInfo:
info = jnp.finfo(type)
return FInfo(
Expand Down