Expand description
§Tensor Frame
A PyTorch-like tensor library for Rust with support for multiple backends including CPU, WGPU, and CUDA.
§Overview
Tensor Frame provides a flexible and efficient tensor computation framework that allows you to:
- Create and manipulate multi-dimensional arrays (tensors)
- Perform element-wise operations with automatic broadcasting
- Use different compute backends (CPU, GPU via WGPU, or CUDA)
- Seamlessly switch between backends based on your hardware capabilities
§Quick Start
use tensor_frame::{Tensor, TensorOps};
// Create tensors
let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], vec![2, 2]).unwrap();
let b = Tensor::ones(vec![2, 2]).unwrap();
// Perform operations
let c = (a + b).unwrap();
let sum = c.sum(None).unwrap();
println!("Result: {:?}", c.to_vec().unwrap());
§Features
- Multiple Backends: Choose between CPU (with Rayon parallelization), WGPU (WebGPU), or CUDA
- Broadcasting: Automatic shape broadcasting for element-wise operations
- Rich Operations: Addition, subtraction, multiplication, division, reductions (sum, mean)
- Shape Manipulation: Reshape and transpose operations
- Type Safety: Strong typing with comprehensive error handling
§Backend Selection
Enable different backends through Cargo features:
# CPU backend (default)
tensor_frame = "0.0.3-alpha"
# WGPU backend
tensor_frame = { version = "0.0.3-alpha", features = ["wgpu"] }
# CUDA backend
tensor_frame = { version = "0.0.3-alpha", features = ["cuda"] }
§Examples
§Creating Tensors
use tensor_frame::Tensor;
// From a vector with shape
let tensor = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], vec![2, 2]).unwrap();
// Zeros tensor
let zeros = Tensor::zeros(vec![3, 3]).unwrap();
// Ones tensor
let ones = Tensor::ones(vec![2, 4]).unwrap();
§Operations with Broadcasting
use tensor_frame::Tensor;
let a = Tensor::ones(vec![2, 1]).unwrap(); // Shape: [2, 1]
let b = Tensor::ones(vec![1, 3]).unwrap(); // Shape: [1, 3]
let c = (a + b).unwrap(); // Shape: [2, 3] via broadcasting
Structs§
- Shape
- Core tensor types and operations Represents the shape (dimensions) of a tensor.
- Tensor
- Core tensor types and operations A multi-dimensional array with support for various backends and operations.
Enums§
- Tensor
Error - Error types and Result alias for the library The main error type for tensor operations.
Traits§
- Backend
- The backend trait for tensor operations The main backend trait that all compute backends must implement.
- Tensor
Ops - Core tensor types and operations Trait defining common operations on tensors.
Type Aliases§
- Result
- Error types and Result alias for the library
A type alias for
Result<T, TensorError>
.