rmath.array API Reference
The rmath.array module provides the foundation of RMath: the Array
class. This is a parallel, N-dimensional numeric array that supports matrix operations,
reductions, and seamless interop with NumPy, PyTorch, and JAX without the GIL.
Creation & Basic Ops
import rmath.array as ra
z = ra.zeros(3, 3)
o = ra.ones(2, 4)
a = ra.Array([[1.0, 2.0], [3.0, 4.0]])
print(f"ones shape : {o.shape}")
print(f"array sum : {a.sum()}")
print(f"array mean : {a.mean()}")
print(f"transpose :
{a.transpose()}")
ones shape : [2, 4]
array sum : 10.0
array mean : 2.5
transpose :
Array([
[ 1.0000, 3.0000],
[ 2.0000, 4.0000]])
API Reference (Selected Methods)
The Array class contains over 100 methods for high-performance numerical computing. Below is a subset.
| Method | Description |
ra.zeros(*shape) | Create an array of zeros. |
ra.ones(*shape) | Create an array of ones. |
ra.randn(*shape) | Normal random samples. |
ra.arange(start, end, step) | Step-wise sequence of values. |
a.shape | Returns the dimensions of the array. |
a.reshape(rows, cols) | Reshape the array into new dimensions. |
a.transpose() | Transpose the array dimensions. |
a.matmul(other) | Matrix multiplication (equivalent to a @ other). |
a.sum() | Sum of all elements via Kahan compensation. |
a.mean() / a.variance() | Statistical reductions. |
a.lazy() | Returns a LazyPipeline to fuse loop operations without allocations. |
a.to_numpy() | Zero-copy conversion to a NumPy ndarray. |
a.from_numpy(arr) | Create an RMath Array from a NumPy ndarray. |
Performance Note: All math operations like .sin(), .exp(), and reductions like .sum() automatically dispatch to a background Rayon thread pool if the array has more than 8,192 elements.