tenferro_tensor/lib.rs
1//! Core tensor types, views, backend traits, and backend-independent contracts.
2//!
3//! # Owned Tensors And Views
4//!
5//! [`TypedTensor<T>`](TypedTensor) and the dtype-erased [`Tensor`] enum are
6//! owned tensor values. They are the right representation when a result is
7//! materialized as compact column-major storage.
8//!
9//! [`TypedTensorView`] is a borrowed typed view over an existing tensor buffer.
10//! It carries logical shape, arbitrary strides, and an offset, so metadata-only
11//! layout changes such as transposes, slices, and broadcasts can be represented
12//! without copying. A view can be materialized explicitly with
13//! [`TypedTensorView::to_contiguous`] when a compact owned tensor is required.
14//!
15//! [`TensorRead`] is the dtype-erased borrowed input type used by eager kernels
16//! and backend dispatch. It can borrow either an owned [`Tensor`] or a
17//! [`TensorView`] with arbitrary strides. Prefer `TensorRead` for read-only
18//! operation inputs so callers are not forced to materialize layout-only views.
19//!
20//! [`TensorOwnedView`] and [`TensorValue`] are the owned lazy-value forms. Use
21//! them when an API must store a view result beyond the lifetime of a borrowed
22//! input, then expose a short-lived `TensorRead` at kernel-dispatch time.
23//!
24//! Use [`Tensor::as_slice`] or [`TypedTensorView::as_slice`] only when compact
25//! contiguous storage is part of the API contract. Use shape/stride-aware kernel
26//! paths or `TensorRead` otherwise.
27//!
28//! # Examples
29//!
30//! ```rust
31//! use tenferro_tensor::{Tensor, TypedTensor};
32//!
33//! let a = Tensor::F64(TypedTensor::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap());
34//! assert_eq!(a.shape(), &[2]);
35//! ```
36
37/// Lightweight backend-independent host tensor data model.
38///
39/// Execution-capable tensors and backends in this crate remain separate from
40/// the host-only core model during the crate-boundary split.
41pub mod core {
42 pub use tenferro_tensor_core::*;
43}
44
45pub use tenferro_tensor_core::{ShapeVec, SliceSpec, StrideVec, TensorRef};
46
47pub mod backend;
48pub mod cache;
49pub mod config;
50pub mod error;
51pub mod types;
52pub mod validate;
53
54pub use backend::{
55 default_backend_session, BackendCachedDot, BackendRuntimeCache, BackendSession,
56 BackendSessionHost, SessionCachedDot, TensorAnalytic, TensorBackend, TensorBackendOps,
57 TensorBuffer, TensorDeviceTransfer, TensorDot, TensorElementwise, TensorFusion, TensorIndexing,
58 TensorReduction, TensorStructural, TensorViewCanonicalization,
59};
60pub use cache::{CacheStats, RuntimeCacheControl};
61pub use config::*;
62pub use error::*;
63pub use types::*;
64
65#[cfg(test)]
66mod tests;