Skip to main content

Crate nuvec_core

Crate nuvec_core 

Source
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 f32 parts, the element type of DType::Complex64.
Device
A processor that executes array operations.
Flags
How an array’s elements are laid out in memory.
SliceArg
One slice specification per dimension: start:stop:step with Python semantics.
Stream
An ordered queue of operations on a device.
bf16
A 16-bit floating point type implementing the bfloat16 format.
f16
A 16-bit floating point type implementing the IEEE 754-2008 standard binary16 a.k.a “half” format.

Enums§

ArgReduceOp
The position of an extreme value along one axis.
BinaryOp
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.
DeviceKind
The kind of processor a device is.
Error
Why an operation failed.
Primitive
An operation recorded in the graph, with its parameters.
ReduceOp
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, … below stop (above it for negative steps), converted to dtype. The length is ceil((stop - start) / step), as in MLX.
argmax
Index (uint32) of the maximum along axis, or over the flattened array if None. The first occurrence wins; the first NaN wins over any number.
argmin
Index (uint32) of the minimum along axis, or over the flattened array if None. 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
d if it is floating point or complex, otherwise the promotion of d with float32. Transcendental functions and division compute in this type.
broadcast_to
Presents a as the larger shape (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 == b as a bool array.
eval
Evaluates arrays and 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 > b as a bool array. Not defined for complex numbers.
greater_equal
Element-wise a >= b as a bool array. Not defined for complex numbers.
less
Element-wise a < b as a bool array. Not defined for complex numbers.
less_equal
Element-wise a <= b as 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 != b as a bool array.
ones
An array of ones.
prod
Product over axes (empty = all), with the same widening as sum.
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:step in 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 if axes is 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 i is input axis axes[i]. Shares the data.
where_
Element-wise selection: a where condition is true, otherwise b.
zeros
An array of zeros.

Type Aliases§

Result
Result with Error as the error type.