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 capability;
50pub mod config;
51pub mod dispatch;
52pub mod error;
53pub mod types;
54pub mod validate;
55
56pub use backend::{
57 default_backend_session, BackendCachedDot, BackendRuntimeCache, BackendSession,
58 BackendSessionHost, ContractionScalar, DotGeneralAccumulation, SessionCachedDot,
59 TensorAnalytic, TensorBackend, TensorBackendOps, TensorBuffer, TensorDeviceTransfer, TensorDot,
60 TensorElementwise, TensorFusion, TensorIndexing, TensorReduction, TensorStructural,
61 TensorViewCanonicalization,
62};
63pub use cache::{CacheStats, RuntimeCacheControl};
64pub use capability::{
65 capability_output_dtype, BackendId, CapabilityAxis, CapabilityQuery, OperationCapability,
66 SupportLevel, TensorBackendCapability,
67};
68pub use config::*;
69pub use error::*;
70pub use types::*;
71
72#[cfg(test)]
73mod tests;