Skip to content

Use jnp.zeros rather than jnp.empty in places where values are important.#51

Open
copybara-service[bot] wants to merge 1 commit intomainfrom
test_900399273
Open

Use jnp.zeros rather than jnp.empty in places where values are important.#51
copybara-service[bot] wants to merge 1 commit intomainfrom
test_900399273

Conversation

@copybara-service
Copy link
Copy Markdown

Use jnp.zeros rather than jnp.empty in places where values are important.

Why? JAX has always lowered jnp.empty to jnp.zeros, because in early versions of XLA there was no way to create an uninitialized buffer. In a future JAX release, jnp.empty will lower to jax.lax.empty, which creates an uninitialized buffer. This is closer to the intent of jnp.empty, and can lead to more efficient code when the author knows that initializing the array is not required.

These problematic uses were detected by temporarily making jnp.empty return NaN (for float & complex dtypes) or the maximum value (for int and bool dtypes), and running global presubmit tests.

…portant.

Why? JAX has always lowered `jnp.empty` to `jnp.zeros`, because in early versions of XLA there was no way to create an uninitialized buffer. In a future JAX release, `jnp.empty` will lower to `jax.lax.empty`, which creates an uninitialized buffer. This is closer to the intent of `jnp.empty`, and can lead to more efficient code when the author knows that initializing the array is not required.

These problematic uses were detected by temporarily making `jnp.empty` return `NaN` (for float & complex dtypes) or the maximum value (for int and bool dtypes), and running global presubmit tests.

PiperOrigin-RevId: 900399273
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants