A tensor-based automatic differentiation engine built from scratch in Rust.
Delta is an educational tensor autograd engine that prioritizes clarity and correctness over performance. Built entirely from scratch with zero dependencies, it demonstrates the fundamental concepts behind modern deep learning frameworks.
- Nabla (∇) — the gradient operator
- Delta (Δ) — change, difference
Together they represent the core of differentiation: measuring how things change.
-
Tensor Operations
- N-dimensional tensor creation and indexing
- Element-wise arithmetic:
add,sub,mul,div,neg - Scalar operations:
scalar_add,scalar_mul - Matrix multiplication:
matmul - Transpose:
transpose,t()
-
Operator Overloading
- Full support for
+,-,*,/operators - Works with both owned values and references
- Scalar multiplication:
tensor * 3.0or3.0 * tensor
- Full support for
-
Developer Experience
- Pretty-printed tensor display with truncation for large tensors
- Comprehensive error messages
- Full test coverage
- Broadcasting for element-wise operations
- Reduction operations (sum, mean, max)
- Computation graph with index-based nodes
- Automatic differentiation (backward pass)
- Neural network primitives (layers, loss functions, optimizers)
- C FFI for cross-language support
use delta::tensor::Tensor;
fn main() {
// Create tensors
let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3]);
let b = Tensor::from_vec(vec![7.0, 8.0, 9.0, 10.0, 11.0, 12.0], &[3, 2]);
// Matrix multiplication
let c = a.matmul(&b);
println!("{}", c);
// Operator overloading
let x = Tensor::from_vec(vec![1.0, 2.0, 3.0], &[3]);
let y = Tensor::from_vec(vec![4.0, 5.0, 6.0], &[3]);
let z = &x + &y; // Element-wise addition
let scaled = &x * 2.0; // Scalar multiplication
// Transpose
let t = a.transpose();
println!("Transposed: {}", t);
}# Build the library
cargo build
# Run tests
cargo test
# Run the example
cargo run --example basic
# Build documentation
cargo doc --opendelta/
├── src/
│ ├── lib.rs # Library root
│ └── tensor/
│ ├── mod.rs # Module exports
│ ├── shape.rs # Shape and stride handling
│ ├── storage.rs # Underlying data storage
│ └── tensor.rs # Tensor struct and operations
├── examples/
│ └── basic.rs # Usage examples
└── Cargo.toml
- Educational First — Code reflects the underlying mathematics
- Zero Dependencies — Built from scratch for learning
- Correctness Over Speed — Naive algorithms, clear implementations
- Rust-Idiomatic — Embraces ownership, uses index-based graphs
- micrograd — Andrej Karpathy's minimal autograd
- tinygrad — Simple deep learning framework
- candle — Hugging Face's Rust ML framework
MIT License — see LICENSE for details.
"What I cannot create, I do not understand." — Richard Feynman