Skip to content

Commit c847a41

Browse files
vanderplastensorflower-gardener
authored andcommitted
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. PiperOrigin-RevId: 900691452
1 parent 413c164 commit c847a41

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tensorflow_probability/python/internal/backend/numpy/tensor_array_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self,
5454
self._dtype = utils.numpy_dtype(dtype)
5555
if data is None:
5656
if JAX_MODE and size is not None and element_shape is not None:
57-
data = np.empty((size,) + tuple(element_shape), dtype=self._dtype)
57+
data = np.zeros((size,) + tuple(element_shape), dtype=self._dtype)
5858
# Can be useful for finding failure cases in JAX TensorArray-using code.
5959
# elif JAX_MODE:
6060
# raise ValueError(

0 commit comments

Comments
 (0)