Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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