Skip to content

Commit

Permalink
add brainunit.math.broadcast_to() (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming0625 committed Jul 7, 2024
1 parent e61dc4c commit 4cefe6b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions brainunit/math/_fun_keep_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,39 @@ def broadcast_arrays(
return _broadcast_fun(jnp.broadcast_arrays, *args)


@set_module_as('brainunit.math')
def broadcast_to(
array: Union[Quantity, jax.typing.ArrayLike],
shape: Tuple[int, ...]
) -> Quantity | jax.Array:
"""
Broadcast an array to a new shape.
Parameters
----------
array : array_like
The array to broadcast.
shape : tuple or int
The shape of the desired array. A single integer ``i`` is interpreted
as ``(i,)``.
Returns
-------
broadcast : array
A readonly view on the original array with the given shape. It is
typically not contiguous. Furthermore, more than one element of a
broadcasted array may refer to a single memory location.
Raises
------
ValueError
If the array is not compatible with the new shape according to NumPy's
broadcasting rules.
"""
return _fun_keep_unit_unary(jnp.broadcast_to, array, shape=shape)


@set_module_as('brainunit.math')
def atleast_1d(
*arys: Union[jax.Array, Quantity]
Expand Down

0 comments on commit 4cefe6b

Please sign in to comment.