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_generalcontracts and batches over. The result has the batch dimensions, then the free dimensions of the left operand, then those of the right operand. - Gather
Dims - StableHLO’s gather dimension numbers; the index vector is the last dimension of the indices, as in JAX.
- Scatter
Dims - StableHLO’s scatter dimension numbers; the index vector is the last dimension of the indices, as in JAX.
Enums§
- Cumulative
Op - The operation of a cumulative reduction (
cumsumand the like). - Gather
Scatter Mode - How
gatherandscattertreat out-of-bounds indices. - Reduce
Op - A reduction.
Functions§
- arg_
min_ max - The index of the largest (
max) or smallest element alongaxis. NaN counts as the extreme, and ties take the first index, as in JAX. - broadcast_
in_ dim broadcast_in_dim: dimensioniofxbecomes dimensiondims[i]of the result, which has shapeout_shape.- broadcast_
in_ dim_ into broadcast_in_dimwritten toout(ofsize(out_shape)elements).- clamp
clamp(lo, x, hi), propagating NaN;loandhiare scalars or have the shape ofx.- clamp_
starts - Clamps start indices so that a window of
sizesstays insideshape, as XLA does fordynamic_sliceanddynamic_update_slice. - concatenate
concatenatealongdim.- cumulative
- A cumulative reduction along
axis(inclusive; from the end withreverse), combining elements in the order XLA does on CPU. - cumulative_
into cumulativewritten toout(of the size ofx).- 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 ofsizesat (clamped)starts.- dynamic_
update_ slice dynamic_update_slice:xwithupdatewritten 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 alongdimof each element ofshape.- iota_
into iotawritten toout(ofsize(shape)elements), without allocating.- pad
pad: for each dimension,(low, high, interior)padding withvalue. Negativeloworhighremoves elements.- ravel
- Converts a multi-index into a flat index, given strides.
- reduce
- Reduces
xoveraxes, combining elements in row-major order. - reduce_
all xfolded byopfromop’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
shapewithoutaxes. - rev
rev: reverses the elements alongdims.- scatter
scatter: combinesupdatesintoxwithcombine(old, update)(or replaces whencombineisNone), in row-major order of the updates. WithClip, 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: elementicomes fromcases[which[i]](whichis a scalar or has the shape of the cases). Out-of-range indices are clamped.- size
- Returns the number of elements of
shape. - slice
slicewith static bounds and strides.- sort
sort: sorts the operands (of the same shape) alongdim, stably and lexicographically by the firstnum_keysof them insort_order.- sort_
order - The order of
lax.sortkeys: integers and booleans in their natural order, and floats in the total order-inf < ... < 0 < ... < inf < NaNin which-0.0equals0.0and 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
dimstably bycmp, 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
xatsum(index[d] * src_strides[d])for every index ofout_shape, in row-major order: the positions advance by adding strides, and the innermost dimension is filled, copied, or gathered. - strided_
gather_ into strided_gatherwritten toout(ofsize(out_shape)elements), without allocating for up to 8 dimensions.- strides
- Returns the row-major strides of
shape. - top_k
top_kalongaxis: theklargest elements of each line in descending order (ties in their original order), and their indices.- transpose
transpose: dimensioniof the result is dimensionperm[i]ofx.- transpose_
into transposewritten toout(ofsize(shape)elements), without allocating for up to 8 dimensions.- unravel
- Converts a flat index into a multi-index.