tensor-operations 0.1.0

Week 13: Matrix and Tensor Operations in Rust - Manual vs Optimized
Documentation
# Quick Reference: Running the Rust Project

## Installation & Setup

```bash
# Clone or navigate to project
cd /Users/maksimvialykh/github/tensor-operations

# Verify Rust is installed
rustc --version
cargo --version
```

## Common Commands

### Building
```bash
# Debug build
cargo build

# Release build (optimized, recommended for benchmarks)
cargo build --release
```

### Testing
```bash
# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Run specific test
cargo test test_matrix_creation

# Run only manual implementation tests
cargo test manual::
```

### Examples

```bash
# Basic operations (side-by-side comparison)
cargo run --example basic_operations

# Performance comparison with timing
cargo run --example performance_comparison --release

# Advanced operations (QR, SVD, eigenvalues, solving)
cargo run --example advanced_operations
```

### Benchmarking

```bash
# Run criterion benchmarks
cargo bench

# Benchmark specific operation
cargo bench benchmark_addition

# View HTML reports
open target/criterion/index.html
```

### Documentation

```bash
# Generate and open documentation
cargo doc --no-deps --open

# View in browser
# Opens local API documentation for the crate
```

## Project Files at a Glance

```
src/
├── lib.rs              # Library root, exports Manual and OptimizedMatrix
├── manual.rs           # Pure Rust implementation (450+ lines)
└── optimized.rs        # nalgebra-based implementation (380+ lines)

examples/
├── basic_operations.rs         # Side-by-side 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                        # Main project documentation
RUST_GUIDE.md                   # Complete learning guide
PROJECT_STATUS.md               # This project's status
```

## Key Code Examples

### Creating Matrices

```rust
use tensor_operations::manual::Matrix;

// From vector
let m = Matrix::new(vec![
    vec![1.0, 2.0],
    vec![3.0, 4.0],
])?;

// Identity matrix
let i = Matrix::identity(3)?;

// Zero matrix
let z = Matrix::zeros(2, 3)?;
```

### Basic Operations

```rust
// Addition
let sum = a.add(&b)?;

// Multiplication
let product = a.mul(&b)?;

// Transpose
let t = m.transpose()?;

// Determinant
let det = m.determinant()?;
```

### Advanced Operations (Optimized Only)

```rust
use tensor_operations::optimized::OptimizedMatrix;

// QR Decomposition
let (q, r) = m.qr_decomposition()?;

// SVD
let (u, singular_values, vt) = m.svd()?;

// Eigenvalues
let evals = m.eigenvalues()?;

// Solve Ax = b
let x = a.solve(&b)?;
```

## Troubleshooting

### Compilation Issues

```bash
# Clean build from scratch
cargo clean
cargo build

# Check for warnings
cargo clippy

# Format code
cargo fmt
```

### Test Failures

```bash
# Run with detailed output
cargo test -- --nocapture --test-threads=1

# Run single failing test
cargo test test_name -- --nocapture
```

### Performance Questions

```bash
# Run benchmarks in release mode
cargo bench --release

# Compare with previous benchmarks
# (Criterion saves results automatically)
```

## Learning Resources

1. **Start Here**: [README.md]README.md
2. **Study Guide**: [RUST_GUIDE.md]RUST_GUIDE.md
3. **Source Code**: [src/manual.rs]src/manual.rs
4. **Examples**: [examples/basic_operations.rs]examples/basic_operations.rs
5. **Tests**: Within each Rust file at bottom
6. **Benchmarks**: [benches/matrix_benchmarks.rs]benches/matrix_benchmarks.rs

## Performance Expectations

On modern hardware, typical speedups (optimized vs manual):

| Operation | Size | Speedup |
|-----------|------|---------|
| Addition | 20×20 | ~7x |
| Multiplication | 20×20 | ~14x |
| Determinant | 5×5 | ~92x |
| Transpose | 50×50 | ~3x |

## File Structure Summary

| File | Purpose | Status |
|------|---------|--------|
| src/manual.rs | Educational implementation | ✅ Complete |
| src/optimized.rs | Production implementation | ✅ Complete |
| examples/*.rs | Demonstration code | ✅ Working |
| benches/*.rs | Performance measurement | ✅ Running |
| Cargo.toml | Project configuration | ✅ Configured |
| README.md | Main documentation | ✅ Updated |
| RUST_GUIDE.md | Learning guide | ✅ Complete |

## Status Check

```bash
# Verify everything is working
cargo build --release && cargo test && cargo bench

# Should see:
# ✅ Finished `release` profile...
# ✅ test result: ok. 13 passed
# ✅ All benchmarks completed
```

---

**Project Status**: ✅ Ready for publication on crates.io
**Rust Version**: 1.56+
**Edition**: 2021