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

Fix data/utils dtype warning for float64 inputs. #675

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions kauldron/data/utils.py
Original file line number Diff line number Diff line change
@@ -68,8 +68,13 @@ def array_spec_to_jnp_empty(spec: ArraySpec, batch_dim: int = 17) -> jax.Array:
Returns:
An empty jnp array with the requested shape and dtype.
"""
# silently convert int64 -> int32 to avoid jax warning
dtype = jnp.int32 if spec.dtype in [jnp.int64, np.int64] else spec.dtype
# silently convert int64 -> int32 and float64 -> float32 to avoid jax warning
if spec.dtype in [jnp.int64, np.int64]:
dtype = jnp.int32
elif spec.dtype in [jnp.float64, np.float64]:
dtype = jnp.float32
else:
dtype = spec.dtype

if spec.shape[0] is None:
return jnp.empty((batch_dim,) + spec.shape[1:], dtype)