(x, n_devices)
return fastmath.nested_map(f, x)
Replicates/broadcasts ``x`` for ``n_devices``.
Replicates/broadcasts ``x`` for ``n_devices``.
Replicates / broadcasts x for n_devices .
def for_n_devices(x, n_devices):
  """Replicates/broadcasts ``x`` for ``n_devices``."""
  def f(x):
    if n_devices > 1 and fastmath.is_backend(fastmath.Backend.JAX):
      return jax.device_put_replicated(x, jax.local_devices())
    elif n_devices > 1:
      return jnp.broadcast_to(x, (n_devices,) + jnp.asarray(x).shape)
    else:
      return x
  return fastmath.nested_map(f, x)
def for_n_devices ( x , n_devices ) : def f ( x ) : if n_devices > 1 and fastmath . is_backend ( fastmath . Backend . JAX ) : return jax . device_put_replicated ( x , jax . local_devices ( ) ) elif n_devices > 1 : return jnp . broadcast_to ( x , ( n_devices , ) + jnp . asarray ( x ) . shape ) else : return x return fastmath . nested_map ( f , x )