Expand description
Array operations as free functions with MLX’s names: the mirrors of the Array
methods.
Every operation whose first argument is an array is a method, and the method is the
canonical, documented form: x.sum(-1), x.matmul(&w.t()), m.select(&a, 0.0). This
module holds the same operations as free functions with MLX’s names and the same
parameters (the receiver becomes the first argument), so MLX code ports line by line:
sum(&x, -1), matmul(&x, &w.t()), where_(&m, &a, 0.0). A few operations exist only
here because their first argument is not one array: concatenate, stack,
where_ and the constructors (zeros, ones, full, arange).
Operations return Array, never Result: invalid arguments give a failed array
carrying crate::Error::Op with the operation’s name and the caller’s source location,
and every array computed from it fails with the same error, surfacing at
Array::check, Array::eval, Array::item or Array::to_vec.
use nuvec_core::{Array, array, ops};
let x = array![[1.0, 2.0], [3.0, 4.0]];
let a = x.exp().sum(-1);
let b = ops::sum(&ops::exp(&x), -1);
assert_eq!(a.to_vec::<f32>().unwrap(), b.to_vec::<f32>().unwrap());Functions§
- abs
- Element-wise
abs; seeArray::abs. - add
- Element-wise
add; seeArray::add. Either operand may be a weak Rust number. - addmm
alpha · (a @ b) + beta · c; seeArray::addmm.- all
- Whether every element is non-zero over
axes; seeArray::all. - all_
keepdims - Whether every element is non-zero over
axes, keeping them as size-1 dimensions; seeArray::all_keepdims. - any
- Whether any element is non-zero over
axes; seeArray::any. - any_
keepdims - Whether any element is non-zero over
axes, keeping them as size-1 dimensions; seeArray::any_keepdims. - arange
- Evenly spaced values
start, start + step, …belowstop(above it for a negative step), as MLX: int32 when every argument is an integer (int64 when they do not fit), float32 when any is a float. UseArray::astypefor another dtype. - argmax
- Indices (uint32) of the maxima along one axis (
..: the flattened array); seeArray::argmax. - argmax_
keepdims argmaxkeeping the reduced axis; seeArray::argmax_keepdims.- argmin
- Indices (uint32) of the minima along one axis (
..: the flattened array); seeArray::argmin. - argmin_
keepdims argminkeeping the reduced axis; seeArray::argmin_keepdims.- argpartition
- The indices (uint32) that partition the array; see
Array::argpartition. - argsort
- The indices (uint32) that sort the array along one axis; see
Array::argsort. - astype
- The elements converted to
dtype; seeArray::astype. - broadcast_
to - The array broadcast to
shape; seeArray::broadcast_to. - concatenate
arraysjoined alongaxis(MLX’sconcatenate); dtypes are promoted.- conjugate
- Element-wise
conjugate; seeArray::conjugate. - contiguous
- Element-wise
contiguous; seeArray::contiguous. - conv1d
- A 1-D convolution of
[N, L, C_in]with[C_out, K, C_in / groups]; seeArray::conv1d. - copy
- Element-wise
copy; seeArray::copy. - cos
- Element-wise
cos; seeArray::cos. - cummax
- The running maximum along one axis (
..: the flattened array); seeArray::cummax. - cummax_
with - The running maximum with
ScanOptions; seeArray::cummax_with. - cummin
- The running minimum along one axis (
..: the flattened array); seeArray::cummin. - cummin_
with - The running minimum with
ScanOptions; seeArray::cummin_with. - cumprod
- The cumulative product along one axis (
..: the flattened array); seeArray::cumprod. - cumprod_
with - The cumulative product with
ScanOptions; seeArray::cumprod_with. - cumsum
- The cumulative sum along one axis (
..: the flattened array); seeArray::cumsum. - cumsum_
with - The cumulative sum with
ScanOptions; seeArray::cumsum_with. - dequantize
- The weights of
quantizerestored, indtype(default: the scales’ dtype for affine, bfloat16 for the floating-point modes); MLX’sdequantize. See alsoQuantized::dequantize. - divide
- Element-wise
divide; seeArray::divide. Either operand may be a weak Rust number. - equal
- Element-wise
equal; seeArray::equal. Either operand may be a weak Rust number. - erfinv
- Element-wise
erfinv; seeArray::erfinv. - exp
- Element-wise
exp; seeArray::exp. - expand_
dims - Size-1 dimensions inserted at
axes(positions in the result); seeArray::expand_dims. - floor_
divide - Element-wise
floor_divide; seeArray::floor_divide. Either operand may be a weak Rust number. - from_
fp8 - E4M3 bytes as
dtypefloats (MLX’sfrom_fp8); seeArray::from_fp8. - full
- An array of
shapewith every elementvalue: a Rust number is weak, as in MLX (0.5gives float32,1int32), and an array keeps its dtype (Array::from(7u8)gives uint8). - full_
like value(a weak scalar takesa’s dtype) ina’s shape; seeArray::full_like.- gather_
mm - Products of gathered matrices; see
Array::gather_mm. - gather_
qmm - Quantized products of gathered matrices (mixture-of-experts layers); see
Array::gather_qmm. - greater
- Element-wise
greater; seeArray::greater. Either operand may be a weak Rust number. - greater_
equal - Element-wise
greater_equal; seeArray::greater_equal. Either operand may be a weak Rust number. - less
- Element-wise
less; seeArray::less. Either operand may be a weak Rust number. - less_
equal - Element-wise
less_equal; seeArray::less_equal. Either operand may be a weak Rust number. - log
- Element-wise
log; seeArray::log. - logaddexp
- Element-wise
logaddexp; seeArray::logaddexp. Either operand may be a weak Rust number. - logcumsumexp
- The running
log(Σ exp)along one axis (..: the flattened array); seeArray::logcumsumexp. - logcumsumexp_
with - The running
log(Σ exp)withScanOptions; seeArray::logcumsumexp_with. - logsumexp
log(sum(exp(a))), computed stably, overaxes; seeArray::logsumexp.- logsumexp_
keepdims log(sum(exp(a))), computed stably, overaxes, keeping them as size-1 dimensions; seeArray::logsumexp_keepdims.- matmul
- Matrix product; see
Array::matmul. - max
- The maximum over
axes; seeArray::max. - max_
keepdims - The maximum over
axes, keeping them as size-1 dimensions; seeArray::max_keepdims. - maximum
- Element-wise
maximum; seeArray::maximum. Either operand may be a weak Rust number. - mean
- The mean over
axes; seeArray::mean. - mean_
keepdims - The mean over
axes, keeping them as size-1 dimensions; seeArray::mean_keepdims. - min
- The minimum over
axes; seeArray::min. - min_
keepdims - The minimum over
axes, keeping them as size-1 dimensions; seeArray::min_keepdims. - minimum
- Element-wise
minimum; seeArray::minimum. Either operand may be a weak Rust number. - multiply
- Element-wise
multiply; seeArray::multiply. Either operand may be a weak Rust number. - negative
- Element-wise
negative; seeArray::negative. - not_
equal - Element-wise
not_equal; seeArray::not_equal. Either operand may be a weak Rust number. - ones
- An array of ones of
shape. - ones_
like - Ones of
a’s shape and dtype; seeArray::ones_like. - partition
- The array partitioned around position
kthalong one axis; seeArray::partition. - power
- Element-wise
power; seeArray::power. Either operand may be a weak Rust number. - prod
- The product over
axes; seeArray::prod. - prod_
keepdims - The product over
axes, keeping them as size-1 dimensions; seeArray::prod_keepdims. - put_
along_ axis - A copy with
valuesplaced atindicesalongaxis; seeArray::put_along_axis. - quantize
wquantized along its last axis; seeArray::quantize.- quantized_
matmul x · dequantize(w)ᵀ(or without the transpose); seeArray::quantized_matmul.- repeat
- Each element repeated
repeatstimes along one axis; seeArray::repeat. - reshape
- The same elements in another shape (one
-1inferred); seeArray::reshape. - scatter_
add_ along_ axis - A copy with
valuesadded atindicesalongaxis(repeated indices accumulate); seeArray::scatter_add_along_axis. - sigmoid
- Element-wise
sigmoid; seeArray::sigmoid. - sign
- Element-wise
sign; seeArray::sign. - sin
- Element-wise
sin; seeArray::sin. - slice_
update - A copy of
awith the region atindexreplaced byupdate; seeArray::slice_update. - softmax
exp(a) / sum(exp(a))overaxes; seeArray::softmax.- sort
- The array sorted along one axis; see
Array::sort. - split
- The array split into
partsequal parts alongaxis; seeArray::split. - split_
at - The array split before each of
indicesalongaxis; seeArray::split_at. - split_n
- The array split into
Nequal parts alongaxis; seeArray::split_n. - sqrt
- Element-wise
sqrt; seeArray::sqrt. - squeeze
- Size-1 dimensions removed (
..: all of them); seeArray::squeeze. - stack
arrays(one shape) stacked along a new axisaxis(MLX’sstack).- std
- The standard deviation over
axes; seeArray::std. - std_
keepdims - The standard deviation over
axes, keeping them as size-1 dimensions; seeArray::std_keepdims. - std_
with - The standard deviation over
axeswithVarOptions; seeArray::std_with. - stop_
gradient - Element-wise
stop_gradient; seeArray::stop_gradient. - subtract
- Element-wise
subtract; seeArray::subtract. Either operand may be a weak Rust number. - sum
- The sum over
axes; seeArray::sum. - sum_
keepdims - The sum over
axes, keeping them as size-1 dimensions; seeArray::sum_keepdims. - take
- The elements at
indicesalong one axis (..: the flattened array); seeArray::take. - take_
along_ axis - The elements at
indicesalongaxis; seeArray::take_along_axis. - tanh
- Element-wise
tanh; seeArray::tanh. - to_fp8
- Floats as E4M3 bytes (MLX’s
to_fp8); seeArray::to_fp8. - topk
- The
klargest elements along one axis; seeArray::topk. - transpose
- The axes reordered (
..: reversed); seeArray::transpose. - var
- The variance over
axes; seeArray::var. - var_
keepdims - The variance over
axes, keeping them as size-1 dimensions; seeArray::var_keepdims. - var_
with - The variance over
axeswithVarOptions; seeArray::var_with. - view
x’s bits asdtype(MLX’sview); seeArray::view.- where_
- Element-wise selection:
awhereconditionis true, elseb(MLX’swhere); seeArray::select. Any operand may be a weak Rust number. - zeros
- An array of zeros of
shape. - zeros_
like - Zeros of
a’s shape and dtype; seeArray::zeros_like.