jax.numpy.spacing — JAX documentation (original) (raw)
jax.numpy.spacing#
jax.numpy.spacing(x, /)[source]#
Return the spacing between x and the next adjacent number.
JAX implementation of numpy.spacing().
Parameters:
x (ArrayLike) – real-valued array. Integer or boolean types will be cast to float.
Returns:
Array of same shape as x containing spacing between each entry ofx and its closest adjacent value.
Return type:
Examples
x = jnp.array([0.0, 0.25, 0.5, 0.75, 1.0], dtype='float32') jnp.spacing(x) Array([1.4012985e-45, 2.9802322e-08, 5.9604645e-08, 5.9604645e-08, 1.1920929e-07], dtype=float32)
For x = 1, the spacing is equal to the eps value given byjax.numpy.finfo:
x = jnp.float32(1) jnp.spacing(x) == jnp.finfo(x.dtype).eps Array(True, dtype=bool)