Skip to main content

nuvec_core/
lib.rs

1//! Lazy array graph, primitives, dtypes, streams and evaluation: the core of nuvec.
2//!
3//! Operations on [`Array`]s record a graph and return immediately. Nothing is computed
4//! until an array is evaluated, explicitly or by reading it back:
5//!
6//! ```
7//! use nuvec_core::{Array, Result};
8//!
9//! # fn main() -> Result<()> {
10//! let a = Array::from_slice(&[1.0f32, 2.0, 3.0], &[3])?;
11//! let b = Array::full(&[3], 10.0f32)?;
12//! let c = (&a + &b) * &a; // lazy: nothing computed yet
13//! assert!(!c.is_evaluated());
14//! assert_eq!(c.to_vec::<f32>()?, vec![11.0, 24.0, 39.0]);
15//! # Ok(())
16//! # }
17//! ```
18//!
19//! Binary operations promote types (MLX's table) and broadcast shapes (NumPy rules); views
20//! (`reshape`, `transpose`, `slice`, `broadcast_to`, `expand_dims`, `squeeze`) share data.
21//!
22//! Reductions (`sum`, `mean`, `max`, `argmax`, …) work over any axes and layouts;
23//! `matmul` broadcasts batch dimensions and uses a SIMD GEMM on the CPU.
24//!
25//! **Status:** pre-alpha. Evaluated on the CPU.
26
27#![forbid(unsafe_code)]
28
29mod array;
30mod buffer;
31mod cast;
32mod device;
33mod dtype;
34mod error;
35mod eval;
36mod kernels;
37mod ops;
38mod primitive;
39mod shape;
40mod view;
41
42pub use array::Array;
43pub use device::{Device, DeviceKind, Stream, default_stream, set_default_stream};
44pub use dtype::{Category, Complex64, DType, Element, at_least_float, bf16, f16, promote_types};
45pub use error::{Error, Result};
46pub use eval::eval;
47pub use ops::{
48    abs, add, all, any, arange, argmax, argmin, astype, broadcast_to, cos, divide, equal, exp,
49    expand_dims, greater, greater_equal, less, less_equal, log, matmul, max, maximum, mean, min,
50    minimum, multiply, negative, not_equal, ones, prod, reshape, sigmoid, sin, slice, sqrt,
51    squeeze, subtract, sum, tanh, transpose, where_, zeros,
52};
53pub use primitive::{ArgReduceOp, BinaryOp, Primitive, ReduceOp, UnaryOp};
54pub use shape::Flags;
55pub use view::SliceArg;
56
57/// The version of this crate.
58pub const VERSION: &str = env!("CARGO_PKG_VERSION");