yscv_tensor/lib.rs
1//! Tensor types and numeric primitives for the yscv framework.
2//!
3//! # Tensor type
4//!
5//! [`Tensor`] is the core n-dimensional array. It stores contiguous, 64-byte
6//! aligned `f32` data and carries its own shape and strides. FP16 and BF16
7//! storage is supported via [`DType`] and the conversion helpers
8//! [`Tensor::to_dtype`], [`Tensor::from_f16`], and [`Tensor::from_bf16`].
9//!
10//! # Supported dtypes
11//!
12//! | Variant | Backing store | Notes |
13//! |---------|---------------|-------|
14//! | `F32` | `AlignedVec<f32>` | Default, SIMD-accelerated ops |
15//! | `F16` | `AlignedVec<u16>` | IEEE 754 half-precision bit patterns |
16//! | `BF16` | `AlignedVec<u16>` | Brain floating-point bit patterns |
17//!
18//! Arithmetic operations require `F32`. Convert with [`Tensor::to_dtype`]
19//! before performing math on F16/BF16 tensors.
20//!
21//! # Broadcasting
22//!
23//! Binary operations (`add`, `sub`, `mul`, `div`, `pow`, etc.) follow
24//! NumPy-style broadcasting rules:
25//!
26//! 1. Shapes are right-aligned. Missing leading dimensions are treated as 1.
27//! 2. Dimensions of size 1 are stretched to match the other operand.
28//! 3. If dimensions differ and neither is 1, the operation returns
29//! [`TensorError::BroadcastIncompatible`].
30//!
31//! Example: `[3, 1, 5] + [4, 5]` broadcasts to `[3, 4, 5]`.
32#![allow(unsafe_code)]
33
34mod core;
35
36pub use core::*;