RMath

Ecosystem Interoperability

RMath is designed to be a "drop-in accelerator." It implements standard memory protocols like __array__ and __dlpack__ to ensure seamless, zero-copy compatibility with the Python scientific ecosystem.

Proven: Seamless NumPy Bridge

RMath implements the __array__ protocol, allowing standard NumPy conversions. Because RMath uses Arc for safe, lock-free multithreading, data handed off to NumPy is securely cloned and isolated. This guarantees that your RMath data remains immutable and thread-safe.

numpy_bridge.py
import rmath.array as ra
import numpy as np

# Create RMath Array
a = ra.ones(2, 2)

# Seamless conversion to standard NumPy array via __array__
np_arr = np.asarray(a)

# Modify NumPy array safely (RMath original remains immutable)
np_arr[0, 0] = 99.0

print(f"RMath a[0,0] : {a[0, 0]}")
print(f"NumPy [0,0]  : {np_arr[0, 0]}")
RMath a[0,0] : 1.0 NumPy [0,0] : 99.0

Proven: PyTorch Zero-Copy

Using the DLPack protocol, RMath can pass data efficiently to PyTorch with minimal overhead, making it easy to use RMath for data preprocessing before feeding tensors into neural networks.

pytorch_interop.py
import rmath.array as ra
import torch

# Generate large dataset in RMath (e.g., using Welford's or projections)
ra_arr = ra.randn(10, 5)

# RMath -> PyTorch via DLPack
th_tensor = torch.from_dlpack(ra_arr)

print(f"RMath Shape   : {ra_arr.shape}")
print(f"PyTorch Shape : {th_tensor.shape}")
RMath Shape : [10, 5] PyTorch Shape : torch.Size([10, 5])
Safety Philosophy: RMath prioritizes thread safety and lock-free parallelism over mutable shared state. Immutability in Rust is what allows RMath to run computations across 100% of your CPU cores without GIL bottlenecks.