Skip to main content

Module array

Module array 

Source
Expand description

Array operations on row-major buffers.

Each function takes the elements of its operands as slices with their shapes, and returns the elements of the result. Shapes are assumed to have been checked (by shape inference); the functions panic on inconsistent inputs.

Structs§

DotDims
The dimensions that dot_general contracts and batches over. The result has the batch dimensions, then the free dimensions of the left operand, then those of the right operand.
GatherDims
StableHLO’s gather dimension numbers; the index vector is the last dimension of the indices, as in JAX.
ScatterDims
StableHLO’s scatter dimension numbers; the index vector is the last dimension of the indices, as in JAX.

Enums§

CumulativeOp
The operation of a cumulative reduction (cumsum and the like).
GatherScatterMode
How gather and scatter treat out-of-bounds indices.
ReduceOp
A reduction.

Functions§

arg_min_max
The index of the largest (max) or smallest element along axis. NaN counts as the extreme, and ties take the first index, as in JAX.
broadcast_in_dim
broadcast_in_dim: dimension i of x becomes dimension dims[i] of the result, which has shape out_shape.
broadcast_in_dim_into
broadcast_in_dim written to out (of size(out_shape) elements).
clamp
clamp(lo, x, hi), propagating NaN; lo and hi are scalars or have the shape of x.
clamp_starts
Clamps start indices so that a window of sizes stays inside shape, as XLA does for dynamic_slice and dynamic_update_slice.
concatenate
concatenate along dim.
cumulative
A cumulative reduction along axis (inclusive; from the end with reverse), combining elements in the order XLA does on CPU.
cumulative_into
cumulative written to out (of the size of x).
dot_general
dot_general: sums of products over the contracting dimensions, in the operands’ type.
dot_shape
The shape of the result of dot_general.
dynamic_slice
dynamic_slice: a window of sizes at (clamped) starts.
dynamic_update_slice
dynamic_update_slice: x with update written at (clamped) starts.
free_dims
The dimensions of an operand that are neither contracted nor batched.
gather
gather, with start indices clamped so that slices are in bounds (the semantics of every mode that gather supports).
gather_shape
The shape of the result of a gather.
iota
iota: the index along dim of each element of shape.
iota_into
iota written to out (of size(shape) elements), without allocating.
pad
pad: for each dimension, (low, high, interior) padding with value. Negative low or high removes elements.
ravel
Converts a multi-index into a flat index, given strides.
reduce
Reduces x over axes, combining elements in row-major order.
reduce_all
x folded by op from op’s identity, element by element in order. Integers and booleans, whose operations are associative, are folded in eight lanes, which gives the same result.
reduced_shape
Returns shape without axes.
rev
rev: reverses the elements along dims.
scatter
scatter: combines updates into x with combine(old, update) (or replaces when combine is None), in row-major order of the updates. With Clip, start indices are clamped; otherwise windows that are not entirely in bounds are skipped, as XLA does.
scatter_window
The size of the window of a scatter in each operand dimension.
select_n
select_n: element i comes from cases[which[i]] (which is a scalar or has the shape of the cases). Out-of-range indices are clamped.
size
Returns the number of elements of shape.
slice
slice with static bounds and strides.
sort
sort: sorts the operands (of the same shape) along dim, stably and lexicographically by the first num_keys of them in sort_order.
sort_order
The order of lax.sort keys: integers and booleans in their natural order, and floats in the total order -inf < ... < 0 < ... < inf < NaN in which -0.0 equals 0.0 and all NaNs are equal, as JAX’s comparator makes it by canonicalizing zeros and NaNs before a total-order comparison.
sort_permutation
The permutation that sorts along dim stably by cmp, which compares the flat indices of two elements: for each element of the result, the flat index of the element it comes from.
strided_gather
The elements of x at sum(index[d] * src_strides[d]) for every index of out_shape, in row-major order: the positions advance by adding strides, and the innermost dimension is filled, copied, or gathered.
strided_gather_into
strided_gather written to out (of size(out_shape) elements), without allocating for up to 8 dimensions.
strides
Returns the row-major strides of shape.
top_k
top_k along axis: the k largest elements of each line in descending order (ties in their original order), and their indices.
transpose
transpose: dimension i of the result is dimension perm[i] of x.
transpose_into
transpose written to out (of size(shape) elements), without allocating for up to 8 dimensions.
unravel
Converts a flat index into a multi-index.