RMath

rmath.Tensor

The rmath.Tensor class provides a dynamic computational graph for reverse-mode automatic differentiation. It is highly optimized for CPU-bound deep learning research and gradient-based optimization.

PyTorch Comparison Benchmarks

RMath's Tensor is built from the ground up for CPU environments where heavy ML frameworks like PyTorch suffer from high overhead. By executing graph traversals entirely in native Rust, RMath achieves a ~4.14× average speedup over PyTorch for medium-sized tensor workloads (e.g., training loops with 200×200 arrays).

Key Speedups vs PyTorch

  • Model Update (Adam step): 3.3× faster
  • Model Update (SGD step): 2.0× faster
  • Backpropagation (.backward): 5.99× faster
  • Forward Pass (Fused ops): 7.0× faster

Proven: Backpropagation

The Autograd engine uses a lean, zero-dependency reverse-mode tape.

autograd_verify.py
import rmath as rm

# Graph: z = (x * 2 + 5).sum()
x = rm.Tensor([1.0, 2.0], requires_grad=True)
y = x * 2.0 + 5.0
z = y.sum()

# Execute reverse-mode differentiation
z.backward()

print(f"Gradient dx: {x.grad}")
Gradient dx: Array([2.0000, 2.0000])