Skip to content

Commit

Permalink
Merge pull request #25969 from jakevdp:fix-util
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 717104490
  • Loading branch information
Google-ML-Automation committed Jan 19, 2025
2 parents cc38d8c + 45a3520 commit aed9c6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 4 additions & 2 deletions jax/_src/lax/lax.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ def asarray(x: ArrayLike) -> Array:
"""Lightweight conversion of ArrayLike input to Array output."""
if isinstance(x, Array):
return x
if isinstance(x, (np.ndarray, np.generic, bool, int, float, builtins.complex)):
return _convert_element_type(x, weak_type=dtypes.is_weakly_typed(x)) # type: ignore[unused-ignore,bad-return-type]
elif isinstance(x, (bool, np.ndarray, np.generic)):
return _convert_element_type(x, weak_type=False) # type: ignore[bad-return-type]
elif isinstance(x, (int, float, builtins.complex)):
return _convert_element_type(dtypes.coerce_to_array(x), weak_type=True) # type: ignore[bad-return-type]
else:
raise TypeError(f"asarray: expected ArrayLike, got {x} of type {type(x)}.")

Expand Down
2 changes: 0 additions & 2 deletions jax/_src/numpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ def _arraylike_asarray(x: Any) -> Array:
"""Convert an array-like object to an array."""
if hasattr(x, '__jax_array__'):
x = x.__jax_array__()
elif isinstance(x, (bool, int, float, complex)):
x = dtypes.coerce_to_array(x)
return lax.asarray(x)


Expand Down

0 comments on commit aed9c6f

Please sign in to comment.