| Crates.io | tensor-operations |
| lib.rs | tensor-operations |
| version | 0.1.0 |
| created_at | 2026-01-18 15:33:10.07808+00 |
| updated_at | 2026-01-18 15:33:10.07808+00 |
| description | Week 13: Matrix and Tensor Operations in Rust - Manual vs Optimized |
| homepage | |
| repository | |
| max_upload_size | |
| id | 2052502 |
| size | 368,013 |
If you find this project helpful, please consider supporting it:
A comprehensive learning project implementing matrix and linear algebra operations in Rust, with two complementary approaches:
Perfect for learning both Rust fundamentals and linear algebra concepts through practical implementation.
Prerequisites: Rust 1.56+ installed (install.rust-lang.org)
# Run examples
cargo run --example basic_operations
cargo run --example performance_comparison --release
cargo run --example advanced_operations
# Run tests
cargo test
# Run benchmarks
cargo bench
# View documentation
cargo doc --no-deps --open
RUST_GUIDE.md - Complete learning guide covering:
WEEK13_STUDY_GUIDE.md - Original Python study guide with:
โโโ src/
โ โโโ lib.rs # Library root (module exports)
โ โโโ manual.rs # Pure Rust matrix implementation (~450 lines)
โ โโโ optimized.rs # nalgebra-based implementation (~380 lines)
โ
โโโ examples/
โ โโโ basic_operations.rs # Side-by-side comparison demo
โ โโโ performance_comparison.rs # Timing measurements
โ โโโ advanced_operations.rs # QR, SVD, eigenvalues, solving
โ
โโโ benches/
โ โโโ matrix_benchmarks.rs # Criterion benchmarks
โ
โโโ Cargo.toml # Project configuration
โโโ README.md # This file
Rust Concepts:
Linear Algebra:
Performance Engineering:
cargo run --example basic_operations
Shows side-by-side comparison of both implementations performing the same operations.
cargo run --example performance_comparison --release
Measures execution time and calculates speedup of optimized vs manual implementation.
cargo run --example advanced_operations
Demonstrates QR decomposition, SVD, eigenvalues, and linear system solving using optimized nalgebra backend.
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_matrix_creation
# Run specific module tests
cargo test manual::
cargo test optimized::
Test Coverage:
# Run criterion benchmarks
cargo bench
# Benchmark specific operation
cargo bench benchmark_addition
Benchmarks test performance across multiple matrix sizes and generate HTML reports in target/criterion/.
Creating a Matrix:
use tensor_operations::manual::Matrix;
let m = Matrix::new(vec![
vec![1.0, 2.0],
vec![3.0, 4.0],
])?;
Matrix Operations:
let sum = a.add(&b)?;
let product = a.mul(&b)?;
let det = a.determinant()?;
let inverse = a.inverse()?;
Advanced Operations:
use tensor_operations::optimized::OptimizedMatrix;
let (q, r) = m.qr_decomposition()?;
let (u, singular_vals, vt) = m.svd()?;
let evals = m.eigenvalues()?;
let x = a.solve(&b)?;
Typical speedups (optimized vs manual) on modern hardware:
| Operation | Size | Manual | Optimized | Speedup |
|---|---|---|---|---|
| Addition | 10ร10 | ~5 ยตs | ~0.7 ยตs | 7x |
| Multiplication | 20ร20 | ~16 ms | ~150 ยตs | 100x |
| Determinant | 5ร5 | ~50 ยตs | ~5 ยตs | 10x |
| Transpose | 50ร50 | ~10 ยตs | ~2 ยตs | 5x |
See RUST_GUIDE.md for detailed performance analysis.
src/manual.rs)src/optimized.rs)See RUST_GUIDE.md for detailed learning plan.
| File | Lines | Purpose |
|---|---|---|
src/manual.rs |
450+ | Pure Rust implementation, 17 tests |
src/optimized.rs |
380+ | nalgebra wrapper, 11 tests |
src/lib.rs |
44 | Library root with exports |
examples/basic_operations.rs |
180+ | Basic usage demonstration |
examples/performance_comparison.rs |
160+ | Timing measurements |
examples/advanced_operations.rs |
210+ | QR, SVD, eigenvalues |
benches/matrix_benchmarks.rs |
120+ | Criterion benchmarks |
Upon completing this project, you will understand:
โ
How matrix operations work at a fundamental level
โ
Rust ownership, borrowing, and error handling
โ
Algorithm complexity and performance optimization
โ
When to use optimized libraries vs. manual implementation
โ
How to benchmark and measure performance
โ
Best practices for numerical computing in Rust
This project also includes the original Python implementation for comparison:
WEEK13_STUDY_GUIDE.md - Study materialsmanual_matrix.py - Manual implementationnumpy_matrix.py - NumPy implementationWeek13_ndarray_tensor_operations.ipynb - Jupyter notebookMIT License
# Manual implementation
from manual_matrix import Matrix
A = Matrix([[1, 2], [3, 4]])
B = Matrix([[5, 6], [7, 8]])
C = A @ B # Matrix multiplication
# NumPy implementation
from numpy_matrix import NumpyMatrix
A = NumpyMatrix([[1, 2], [3, 4]])
B = NumpyMatrix([[5, 6], [7, 8]])
C = A @ B # Same operation, much faster
tensor-operations/
โโโ README.md # This file
โโโ WEEK13_STUDY_GUIDE.md # Comprehensive study guide
โโโ manual_matrix.py # Manual implementations
โโโ numpy_matrix.py # NumPy implementations
โโโ Week13_ndarray_tensor_operations.ipynb # Interactive notebook
โโโ performance_comparison.png # Benchmark visualization
By completing this week's materials, you will: