Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

API Reference

This section provides detailed documentation for all public APIs in Tensor Frame.

Core Types

  • Tensor - The main tensor type with all operations
  • Backends - Backend trait and implementation details
  • Operations - Detailed operation specifications

Key Traits and Enums

TensorOps Trait

The TensorOps trait defines all tensor manipulation and computation operations:

#![allow(unused)]
fn main() {
pub trait TensorOps {
    fn reshape(&self, new_shape: Vec<usize>) -> Result<Tensor>;
    fn transpose(&self) -> Result<Tensor>;
    fn squeeze(&self, dim: Option<usize>) -> Result<Tensor>;
    fn unsqueeze(&self, dim: usize) -> Result<Tensor>;
    // ... more methods
}
}

DType Enum

Supported data types:

#![allow(unused)]
fn main() {
pub enum DType {
    F32,    // 32-bit floating point (default)
    F64,    // 64-bit floating point  
    I32,    // 32-bit signed integer
    U32,    // 32-bit unsigned integer
}
}

BackendType Enum

Available computational backends:

#![allow(unused)]
fn main() {
pub enum BackendType {
    Cpu,    // CPU backend with Rayon
    Wgpu,   // Cross-platform GPU backend
    Cuda,   // NVIDIA CUDA backend
}
}

Error Handling

All operations return Result<T> with TensorError for comprehensive error handling:

#![allow(unused)]
fn main() {
pub enum TensorError {
    ShapeMismatch { expected: Vec<usize>, got: Vec<usize> },
    BackendError(String),
    InvalidOperation(String),
    DimensionError(String),
}
}

Memory Management

Tensor Frame uses smart pointers and reference counting for efficient memory management:

  • Tensors are cheaply clonable (reference counted)
  • Backend storage is automatically managed
  • Cross-backend tensor conversion is supported
  • Zero-copy operations where possible