code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def _notimplemented_flat(self): """Not implemented: Use :meth:`~jax.Array.flatten` instead.""" raise NotImplementedError("JAX Arrays do not implement the arr.flat property: " "consider arr.flatten() instead.")
Not implemented: Use :meth:`~jax.Array.flatten` instead.
_notimplemented_flat
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def _multi_slice(self: Array, start_indices: tuple[tuple[int, ...]], limit_indices: tuple[tuple[int, ...]], removed_dims: tuple[tuple[int, ...]]) -> list[Array]: """Extracts multiple slices from `arr`. This is used to shard Array arguments to pmap. It's implemente...
Extracts multiple slices from `arr`. This is used to shard Array arguments to pmap. It's implemented as a Array method here to avoid circular imports.
_multi_slice
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def get(self, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None, fill_value: ArrayLike | None = None, out_sharding: Sharding | PartitionSpec | None = None): """Equivalent to ``x[idx]``. Returns the value of ``x`` tha...
Equivalent to ``x[idx]``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexing <numpy.doc.indexing>` ``x[idx]``. This function differs from the usual array indexing syntax in that it allows additional keyword arguments ``indices_are_sorted`` and ``unique_indices`` to be passe...
get
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def set(self, values: ArrayLike, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> None: """Pure equivalent of ``x[idx] = y``. Returns the value of ``x`` that would result from the NumPy-style :mod:`indexed assignment ...
Pure equivalent of ``x[idx] = y``. Returns the value of ``x`` that would result from the NumPy-style :mod:`indexed assignment <numpy.doc.indexing>` ``x[idx] = y``. See :mod:`jax.ops` for details.
set
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def apply(self, func: Callable[[ArrayLike], Array], *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> Array: """Pure equivalent of ``func.at(x, idx)`` for a unary ufunc ``func``. Returns the value of ``x`` that would r...
Pure equivalent of ``func.at(x, idx)`` for a unary ufunc ``func``. Returns the value of ``x`` that would result from applying the unary function ``func`` to ``x`` at the given indices. This is similar to ``x.at[idx].set(func(x[idx]))``, but differs in the case of repeated indices: in ``x.at[idx].apply(...
apply
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def add(self, values: ArrayLike, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> Array: """Pure equivalent of ``x[idx] += y``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed assignment...
Pure equivalent of ``x[idx] += y``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] += y``. See :mod:`jax.ops` for details.
add
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def subtract(self, values: ArrayLike, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> Array: """Pure equivalent of ``x[idx] -= y``. Returns the value of ``x`` that would result from the NumPy-style :mod:ind...
Pure equivalent of ``x[idx] -= y``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] -= y``. See :mod:`jax.ops` for details.
subtract
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def multiply(self, values: ArrayLike, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> Array: """Pure equivalent of ``x[idx] *= y``. Returns the value of ``x`` that would result from the NumPy-style :mod:ind...
Pure equivalent of ``x[idx] *= y``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] *= y``. See :mod:`jax.ops` for details.
multiply
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def divide(self, values: ArrayLike, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> Array: """Pure equivalent of ``x[idx] /= y``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed a...
Pure equivalent of ``x[idx] /= y``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] /= y``. See :mod:`jax.ops` for details.
divide
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def power(self, values: ArrayLike, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> Array: """Pure equivalent of ``x[idx] **= y``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed ass...
Pure equivalent of ``x[idx] **= y``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] **= y``. See :mod:`jax.ops` for details.
power
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def min(self, values: ArrayLike, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> Array: """Pure equivalent of ``x[idx] = minimum(x[idx], y)``. Returns the value of ``x`` that would result from the NumPy-style :mod:in...
Pure equivalent of ``x[idx] = minimum(x[idx], y)``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] = minimum(x[idx], y)``. See :mod:`jax.ops` for details.
min
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def max(self, values: ArrayLike, *, indices_are_sorted: bool = False, unique_indices: bool = False, mode: str | lax.GatherScatterMode | None = None) -> Array: """Pure equivalent of ``x[idx] = maximum(x[idx], y)``. Returns the value of ``x`` that would result from the NumPy-style :mod:in...
Pure equivalent of ``x[idx] = maximum(x[idx], y)``. Returns the value of ``x`` that would result from the NumPy-style :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] = maximum(x[idx], y)``. See :mod:`jax.ops` for details.
max
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def register_jax_array_methods(): """Call this function once to register methods of JAX arrays""" _set_shaped_array_attributes(core.ShapedArray) _set_shaped_array_attributes(core.DShapedArray) _set_array_base_attributes(ArrayImpl, exclude={'__getitem__'}) _set_tracer_aval_forwarding(core.Tracer, exclude={*_i...
Call this function once to register methods of JAX arrays
register_jax_array_methods
python
jax-ml/jax
jax/_src/numpy/array_methods.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/array_methods.py
Apache-2.0
def _is_category_disabled( category: Category | None, ) -> bool: """Check if the error checking behavior for the given category is disabled.""" if category is None: return False if category == "nan": raise ValueError("nan is deprecated. Use `_set_error_if_nan` instead.") if category == "divide": ...
Check if the error checking behavior for the given category is disabled.
_is_category_disabled
python
jax-ml/jax
jax/_src/numpy/error.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/error.py
Apache-2.0
def _set_error_if_with_category( pred: Array, /, msg: str, category: Category | None = None, ) -> None: """Set the internal error state if any element of `pred` is `True`. This function is similar to :func:`set_error_if`, but it also takes a category argument. The category can be "nan", "divide",...
Set the internal error state if any element of `pred` is `True`. This function is similar to :func:`set_error_if`, but it also takes a category argument. The category can be "nan", "divide", or "oob". The error checking behavior for each category can be configured using :func:`set_error_checking_behavior`. If ...
_set_error_if_with_category
python
jax-ml/jax
jax/_src/numpy/error.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/error.py
Apache-2.0
def _set_error_if_nan(pred: Array, /): """Set the internal error state if any element of `pred` is `NaN`. This function is disabled if the `jax_error_checking_behavior_nan` flag is set to "ignore". """ if config.error_checking_behavior_nan.value == "ignore": return if not dtypes.issubdtype(pred.dtype,...
Set the internal error state if any element of `pred` is `NaN`. This function is disabled if the `jax_error_checking_behavior_nan` flag is set to "ignore".
_set_error_if_nan
python
jax-ml/jax
jax/_src/numpy/error.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/error.py
Apache-2.0
def _set_error_if_divide_by_zero(pred: Array, /): """Set the internal error state if any element of `pred` is zero. This function is intended for checking if the denominator of a division is zero. This function is disabled if the `jax_error_checking_behavior_divide` flag is set to "ignore". """ if confi...
Set the internal error state if any element of `pred` is zero. This function is intended for checking if the denominator of a division is zero. This function is disabled if the `jax_error_checking_behavior_divide` flag is set to "ignore".
_set_error_if_divide_by_zero
python
jax-ml/jax
jax/_src/numpy/error.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/error.py
Apache-2.0
def _check_precondition_oob_gather( shape: tuple[int, ...], gather_indices: ArrayLike ) -> None: """Check for out of bounds errors before calling `lax.gather`.""" if config.error_checking_behavior_oob.value == "ignore": return # TODO(mattjj): fix the circular import issue. from jax._src import error_ch...
Check for out of bounds errors before calling `lax.gather`.
_check_precondition_oob_gather
python
jax-ml/jax
jax/_src/numpy/error.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/error.py
Apache-2.0
def _check_precondition_oob_dynamic_slice( shape: tuple[int, ...], start_indices: Sequence[ArrayLike], slice_sizes: list[int], allow_negative_indices: list[bool], ) -> None: """Check for out of bounds errors before calling `lax.dynamic_slice`.""" if config.error_checking_behavior_oob.value == "ignor...
Check for out of bounds errors before calling `lax.dynamic_slice`.
_check_precondition_oob_dynamic_slice
python
jax-ml/jax
jax/_src/numpy/error.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/error.py
Apache-2.0
def fftn(a: ArrayLike, s: Shape | None = None, axes: Sequence[int] | None = None, norm: str | None = None) -> Array: r"""Compute a multidimensional discrete Fourier transform along given axes. JAX implementation of :func:`numpy.fft.fftn`. Args: a: input array s: sequence of integers. S...
Compute a multidimensional discrete Fourier transform along given axes. JAX implementation of :func:`numpy.fft.fftn`. Args: a: input array s: sequence of integers. Specifies the shape of the result. If not specified, it will default to the shape of ``a`` along the specified ``axes``. axes: seque...
fftn
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def ifftn(a: ArrayLike, s: Shape | None = None, axes: Sequence[int] | None = None, norm: str | None = None) -> Array: r"""Compute a multidimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.ifftn`. Args: a: input array s: sequence of integers. Specif...
Compute a multidimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.ifftn`. Args: a: input array s: sequence of integers. Specifies the shape of the result. If not specified, it will default to the shape of ``a`` along the specified ``axes``. axes: sequence of i...
ifftn
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def rfftn(a: ArrayLike, s: Shape | None = None, axes: Sequence[int] | None = None, norm: str | None = None) -> Array: """Compute a multidimensional discrete Fourier transform of a real-valued array. JAX implementation of :func:`numpy.fft.rfftn`. Args: a: real-valued input array. s: o...
Compute a multidimensional discrete Fourier transform of a real-valued array. JAX implementation of :func:`numpy.fft.rfftn`. Args: a: real-valued input array. s: optional sequence of integers. Controls the effective size of the input along each specified axis. If not specified, it will default to th...
rfftn
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def irfftn(a: ArrayLike, s: Shape | None = None, axes: Sequence[int] | None = None, norm: str | None = None) -> Array: """Compute a real-valued multidimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.irfftn`. Args: a: input array. s: optional seq...
Compute a real-valued multidimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.irfftn`. Args: a: input array. s: optional sequence of integers. Specifies the size of the output in each specified axis. If not specified, the dimension of output along axis ``axe...
irfftn
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def fft(a: ArrayLike, n: int | None = None, axis: int = -1, norm: str | None = None) -> Array: r"""Compute a one-dimensional discrete Fourier transform along a given axis. JAX implementation of :func:`numpy.fft.fft`. Args: a: input array n: int. Specifies the dimension of the result along ``axis...
Compute a one-dimensional discrete Fourier transform along a given axis. JAX implementation of :func:`numpy.fft.fft`. Args: a: input array n: int. Specifies the dimension of the result along ``axis``. If not specified, it will default to the dimension of ``a`` along ``axis``. axis: int, default=...
fft
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def ifft(a: ArrayLike, n: int | None = None, axis: int = -1, norm: str | None = None) -> Array: r"""Compute a one-dimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.ifft`. Args: a: input array n: int. Specifies the dimension of the result along ``axis``. If n...
Compute a one-dimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.ifft`. Args: a: input array n: int. Specifies the dimension of the result along ``axis``. If not specified, it will default to the dimension of ``a`` along ``axis``. axis: int, default=-1. Specif...
ifft
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def rfft(a: ArrayLike, n: int | None = None, axis: int = -1, norm: str | None = None) -> Array: r"""Compute a one-dimensional discrete Fourier transform of a real-valued array. JAX implementation of :func:`numpy.fft.rfft`. Args: a: real-valued input array. n: int. Specifies the effective dimens...
Compute a one-dimensional discrete Fourier transform of a real-valued array. JAX implementation of :func:`numpy.fft.rfft`. Args: a: real-valued input array. n: int. Specifies the effective dimension of the input along ``axis``. If not specified, it will default to the dimension of input along ``axis...
rfft
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def irfft(a: ArrayLike, n: int | None = None, axis: int = -1, norm: str | None = None) -> Array: """Compute a real-valued one-dimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.irfft`. Args: a: input array. n: int. Specifies the dimension of the result along...
Compute a real-valued one-dimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.irfft`. Args: a: input array. n: int. Specifies the dimension of the result along ``axis``. If not specified, ``n = 2*(m-1)``, where ``m`` is the dimension of ``a`` along ``axis``. ax...
irfft
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def fft2(a: ArrayLike, s: Shape | None = None, axes: Sequence[int] = (-2,-1), norm: str | None = None) -> Array: """Compute a two-dimensional discrete Fourier transform along given axes. JAX implementation of :func:`numpy.fft.fft2`. Args: a: input array. Must have ``a.ndim >= 2``. s: optional l...
Compute a two-dimensional discrete Fourier transform along given axes. JAX implementation of :func:`numpy.fft.fft2`. Args: a: input array. Must have ``a.ndim >= 2``. s: optional length-2 sequence of integers. Specifies the size of the output along each specified axis. If not specified, it will defau...
fft2
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def ifft2(a: ArrayLike, s: Shape | None = None, axes: Sequence[int] = (-2,-1), norm: str | None = None) -> Array: """Compute a two-dimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.ifft2`. Args: a: input array. Must have ``a.ndim >= 2``. s: optional length-...
Compute a two-dimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.ifft2`. Args: a: input array. Must have ``a.ndim >= 2``. s: optional length-2 sequence of integers. Specifies the size of the output in each specified axis. If not specified, it will default to the s...
ifft2
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def rfft2(a: ArrayLike, s: Shape | None = None, axes: Sequence[int] = (-2,-1), norm: str | None = None) -> Array: """Compute a two-dimensional discrete Fourier transform of a real-valued array. JAX implementation of :func:`numpy.fft.rfft2`. Args: a: real-valued input array. Must have ``a.ndim >= 2...
Compute a two-dimensional discrete Fourier transform of a real-valued array. JAX implementation of :func:`numpy.fft.rfft2`. Args: a: real-valued input array. Must have ``a.ndim >= 2``. s: optional length-2 sequence of integers. Specifies the effective size of the output along each specified axis. If...
rfft2
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def irfft2(a: ArrayLike, s: Shape | None = None, axes: Sequence[int] = (-2,-1), norm: str | None = None) -> Array: """Compute a real-valued two-dimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.irfft2`. Args: a: input array. Must have ``a.ndim >= 2``. s: o...
Compute a real-valued two-dimensional inverse discrete Fourier transform. JAX implementation of :func:`numpy.fft.irfft2`. Args: a: input array. Must have ``a.ndim >= 2``. s: optional length-2 sequence of integers. Specifies the size of the output in each specified axis. If not specified, the dimensi...
irfft2
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def fftshift(x: ArrayLike, axes: None | int | Sequence[int] = None) -> Array: """Shift zero-frequency fft component to the center of the spectrum. JAX implementation of :func:`numpy.fft.fftshift`. Args: x: N-dimensional array array of frequencies. axes: optional integer or sequence of integers specifyin...
Shift zero-frequency fft component to the center of the spectrum. JAX implementation of :func:`numpy.fft.fftshift`. Args: x: N-dimensional array array of frequencies. axes: optional integer or sequence of integers specifying which axes to shift. If None (default), then shift all axes. Returns: ...
fftshift
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def ifftshift(x: ArrayLike, axes: None | int | Sequence[int] = None) -> Array: """The inverse of :func:`jax.numpy.fft.fftshift`. JAX implementation of :func:`numpy.fft.ifftshift`. Args: x: N-dimensional array array of frequencies. axes: optional integer or sequence of integers specifying which axes to ...
The inverse of :func:`jax.numpy.fft.fftshift`. JAX implementation of :func:`numpy.fft.ifftshift`. Args: x: N-dimensional array array of frequencies. axes: optional integer or sequence of integers specifying which axes to shift. If None (default), then shift all axes. Returns: A shifted copy o...
ifftshift
python
jax-ml/jax
jax/_src/numpy/fft.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/fft.py
Apache-2.0
def take( a: ArrayLike, indices: ArrayLike, axis: int | None = None, out: None = None, mode: str | None = None, unique_indices: bool = False, indices_are_sorted: bool = False, fill_value: StaticScalar | None = None, ) -> Array: """Take elements from an array. JAX implementation of :...
Take elements from an array. JAX implementation of :func:`numpy.take`, implemented in terms of :func:`jax.lax.gather`. JAX's behavior differs from NumPy in the case of out-of-bound indices; see the ``mode`` parameter below. Args: a: array from which to take values. indices: N-dimensional array of inte...
take
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def _normalize_index(index, axis_size): """Normalizes an index value in the range [-N, N) to the range [0, N).""" if dtypes.issubdtype(dtypes.dtype(index, canonicalize=True), np.unsignedinteger): return index if core.is_constant_dim(axis_size): axis_size_val = lax_internal._const(index, axis_size) else:...
Normalizes an index value in the range [-N, N) to the range [0, N).
_normalize_index
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def take_along_axis( arr: ArrayLike, indices: ArrayLike, axis: int | None, mode: str | lax.GatherScatterMode | None = None, fill_value: StaticScalar | None = None, ) -> Array: """Take elements from an array. JAX implementation of :func:`numpy.take_along_axis`, implemented in terms of :func:`j...
Take elements from an array. JAX implementation of :func:`numpy.take_along_axis`, implemented in terms of :func:`jax.lax.gather`. JAX's behavior differs from NumPy in the case of out-of-bound indices; see the ``mode`` parameter below. Args: a: array from which to take values. indices: array of integer...
take_along_axis
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def put_along_axis( arr: ArrayLike, indices: ArrayLike, values: ArrayLike, axis: int | None, inplace: bool = True, *, mode: str | None = None, ) -> Array: """Put values into the destination array by matching 1d index and data slices. JAX implementation of :func:`numpy.put_along_axis`. The semantic...
Put values into the destination array by matching 1d index and data slices. JAX implementation of :func:`numpy.put_along_axis`. The semantics of :func:`numpy.put_along_axis` are to modify arrays in-place, which is not possible for JAX's immutable arrays. The JAX version returns a modified copy of the input, a...
put_along_axis
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def split_index_for_jit(idx, shape): """Splits indices into necessarily-static and dynamic parts. Used to pass indices into `jit`-ted function. """ # Convert list indices to tuples in cases (deprecated by NumPy.) idx = eliminate_deprecated_list_indexing(idx) if any(isinstance(i, str) for i in idx): rai...
Splits indices into necessarily-static and dynamic parts. Used to pass indices into `jit`-ted function.
split_index_for_jit
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def merge_static_and_dynamic_indices(treedef, static_idx, dynamic_idx): """Recombines indices that were split by split_index_for_jit.""" idx = [] for s, d in zip(static_idx, dynamic_idx): if d is not None: idx.append(d) elif isinstance(s, tuple): idx.append(slice(s[0], s[1], s[2])) else: ...
Recombines indices that were split by split_index_for_jit.
merge_static_and_dynamic_indices
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def _expand_bool_indices(idx, shape): """Converts concrete bool indexes into advanced integer indexes.""" out = [] total_dims = len(shape) num_ellipsis = sum(e is Ellipsis for e in idx) if num_ellipsis > 1: raise IndexError("an index can only have a single ellipsis ('...')") elif num_ellipsis == 1: ...
Converts concrete bool indexes into advanced integer indexes.
_expand_bool_indices
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def _is_slice_element_none_or_constant_or_symbolic(elt): """Return True if elt is a constant or None.""" if elt is None: return True if core.is_symbolic_dim(elt): return True try: return core.is_concrete(elt) except TypeError: return False
Return True if elt is a constant or None.
_is_slice_element_none_or_constant_or_symbolic
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def _is_advanced_int_indexer(idx): """Returns True if idx should trigger int array indexing, False otherwise.""" # https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing assert isinstance(idx, tuple) if all(e is None or e is Ellipsis or isinstance(e, slice) or _is_scalar(e) a...
Returns True if idx should trigger int array indexing, False otherwise.
_is_advanced_int_indexer
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def _is_int_arraylike(x): """Returns True if x is array-like with integer dtype, False otherwise.""" return (isinstance(x, int) and not isinstance(x, bool) or dtypes.issubdtype(getattr(x, "dtype", None), np.integer) or isinstance(x, (list, tuple)) and all(_is_int_arraylike(e) for e in x))
Returns True if x is array-like with integer dtype, False otherwise.
_is_int_arraylike
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def _is_scalar(x): """Checks if a Python or NumPy scalar.""" return np.isscalar(x) or (isinstance(x, (np.ndarray, Array)) and np.ndim(x) == 0)
Checks if a Python or NumPy scalar.
_is_scalar
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def _canonicalize_tuple_index(arr_ndim, idx): """Helper to remove Ellipsis and add in the implicit trailing slice(None).""" num_dimensions_consumed = sum(not (e is None or e is Ellipsis or isinstance(e, bool)) for e in idx) if num_dimensions_consumed > arr_ndim: index_or_indices = "index" if num_dimensions_co...
Helper to remove Ellipsis and add in the implicit trailing slice(None).
_canonicalize_tuple_index
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def place(arr: ArrayLike, mask: ArrayLike, vals: ArrayLike, *, inplace: bool = True) -> Array: """Update array elements based on a mask. JAX implementation of :func:`numpy.place`. The semantics of :func:`numpy.place` are to modify arrays in-place, which is not possible for JAX's immutable arrays. Th...
Update array elements based on a mask. JAX implementation of :func:`numpy.place`. The semantics of :func:`numpy.place` are to modify arrays in-place, which is not possible for JAX's immutable arrays. The JAX version returns a modified copy of the input, and adds the ``inplace`` parameter which must be set to ...
place
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def put(a: ArrayLike, ind: ArrayLike, v: ArrayLike, mode: str | None = None, *, inplace: bool = True) -> Array: """Put elements into an array at given indices. JAX implementation of :func:`numpy.put`. The semantics of :func:`numpy.put` are to modify arrays in-place, which is not possible for JAX's imm...
Put elements into an array at given indices. JAX implementation of :func:`numpy.put`. The semantics of :func:`numpy.put` are to modify arrays in-place, which is not possible for JAX's immutable arrays. The JAX version returns a modified copy of the input, and adds the ``inplace`` parameter which must be set t...
put
python
jax-ml/jax
jax/_src/numpy/indexing.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/indexing.py
Apache-2.0
def iscomplexobj(x: Any) -> bool: """Check if the input is a complex number or an array containing complex elements. JAX implementation of :func:`numpy.iscomplexobj`. The function evaluates based on input type rather than value. Inputs with zero imaginary parts are still considered complex. Args: x: in...
Check if the input is a complex number or an array containing complex elements. JAX implementation of :func:`numpy.iscomplexobj`. The function evaluates based on input type rather than value. Inputs with zero imaginary parts are still considered complex. Args: x: input object to check. Returns: Tr...
iscomplexobj
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def _convert_and_clip_integer(val: ArrayLike, dtype: DType) -> Array: """ Convert integer-typed val to specified integer dtype, clipping to dtype range rather than wrapping. Args: val: value to be converted dtype: dtype of output Returns: equivalent of val in new dtype Examples -------- N...
Convert integer-typed val to specified integer dtype, clipping to dtype range rather than wrapping. Args: val: value to be converted dtype: dtype of output Returns: equivalent of val in new dtype Examples -------- Normal integer type conversion will wrap: >>> val = jnp.uint32(0xFFFFFFFF...
_convert_and_clip_integer
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def load(file: IO[bytes] | str | os.PathLike[Any], *args: Any, **kwargs: Any) -> Array: """Load JAX arrays from npy files. JAX wrapper of :func:`numpy.load`. This function is a simple wrapper of :func:`numpy.load`, but in the case of ``.npy`` files created with :func:`numpy.save` or :func:`jax.numpy.save`, ...
Load JAX arrays from npy files. JAX wrapper of :func:`numpy.load`. This function is a simple wrapper of :func:`numpy.load`, but in the case of ``.npy`` files created with :func:`numpy.save` or :func:`jax.numpy.save`, the output will be returned as a :class:`jax.Array`, and ``bfloat16`` data types will be re...
load
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def isscalar(element: Any) -> bool: """Return True if the input is a scalar. JAX implementation of :func:`numpy.isscalar`. JAX's implementation differs from NumPy's in that it considers zero-dimensional arrays to be scalars; see the *Note* below for more details. Args: element: input object to check; an...
Return True if the input is a scalar. JAX implementation of :func:`numpy.isscalar`. JAX's implementation differs from NumPy's in that it considers zero-dimensional arrays to be scalars; see the *Note* below for more details. Args: element: input object to check; any type is valid input. Returns: Tr...
isscalar
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def trunc(x: ArrayLike) -> Array: """Round input to the nearest integer towards zero. JAX implementation of :func:`numpy.trunc`. Args: x: input array or scalar. Returns: An array with same shape and dtype as ``x`` containing the rounded values. See also: - :func:`jax.numpy.fix`: Rounds the inp...
Round input to the nearest integer towards zero. JAX implementation of :func:`numpy.trunc`. Args: x: input array or scalar. Returns: An array with same shape and dtype as ``x`` containing the rounded values. See also: - :func:`jax.numpy.fix`: Rounds the input to the nearest integer towards zero....
trunc
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def convolve(a: ArrayLike, v: ArrayLike, mode: str = 'full', *, precision: PrecisionLike = None, preferred_element_type: DTypeLike | None = None) -> Array: r"""Convolution of two one dimensional arrays. JAX implementation of :func:`numpy.convolve`. Convolution of one dimensional arrays...
Convolution of two one dimensional arrays. JAX implementation of :func:`numpy.convolve`. Convolution of one dimensional arrays is defined as: .. math:: c_k = \sum_j a_{k - j} v_j Args: a: left-hand input to the convolution. Must have ``a.ndim == 1``. v: right-hand input to the convolution. Mus...
convolve
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def correlate(a: ArrayLike, v: ArrayLike, mode: str = 'valid', *, precision: PrecisionLike = None, preferred_element_type: DTypeLike | None = None) -> Array: r"""Correlation of two one dimensional arrays. JAX implementation of :func:`numpy.correlate`. Correlation of one dimensional a...
Correlation of two one dimensional arrays. JAX implementation of :func:`numpy.correlate`. Correlation of one dimensional arrays is defined as: .. math:: c_k = \sum_j a_{k + j} \overline{v_j} where :math:`\overline{v_j}` is the complex conjugate of :math:`v_j`. Args: a: left-hand input to the co...
correlate
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def histogram_bin_edges(a: ArrayLike, bins: ArrayLike = 10, range: None | Array | Sequence[ArrayLike] = None, weights: ArrayLike | None = None) -> Array: """Compute the bin edges for a histogram. JAX implementation of :func:`numpy.histogram_bin_edges`. Args: a...
Compute the bin edges for a histogram. JAX implementation of :func:`numpy.histogram_bin_edges`. Args: a: array of values to be binned bins: Specify the number of bins in the histogram (default: 10). range: tuple of scalars. Specifies the range of the data. If not specified, the range is inferred...
histogram_bin_edges
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def histogram(a: ArrayLike, bins: ArrayLike = 10, range: Sequence[ArrayLike] | None = None, weights: ArrayLike | None = None, density: bool | None = None) -> tuple[Array, Array]: """Compute a 1-dimensional histogram. JAX implementation of :func:`numpy.histogram`. Args: ...
Compute a 1-dimensional histogram. JAX implementation of :func:`numpy.histogram`. Args: a: array of values to be binned. May be any size or dimension. bins: Specify the number of bins in the histogram (default: 10). ``bins`` may also be an array specifying the locations of the bin edges. range: ...
histogram
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def histogram2d(x: ArrayLike, y: ArrayLike, bins: ArrayLike | list[ArrayLike] = 10, range: Sequence[None | Array | Sequence[ArrayLike]] | None = None, weights: ArrayLike | None = None, density: bool | None = None) -> tuple[Array, Array, Array]: """Compute a 2-dimensiona...
Compute a 2-dimensional histogram. JAX implementation of :func:`numpy.histogram2d`. Args: x: one-dimensional array of x-values for points to be binned. y: one-dimensional array of y-values for points to be binned. bins: Specify the number of bins in the histogram (default: 10). ``bins`` may also...
histogram2d
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def histogramdd(sample: ArrayLike, bins: ArrayLike | list[ArrayLike] = 10, range: Sequence[None | Array | Sequence[ArrayLike]] | None = None, weights: ArrayLike | None = None, density: bool | None = None) -> tuple[Array, list[Array]]: """Compute an N-dimensional histogr...
Compute an N-dimensional histogram. JAX implementation of :func:`numpy.histogramdd`. Args: sample: input array of shape ``(N, D)`` representing ``N`` points in ``D`` dimensions. bins: Specify the number of bins in each dimension of the histogram. (default: 10). May also be a length-D sequence ...
histogramdd
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def transpose(a: ArrayLike, axes: Sequence[int] | None = None) -> Array: """Return a transposed version of an N-dimensional array. JAX implementation of :func:`numpy.transpose`, implemented in terms of :func:`jax.lax.transpose`. Args: a: input array axes: optionally specify the permutation using a len...
Return a transposed version of an N-dimensional array. JAX implementation of :func:`numpy.transpose`, implemented in terms of :func:`jax.lax.transpose`. Args: a: input array axes: optionally specify the permutation using a length-`a.ndim` sequence of integers ``i`` satisfying ``0 <= i < a.ndim``. ...
transpose
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def permute_dims(a: ArrayLike, /, axes: tuple[int, ...]) -> Array: """Permute the axes/dimensions of an array. JAX implementation of :func:`array_api.permute_dims`. Args: a: input array axes: tuple of integers in range ``[0, a.ndim)`` specifying the axes permutation. Returns: a copy of ``a`...
Permute the axes/dimensions of an array. JAX implementation of :func:`array_api.permute_dims`. Args: a: input array axes: tuple of integers in range ``[0, a.ndim)`` specifying the axes permutation. Returns: a copy of ``a`` with axes permuted. See also: - :func:`jax.numpy.transpose` ...
permute_dims
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def matrix_transpose(x: ArrayLike, /) -> Array: """Transpose the last two dimensions of an array. JAX implementation of :func:`numpy.matrix_transpose`, implemented in terms of :func:`jax.lax.transpose`. Args: x: input array, Must have ``x.ndim >= 2`` Returns: matrix-transposed copy of the array. ...
Transpose the last two dimensions of an array. JAX implementation of :func:`numpy.matrix_transpose`, implemented in terms of :func:`jax.lax.transpose`. Args: x: input array, Must have ``x.ndim >= 2`` Returns: matrix-transposed copy of the array. See Also: - :attr:`jax.Array.mT`: same operation...
matrix_transpose
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def rot90(m: ArrayLike, k: int = 1, axes: tuple[int, int] = (0, 1)) -> Array: """Rotate an array by 90 degrees counterclockwise in the plane specified by axes. JAX implementation of :func:`numpy.rot90`. Args: m: input array. Must have ``m.ndim >= 2``. k: int, optional, default=1. Specifies the number of...
Rotate an array by 90 degrees counterclockwise in the plane specified by axes. JAX implementation of :func:`numpy.rot90`. Args: m: input array. Must have ``m.ndim >= 2``. k: int, optional, default=1. Specifies the number of times the array is rotated. For negative values of ``k``, the array is rotat...
rot90
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def flip(m: ArrayLike, axis: int | Sequence[int] | None = None) -> Array: """Reverse the order of elements of an array along the given axis. JAX implementation of :func:`numpy.flip`. Args: m: Array. axis: integer or sequence of integers. Specifies along which axis or axes should the array elements...
Reverse the order of elements of an array along the given axis. JAX implementation of :func:`numpy.flip`. Args: m: Array. axis: integer or sequence of integers. Specifies along which axis or axes should the array elements be reversed. Default is ``None``, which flips along all axes. Returns...
flip
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def fliplr(m: ArrayLike) -> Array: """Reverse the order of elements of an array along axis 1. JAX implementation of :func:`numpy.fliplr`. Args: m: Array with at least two dimensions. Returns: An array with the elements in reverse order along axis 1. See Also: - :func:`jax.numpy.flip`: reverse ...
Reverse the order of elements of an array along axis 1. JAX implementation of :func:`numpy.fliplr`. Args: m: Array with at least two dimensions. Returns: An array with the elements in reverse order along axis 1. See Also: - :func:`jax.numpy.flip`: reverse the order along the given axis - :fu...
fliplr
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def flipud(m: ArrayLike) -> Array: """Reverse the order of elements of an array along axis 0. JAX implementation of :func:`numpy.flipud`. Args: m: Array with at least one dimension. Returns: An array with the elements in reverse order along axis 0. See Also: - :func:`jax.numpy.flip`: reverse t...
Reverse the order of elements of an array along axis 0. JAX implementation of :func:`numpy.flipud`. Args: m: Array with at least one dimension. Returns: An array with the elements in reverse order along axis 0. See Also: - :func:`jax.numpy.flip`: reverse the order along the given axis - :fun...
flipud
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def iscomplex(x: ArrayLike) -> Array: """Return boolean array showing where the input is complex. JAX implementation of :func:`numpy.iscomplex`. Args: x: Input array to check. Returns: A new array containing boolean values indicating complex elements. See Also: - :func:`jax.numpy.iscomplexobj`...
Return boolean array showing where the input is complex. JAX implementation of :func:`numpy.iscomplex`. Args: x: Input array to check. Returns: A new array containing boolean values indicating complex elements. See Also: - :func:`jax.numpy.iscomplexobj` - :func:`jax.numpy.isrealobj` Examp...
iscomplex
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def isreal(x: ArrayLike) -> Array: """Return boolean array showing where the input is real. JAX implementation of :func:`numpy.isreal`. Args: x: input array to check. Returns: A new array containing boolean values indicating real elements. See Also: - :func:`jax.numpy.iscomplex` - :func:`j...
Return boolean array showing where the input is real. JAX implementation of :func:`numpy.isreal`. Args: x: input array to check. Returns: A new array containing boolean values indicating real elements. See Also: - :func:`jax.numpy.iscomplex` - :func:`jax.numpy.isrealobj` Examples: >>>...
isreal
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def angle(z: ArrayLike, deg: bool = False) -> Array: """Return the angle of a complex valued number or array. JAX implementation of :func:`numpy.angle`. Args: z: A complex number or an array of complex numbers. deg: Boolean. If ``True``, returns the result in degrees else returns in radians. Defau...
Return the angle of a complex valued number or array. JAX implementation of :func:`numpy.angle`. Args: z: A complex number or an array of complex numbers. deg: Boolean. If ``True``, returns the result in degrees else returns in radians. Default is ``False``. Returns: An array of counterclockw...
angle
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def diff(a: ArrayLike, n: int = 1, axis: int = -1, prepend: ArrayLike | None = None, append: ArrayLike | None = None) -> Array: """Calculate n-th order difference between array elements along a given axis. JAX implementation of :func:`numpy.diff`. The first order difference is computed by ``a[...
Calculate n-th order difference between array elements along a given axis. JAX implementation of :func:`numpy.diff`. The first order difference is computed by ``a[i+1] - a[i]``, and the n-th order difference is computed ``n`` times recursively. Args: a: input array. Must have ``a.ndim >= 1``. n: int,...
diff
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def ediff1d(ary: ArrayLike, to_end: ArrayLike | None = None, to_begin: ArrayLike | None = None) -> Array: """Compute the differences of the elements of the flattened array. JAX implementation of :func:`numpy.ediff1d`. Args: ary: input array or scalar. to_end: scalar or array, optional, defau...
Compute the differences of the elements of the flattened array. JAX implementation of :func:`numpy.ediff1d`. Args: ary: input array or scalar. to_end: scalar or array, optional, default=None. Specifies the numbers to append to the resulting array. to_begin: scalar or array, optional, default=Non...
ediff1d
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def gradient( f: ArrayLike, *varargs: ArrayLike, axis: int | Sequence[int] | None = None, edge_order: int | None = None, ) -> Array | list[Array]: """Compute the numerical gradient of a sampled function. JAX implementation of :func:`numpy.gradient`. The gradient in ``jnp.gradient`` is computed u...
Compute the numerical gradient of a sampled function. JAX implementation of :func:`numpy.gradient`. The gradient in ``jnp.gradient`` is computed using second-order finite differences across the array of sampled function values. This should not be confused with :func:`jax.grad`, which computes a precise gradie...
gradient
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def reshape( a: ArrayLike, shape: DimSize | Shape, order: str = "C", *, copy: bool | None = None, out_sharding=None) -> Array: """Return a reshaped copy of an array. JAX implementation of :func:`numpy.reshape`, implemented in terms of :func:`jax.lax.reshape`. Args: a: input array to reshape sh...
Return a reshaped copy of an array. JAX implementation of :func:`numpy.reshape`, implemented in terms of :func:`jax.lax.reshape`. Args: a: input array to reshape shape: integer or sequence of integers giving the new shape, which must match the size of the input array. If any single dimension is gi...
reshape
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def ravel(a: ArrayLike, order: str = "C", *, out_sharding=None) -> Array: """Flatten array into a 1-dimensional shape. JAX implementation of :func:`numpy.ravel`, implemented in terms of :func:`jax.lax.reshape`. ``ravel(arr, order=order)`` is equivalent to ``reshape(arr, -1, order=order)``. Args: a: arr...
Flatten array into a 1-dimensional shape. JAX implementation of :func:`numpy.ravel`, implemented in terms of :func:`jax.lax.reshape`. ``ravel(arr, order=order)`` is equivalent to ``reshape(arr, -1, order=order)``. Args: a: array to be flattened. order: ``'F'`` or ``'C'``, specifies whether the reshap...
ravel
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def ravel_multi_index(multi_index: Sequence[ArrayLike], dims: Sequence[int], mode: str = 'raise', order: str = 'C') -> Array: """Convert multi-dimensional indices into flat indices. JAX implementation of :func:`numpy.ravel_multi_index` Args: multi_index: sequence of integer arrays cont...
Convert multi-dimensional indices into flat indices. JAX implementation of :func:`numpy.ravel_multi_index` Args: multi_index: sequence of integer arrays containing indices in each dimension. dims: sequence of integer sizes; must have ``len(dims) == len(multi_index)`` mode: how to handle out-of bound i...
ravel_multi_index
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def unravel_index(indices: ArrayLike, shape: Shape) -> tuple[Array, ...]: """Convert flat indices into multi-dimensional indices. JAX implementation of :func:`numpy.unravel_index`. The JAX version differs in its treatment of out-of-bound indices: unlike NumPy, negative indices are supported, and out-of-bound i...
Convert flat indices into multi-dimensional indices. JAX implementation of :func:`numpy.unravel_index`. The JAX version differs in its treatment of out-of-bound indices: unlike NumPy, negative indices are supported, and out-of-bound indices are clipped to the nearest valid value. Args: indices: integer ar...
unravel_index
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def resize(a: ArrayLike, new_shape: Shape) -> Array: """Return a new array with specified shape. JAX implementation of :func:`numpy.resize`. Args: a: input array or scalar. new_shape: int or tuple of ints. Specifies the shape of the resized array. Returns: A resized array with specified shape. Th...
Return a new array with specified shape. JAX implementation of :func:`numpy.resize`. Args: a: input array or scalar. new_shape: int or tuple of ints. Specifies the shape of the resized array. Returns: A resized array with specified shape. The elements of ``a`` are repeated in the resized array,...
resize
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def squeeze(a: ArrayLike, axis: int | Sequence[int] | None = None) -> Array: """Remove one or more length-1 axes from array JAX implementation of :func:`numpy.sqeeze`, implemented via :func:`jax.lax.squeeze`. Args: a: input array axis: integer or sequence of integers specifying axes to remove. If any sp...
Remove one or more length-1 axes from array JAX implementation of :func:`numpy.sqeeze`, implemented via :func:`jax.lax.squeeze`. Args: a: input array axis: integer or sequence of integers specifying axes to remove. If any specified axis does not have a length of 1, an error is raised. If not specifi...
squeeze
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def expand_dims(a: ArrayLike, axis: int | Sequence[int]) -> Array: """Insert dimensions of length 1 into array JAX implementation of :func:`numpy.expand_dims`, implemented via :func:`jax.lax.expand_dims`. Args: a: input array axis: integer or sequence of integers specifying positions of axes to add. ...
Insert dimensions of length 1 into array JAX implementation of :func:`numpy.expand_dims`, implemented via :func:`jax.lax.expand_dims`. Args: a: input array axis: integer or sequence of integers specifying positions of axes to add. Returns: Copy of ``a`` with added dimensions. Notes: Unlike...
expand_dims
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def swapaxes(a: ArrayLike, axis1: int, axis2: int) -> Array: """Swap two axes of an array. JAX implementation of :func:`numpy.swapaxes`, implemented in terms of :func:`jax.lax.transpose`. Args: a: input array axis1: index of first axis axis2: index of second axis Returns: Copy of ``a`` with...
Swap two axes of an array. JAX implementation of :func:`numpy.swapaxes`, implemented in terms of :func:`jax.lax.transpose`. Args: a: input array axis1: index of first axis axis2: index of second axis Returns: Copy of ``a`` with specified axes swapped. Notes: Unlike :func:`numpy.swapaxe...
swapaxes
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def moveaxis(a: ArrayLike, source: int | Sequence[int], destination: int | Sequence[int]) -> Array: """Move an array axis to a new position JAX implementation of :func:`numpy.moveaxis`, implemented in terms of :func:`jax.lax.transpose`. Args: a: input array source: index or indices of the...
Move an array axis to a new position JAX implementation of :func:`numpy.moveaxis`, implemented in terms of :func:`jax.lax.transpose`. Args: a: input array source: index or indices of the axes to move. destination: index or indices of the axes destinations Returns: Copy of ``a`` with axes move...
moveaxis
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def isclose(a: ArrayLike, b: ArrayLike, rtol: ArrayLike = 1e-05, atol: ArrayLike = 1e-08, equal_nan: bool = False) -> Array: r"""Check if the elements of two arrays are approximately equal within a tolerance. JAX implementation of :func:`numpy.allclose`. Essentially this function evaluates the follo...
Check if the elements of two arrays are approximately equal within a tolerance. JAX implementation of :func:`numpy.allclose`. Essentially this function evaluates the following condition: .. math:: |a - b| \le \mathtt{atol} + \mathtt{rtol} * |b| ``jnp.inf`` in ``a`` will be considered equal to ``jnp.in...
isclose
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def interp(x: ArrayLike, xp: ArrayLike, fp: ArrayLike, left: ArrayLike | str | None = None, right: ArrayLike | str | None = None, period: ArrayLike | None = None) -> Array: """One-dimensional linear interpolation. JAX implementation of :func:`numpy.interp`. Args: x: N-dimens...
One-dimensional linear interpolation. JAX implementation of :func:`numpy.interp`. Args: x: N-dimensional array of x coordinates at which to evaluate the interpolation. xp: one-dimensional sorted array of points to be interpolated. fp: array of shape ``xp.shape`` containing the function values associat...
interp
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def where(condition, x=None, y=None, /, *, size=None, fill_value=None): """Select elements from two arrays based on a condition. JAX implementation of :func:`numpy.where`. .. note:: when only ``condition`` is provided, ``jnp.where(condition)`` is equivalent to ``jnp.nonzero(condition)``. For that case...
Select elements from two arrays based on a condition. JAX implementation of :func:`numpy.where`. .. note:: when only ``condition`` is provided, ``jnp.where(condition)`` is equivalent to ``jnp.nonzero(condition)``. For that case, refer to the documentation of :func:`jax.numpy.nonzero`. The docstring...
where
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def select( condlist: Sequence[ArrayLike], choicelist: Sequence[ArrayLike], default: ArrayLike = 0, ) -> Array: """Select values based on a series of conditions. JAX implementation of :func:`numpy.select`, implemented in terms of :func:`jax.lax.select_n` Args: condlist: sequence of array-like ...
Select values based on a series of conditions. JAX implementation of :func:`numpy.select`, implemented in terms of :func:`jax.lax.select_n` Args: condlist: sequence of array-like conditions. All entries must be mutually broadcast-compatible. choicelist: sequence of array-like values to choose. Mus...
select
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def bincount(x: ArrayLike, weights: ArrayLike | None = None, minlength: int = 0, *, length: int | None = None ) -> Array: """Count the number of occurrences of each value in an integer array. JAX implementation of :func:`numpy.bincount`. For an array of positive integers ``x``, this fu...
Count the number of occurrences of each value in an integer array. JAX implementation of :func:`numpy.bincount`. For an array of positive integers ``x``, this function returns an array ``counts`` of size ``x.max() + 1``, such that ``counts[i]`` contains the number of occurrences of the value ``i`` in ``x``. ...
bincount
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def broadcast_shapes(*shapes): """Broadcast input shapes to a common output shape. JAX implementation of :func:`numpy.broadcast_shapes`. JAX uses NumPy-style broadcasting rules, which you can read more about at `NumPy broadcasting`_. Args: shapes: 0 or more shapes specified as sequences of integers Ret...
Broadcast input shapes to a common output shape. JAX implementation of :func:`numpy.broadcast_shapes`. JAX uses NumPy-style broadcasting rules, which you can read more about at `NumPy broadcasting`_. Args: shapes: 0 or more shapes specified as sequences of integers Returns: The broadcasted shape as a...
broadcast_shapes
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def broadcast_to(array: ArrayLike, shape: DimSize | Shape, *, out_sharding: NamedSharding | P | None = None) -> Array: """Broadcast an array to a specified shape. JAX implementation of :func:`numpy.broadcast_to`. JAX uses NumPy-style broadcasting rules, which you can read more about at `NumPy br...
Broadcast an array to a specified shape. JAX implementation of :func:`numpy.broadcast_to`. JAX uses NumPy-style broadcasting rules, which you can read more about at `NumPy broadcasting`_. Args: array: array to be broadcast. shape: shape to which the array will be broadcast. Returns: a copy of arr...
broadcast_to
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def split(ary: ArrayLike, indices_or_sections: int | Sequence[int] | ArrayLike, axis: int = 0) -> list[Array]: """Split an array into sub-arrays. JAX implementation of :func:`numpy.split`. Args: ary: N-dimensional array-like object to split indices_or_sections: either a single integer or a seq...
Split an array into sub-arrays. JAX implementation of :func:`numpy.split`. Args: ary: N-dimensional array-like object to split indices_or_sections: either a single integer or a sequence of indices. - if ``indices_or_sections`` is an integer *N*, then *N* must evenly divide ``ary.shape[axis]...
split
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def hsplit(ary: ArrayLike, indices_or_sections: int | Sequence[int] | ArrayLike) -> list[Array]: """Split an array into sub-arrays horizontally. JAX implementation of :func:`numpy.hsplit`. Refer to the documentation of :func:`jax.numpy.split` for details. ``hsplit`` is equivalent to ``split`` with ``axis=1``,...
Split an array into sub-arrays horizontally. JAX implementation of :func:`numpy.hsplit`. Refer to the documentation of :func:`jax.numpy.split` for details. ``hsplit`` is equivalent to ``split`` with ``axis=1``, or ``axis=0`` for one-dimensional arrays. Examples: 1D array: >>> x = jnp.array([1, 2, 3,...
hsplit
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def array_split(ary: ArrayLike, indices_or_sections: int | Sequence[int] | ArrayLike, axis: int = 0) -> list[Array]: """Split an array into sub-arrays. JAX implementation of :func:`numpy.array_split`. Refer to the documentation of :func:`jax.numpy.split` for details; ``array_split`` is equival...
Split an array into sub-arrays. JAX implementation of :func:`numpy.array_split`. Refer to the documentation of :func:`jax.numpy.split` for details; ``array_split`` is equivalent to ``split``, but allows integer ``indices_or_sections`` which does not evenly divide the split axis. Examples: >>> x = jnp.a...
array_split
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def clip( arr: ArrayLike | None = None, /, min: ArrayLike | None = None, max: ArrayLike | None = None, *, a: ArrayLike | DeprecatedArg = DeprecatedArg(), a_min: ArrayLike | None | DeprecatedArg = DeprecatedArg(), a_max: ArrayLike | None | DeprecatedArg = DeprecatedArg() ) -> Array: """Clip array value...
Clip array values to a specified range. JAX implementation of :func:`numpy.clip`. Args: arr: N-dimensional array to be clipped. min: optional minimum value of the clipped range; if ``None`` (default) then result will not be clipped to any minimum value. If specified, it should be broadcast-com...
clip
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def round(a: ArrayLike, decimals: int = 0, out: None = None) -> Array: """Round input evenly to the given number of decimals. JAX implementation of :func:`numpy.round`. Args: a: input array or scalar. decimals: int, default=0. Number of decimal points to which the input needs to be rounded. It mus...
Round input evenly to the given number of decimals. JAX implementation of :func:`numpy.round`. Args: a: input array or scalar. decimals: int, default=0. Number of decimal points to which the input needs to be rounded. It must be specified statically. Not implemented for ``decimals < 0``. o...
round
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def fix(x: ArrayLike, out: None = None) -> Array: """Round input to the nearest integer towards zero. JAX implementation of :func:`numpy.fix`. Args: x: input array. out: unused by JAX. Returns: An array with same shape and dtype as ``x`` containing the rounded values. See also: - :func:`ja...
Round input to the nearest integer towards zero. JAX implementation of :func:`numpy.fix`. Args: x: input array. out: unused by JAX. Returns: An array with same shape and dtype as ``x`` containing the rounded values. See also: - :func:`jax.numpy.trunc`: Rounds the input to nearest integer tow...
fix
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def nan_to_num(x: ArrayLike, copy: bool = True, nan: ArrayLike = 0.0, posinf: ArrayLike | None = None, neginf: ArrayLike | None = None) -> Array: """Replace NaN and infinite entries in an array. JAX implementation of :func:`numpy.nan_to_num`. Args: x: array of values to be repl...
Replace NaN and infinite entries in an array. JAX implementation of :func:`numpy.nan_to_num`. Args: x: array of values to be replaced. If it does not have an inexact dtype it will be returned unmodified. copy: unused by JAX nan: value to substitute for NaN entries. Defaults to 0.0. posinf: ...
nan_to_num
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def allclose(a: ArrayLike, b: ArrayLike, rtol: ArrayLike = 1e-05, atol: ArrayLike = 1e-08, equal_nan: bool = False) -> Array: r"""Check if two arrays are element-wise approximately equal within a tolerance. JAX implementation of :func:`numpy.allclose`. Essentially this function evaluates the follow...
Check if two arrays are element-wise approximately equal within a tolerance. JAX implementation of :func:`numpy.allclose`. Essentially this function evaluates the following condition: .. math:: |a - b| \le \mathtt{atol} + \mathtt{rtol} * |b| ``jnp.inf`` in ``a`` will be considered equal to ``jnp.inf``...
allclose
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def nonzero(a: ArrayLike, *, size: int | None = None, fill_value: None | ArrayLike | tuple[ArrayLike, ...] = None ) -> tuple[Array, ...]: """Return indices of nonzero elements of an array. JAX implementation of :func:`numpy.nonzero`. Because the size of the output of ``nonzero`` is data-dependen...
Return indices of nonzero elements of an array. JAX implementation of :func:`numpy.nonzero`. Because the size of the output of ``nonzero`` is data-dependent, the function is not compatible with JIT and other transformations. The JAX version adds the optional ``size`` argument which must be specified staticall...
nonzero
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def flatnonzero(a: ArrayLike, *, size: int | None = None, fill_value: None | ArrayLike | tuple[ArrayLike, ...] = None) -> Array: """Return indices of nonzero elements in a flattened array JAX implementation of :func:`numpy.flatnonzero`. ``jnp.flatnonzero(x)`` is equivalent to ``nonzero(ravel(a))...
Return indices of nonzero elements in a flattened array JAX implementation of :func:`numpy.flatnonzero`. ``jnp.flatnonzero(x)`` is equivalent to ``nonzero(ravel(a))[0]``. For a full discussion of the parameters to this function, refer to :func:`jax.numpy.nonzero`. Args: a: N-dimensional array. size: ...
flatnonzero
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def unwrap(p: ArrayLike, discont: ArrayLike | None = None, axis: int = -1, period: ArrayLike = 2 * np.pi) -> Array: """Unwrap a periodic signal. JAX implementation of :func:`numpy.unwrap`. Args: p: input array discont: the maximum allowable discontinuity in the sequence. The default is ...
Unwrap a periodic signal. JAX implementation of :func:`numpy.unwrap`. Args: p: input array discont: the maximum allowable discontinuity in the sequence. The default is ``period / 2`` axis: the axis along which to unwrap; defaults to -1 period: the period of the signal, which defaults to :mat...
unwrap
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def pad(array: ArrayLike, pad_width: PadValueLike[int | Array | np.ndarray], mode: str | Callable[..., Any] = "constant", **kwargs) -> Array: """Add padding to an array. JAX implementation of :func:`numpy.pad`. Args: array: array to pad. pad_width: specify the pad width for each dimension of an ...
Add padding to an array. JAX implementation of :func:`numpy.pad`. Args: array: array to pad. pad_width: specify the pad width for each dimension of an array. Padding widths may be separately specified for *before* and *after* the array. Options are: - ``int`` or ``(int,)``: pad each array dim...
pad
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0
def stack(arrays: np.ndarray | Array | Sequence[ArrayLike], axis: int = 0, out: None = None, dtype: DTypeLike | None = None) -> Array: """Join arrays along a new axis. JAX implementation of :func:`numpy.stack`. Args: arrays: a sequence of arrays to stack; each must have the same shape. If a ...
Join arrays along a new axis. JAX implementation of :func:`numpy.stack`. Args: arrays: a sequence of arrays to stack; each must have the same shape. If a single array is given it will be treated equivalently to `arrays = unstack(arrays)`, but the implementation will avoid explicit unstacking...
stack
python
jax-ml/jax
jax/_src/numpy/lax_numpy.py
https://github.com/jax-ml/jax/blob/master/jax/_src/numpy/lax_numpy.py
Apache-2.0