Expand description
Lazy array graph, primitives, dtypes, streams and evaluation: the core of nuvec.
Operations on Arrays record a graph and return immediately. Nothing is computed
until an array is evaluated, explicitly or by reading it back:
use nuvec_core::{Array, Result};
let a = Array::from_slice(&[1.0f32, 2.0, 3.0], &[3])?;
let b = Array::full(&[3], 10.0f32)?;
let c = (&a + &b) * &a; // lazy: nothing computed yet
assert!(!c.is_evaluated());
assert_eq!(c.to_vec::<f32>()?, vec![11.0, 24.0, 39.0]);Binary operations promote types (MLX’s table) and broadcast shapes (NumPy rules); views
(reshape, transpose, slice, broadcast_to, expand_dims, squeeze) share data.
Reductions (sum, mean, max, argmax, …) work over any axes and layouts;
matmul broadcasts batch dimensions and uses a SIMD GEMM on the CPU.
Status: pre-alpha. Evaluated on the CPU.
Structs§
- Array
- A lazily evaluated n-dimensional array.
- Complex64
- A complex number with
f32parts, the element type ofDType::Complex64. - Device
- A processor that executes array operations.
- Flags
- How an array’s elements are laid out in memory.
- Slice
Arg - One slice specification per dimension:
start:stop:stepwith Python semantics. - Stream
- An ordered queue of operations on a device.
- bf16
- A 16-bit floating point type implementing the
bfloat16format. - f16
- A 16-bit floating point type implementing the IEEE 754-2008 standard
binary16a.k.a “half” format.
Enums§
- ArgReduce
Op - The position of an extreme value along one axis.
- Binary
Op - An element-wise function of two operands.
- Category
- The broad kind of an element type, used for type promotion.
- DType
- The element type of an array.
- Device
Kind - The kind of processor a device is.
- Error
- Why an operation failed.
- Primitive
- An operation recorded in the graph, with its parameters.
- Reduce
Op - A reduction over a set of axes.
- UnaryOp
- An element-wise function of one operand.
Constants§
- VERSION
- The version of this crate.
Traits§
- Element
- A Rust type that can be stored in an array. Implemented for the element types of
every
DType; sealed.
Functions§
- abs
- Element-wise absolute value; the float32 magnitude for complex numbers.
- add
- Element-wise
a + b, with promotion and broadcasting. Integers wrap; for booleans this is logical OR. - all
- Whether every element over
axes(empty = all) is non-zero. - any
- Whether any element over
axes(empty = all) is non-zero. - arange
- Evenly spaced values
start, start + step, …belowstop(above it for negative steps), converted todtype. The length isceil((stop - start) / step), as in MLX. - argmax
- Index (uint32) of the maximum along
axis, or over the flattened array ifNone. The first occurrence wins; the first NaN wins over any number. - argmin
- Index (uint32) of the minimum along
axis, or over the flattened array ifNone. The first occurrence wins; the first NaN wins over any number. - astype
- Converts the elements to
dtype. Float-to-integer conversion saturates (NaN becomes 0); conversion to bool tests for non-zero; complex-to-real keeps the real part. - at_
least_ float dif it is floating point or complex, otherwise the promotion ofdwith float32. Transcendental functions and division compute in this type.- broadcast_
to - Presents
aas the largershape(NumPy broadcasting rules). Shares the data. - cos
- Element-wise cosine, in at least float32.
- default_
stream - The stream new operations on this thread are recorded on.
- divide
- Element-wise true division
a / b. Integer operands are promoted to floating point. - equal
- Element-wise
a == bas a bool array. - eval
- Evaluates
arraysand everything they depend on. Each node runs at most once, even across threads. - exp
- Element-wise
e^a, in at least float32. - expand_
dims - Inserts a dimension of size 1 at
axis(negative counts from the end of the result). Shares the data. - greater
- Element-wise
a > bas a bool array. Not defined for complex numbers. - greater_
equal - Element-wise
a >= bas a bool array. Not defined for complex numbers. - less
- Element-wise
a < bas a bool array. Not defined for complex numbers. - less_
equal - Element-wise
a <= bas a bool array. Not defined for complex numbers. - log
- Element-wise natural logarithm, in at least float32.
- matmul
- Matrix product of
[..., M, K]and[..., K, N], broadcasting batch dimensions. - max
- Maximum over
axes(empty = all); NaN propagates. Zero-length axes are an error. - maximum
- Element-wise maximum; NaN propagates. Not defined for complex numbers.
- mean
- Mean over
axes(empty = all), in at least float32. Empty reductions are NaN. - min
- Minimum over
axes(empty = all); NaN propagates. Zero-length axes are an error. - minimum
- Element-wise minimum; NaN propagates. Not defined for complex numbers.
- multiply
- Element-wise
a * b, with promotion and broadcasting. Integers wrap; for booleans this is logical AND. - negative
- Element-wise
-a. Integers wrap. Not defined for booleans. - not_
equal - Element-wise
a != bas a bool array. - ones
- An array of ones.
- prod
- Product over
axes(empty = all), with the same widening assum. - promote_
types - The element type two operands are converted to before a binary operation, following MLX’s promotion table.
- reshape
- The same elements in another shape; one dimension may be
-1(inferred). Shares the data when the layout permits, otherwise copies. - set_
default_ stream - Sets the stream new operations on this thread are recorded on.
- sigmoid
- Element-wise logistic function
1 / (1 + e^-a), in at least float32. - sin
- Element-wise sine, in at least float32.
- slice
- Selects
start:stop:stepin every dimension, with Python semantics (negative indices count from the end, bounds are clamped, steps may be negative). Shares the data. - sqrt
- Element-wise square root, in at least float32.
- squeeze
- Removes dimensions of size 1: the given
axes, or all of them ifaxesis empty. Shares the data. - subtract
- Element-wise
a - b, with promotion and broadcasting. Integers wrap; for booleans this is logical XOR. - sum
- Sum over
axes(empty = all). Integers and bools widen to 32 or 64 bits (as in MLX); half and single precision accumulate in double precision. - tanh
- Element-wise hyperbolic tangent, in at least float32.
- transpose
- Reorders the axes: output axis
iis input axisaxes[i]. Shares the data. - where_
- Element-wise selection:
awhereconditionis true, otherwiseb. - zeros
- An array of zeros.