| Crates.io | tenrso-core |
| lib.rs | tenrso-core |
| version | 0.1.0-alpha.2 |
| created_at | 2025-11-08 08:46:37.897777+00 |
| updated_at | 2025-12-17 06:32:28.235906+00 |
| description | Core tensor types, views, and axis metadata for TenRSo |
| homepage | https://github.com/cool-japan/tenrso |
| repository | https://github.com/cool-japan/tenrso |
| max_upload_size | |
| id | 1922660 |
| size | 706,613 |
Core tensor types, axis metadata, views, and basic operations for TenRSo.
tenrso-core provides the foundational tensor abstraction for the TenRSo ecosystem. It defines:
scirs2_core::ndarray_extAdd to your Cargo.toml:
[dependencies]
tenrso-core = "0.1"
use tenrso_core::{TensorHandle, AxisMeta};
use scirs2_core::ndarray_ext::Array;
// Create a 3D tensor
let data = Array::zeros(vec![10, 20, 30]);
let axes = vec![
AxisMeta::new("batch", 10),
AxisMeta::new("height", 20),
AxisMeta::new("width", 30),
];
let tensor = TensorHandle::from_dense(data, axes);
println!("Rank: {}", tensor.rank());
println!("Shape: {:?}", tensor.shape());
use tenrso_core::AxisMeta;
let axis = AxisMeta::new("channels", 128);
assert_eq!(axis.name, "channels");
assert_eq!(axis.size, 128);
use tenrso_core::DenseND;
let tensor = DenseND::zeros(&[100, 200, 300]);
let view = tensor.slice(&[s![0..10], s![..], s![50..100]]);
// Zero-copy view into subset of data
use tenrso_core::DenseND;
// Unfold along mode 1 (matricize)
let tensor = DenseND::zeros(&[10, 20, 30]);
let matrix = tensor.unfold(1)?; // Shape: (20, 10*30)
// Fold back to original shape
let reconstructed = matrix.fold(&[10, 20, 30], 1)?;
TensorHandle<T> // Unified handle for all representations
├── TensorRepr<T> // Enum of representations
│ ├── Dense(DenseND<T>) // Dense storage
│ ├── Sparse(SparseND<T>) // Sparse storage (from tenrso-sparse)
│ └── LowRank(LowRank<T>) // Low-rank (CP/Tucker/TT)
└── Vec<AxisMeta> // Axis metadata
DenseND<T>
├── data: Array<T, IxDyn> // N-D array from scirs2_core
├── strides: Vec<usize> // Memory strides
└── offset: usize // Base offset for views
Axis - Type alias for usize (axis index)Rank - Type alias for usize (number of dimensions)Shape - SmallVec for tensor dimensions (optimized for ≤6D)AxisMeta - Metadata for a single axis (name + size)TensorRepr<T> - Enum of tensor representationsTensorHandle<T> - Main tensor handleTensorHandle:
rank() -> Rank - Get number of dimensionsshape() -> Shape - Get tensor shapefrom_dense(data, axes) -> Self (TODO)from_sparse(data, axes) -> Self (TODO)from_lowrank(factors, axes) -> Self (TODO)DenseND (TODO: M1):
zeros(shape) -> Self - Create zero-initialized tensorones(shape) -> Self - Create one-initialized tensorfrom_array(array) -> Self - Create from ndarrayview() -> DenseView<T> - Get immutable viewview_mut() -> DenseMut<T> - Get mutable viewslice(&[SliceInfo]) -> DenseView<T> - Slice tensorunfold(mode) -> Array2<T> - Mode-n matricizationreshape(new_shape) -> Result<Self> - Change shapepermute(axes) -> Self - Permute dimensionsdefault - Standard featuresserde - Enable serialization/deserializationSee examples/ directory:
basic_tensor.rs - Creating and manipulating tensors (TODO)views.rs - Zero-copy views and slicing (TODO)unfold_fold.rs - Mode-n matricization (TODO)Run examples:
cargo run --example basic_tensor
# Run unit tests
cargo test
# Run with all features
cargo test --all-features
# Run property tests
cargo test --test properties
See ../../CONTRIBUTING.md for development guidelines.
Apache-2.0