Core Module
rmath.array
N-dimensional array engine. Row-major Vec<Vec<f64>> backed,
with all element-wise operations parallelized via Rayon. Supports automatic
storage tiering: inline (stack), heap, and memory-mapped files.
example.py
import rmath as rm
a = rm.Array([[1, 2], [3, 4]])
b = rm.Array.eye(2)
c = a @ b # matrix multiply
d = a.sin().exp() # element-wise chain
avg = a.mean() # global reduction
Constructors
| Signature | Description |
|---|---|
Array(data) | Create from nested lists, a Vector, or a scalar. rm.Array([[1,2],[3,4]]) |
Array.zeros(*shape) | Array of zeros. rm.Array.zeros(3, 4) |
Array.ones(*shape) | Array of ones. |
Array.eye(n) | Identity matrix of size n × n. |
Array.full(*args, value) | Filled array. rm.Array.full(3, 4, 2.5) |
Array.from_flat(data, shape) | Create from a flat list and a shape tuple. |
Shape & Data Access
| Method | Returns | Description |
|---|---|---|
.shape() | tuple[int, ...] | Dimensions of the array |
.size() | int | Total number of elements |
.nrows() | int | Number of rows |
.ncols() | int | Number of columns |
.to_list() | list[list[float]] | Convert to nested Python lists |
.flatten() | list[float] | Flat 1D list of all elements |
.row(i) | list[float] | Extract row i (raises IndexError) |
.col(j) | list[float] | Extract column j (raises IndexError) |
.get(i, j) | float | Element at (i, j) |
.diag_extract() | list[float] | Main diagonal (square only) |
.triu() | Array | Upper triangular |
.tril() | Array | Lower triangular |
.reshape(rows, cols) | Array | Reshape (raises ValueError if sizes don't match) |
Element-wise Math
All operations return a new Array. Parallelized via Rayon.
Rounding
| Method | Description |
|---|---|
.abs() | Absolute value |
.sqrt() | Square root |
.cbrt() | Cube root |
.ceil() | Round up |
.floor() | Round down |
.round() | Round to nearest |
.trunc() | Truncate toward zero |
Trigonometric
| Method |
|---|
.sin() · .cos() · .tan() · .asin() · .acos() · .atan() |
.sinh() · .cosh() · .tanh() |
Exponential & Logarithmic
| Method |
|---|
.exp() · .exp2() · .expm1() |
.log() · .log2() · .log10() · .log1p() |
Operators
Supports scalar broadcast and Array-Array operations.
| Operator | Left | Right | Explicit |
|---|---|---|---|
+ | Array | float | Array | .add_scalar(s) / .add_array(b) |
- | Array | float | Array | .sub_scalar(s) / .sub_array(b) |
* | Array | float | Array | .mul_scalar(s) / .mul_array(b) |
/ | Array | float | Array | .div_scalar(s) / .div_array(b) |
@ | Array | Array | .matmul(b) |
-a | Unary negation | ||
Matrix Operations
| Method | Returns | Description |
|---|---|---|
.transpose() | Array | Matrix transpose |
.matmul(b) | Array | Matrix multiplication |
.trace() | float | Sum of diagonal (square only) |
.det() | float | Determinant (square only) |
.inv() | Array | Matrix inverse (non-singular) |
.solve(b) | list[float] | Solve Ax = b |
.pow_scalar(exp) | Array | Element-wise power |
.clamp(lo, hi) | Array | Clamp all elements to [lo, hi] |
Reductions
Global
| Method | Returns |
|---|---|
.sum() · .prod() · .mean() | float |
.variance() · .std_dev() | float |
.min() · .max() | float |
.norm_fro() · .norm_l1() · .norm_inf() | float |
Per-axis (returns list[float])
| Row-wise | Column-wise |
|---|---|
.row_sums() | .col_sums() |
.row_means() | .col_means() |
.row_min() | .col_min() |
.row_max() | .col_max() |
.row_variance() | .col_variance() |
.row_std_dev() | .col_std_dev() |
Cumulative (row-wise)
.cumsum() · .cumprod() | Array |
Matrix statistics
.covariance_matrix() | Requires ≥2 rows |
.correlation_matrix() | Pearson correlation |
ML & Normalization
Activations
.sigmoid() | Logistic sigmoid |
.relu() | Rectified linear unit |
.leaky_relu(alpha) | Leaky ReLU with given slope |
.softmax() | Row-wise softmax (numerically stable) |
Normalization
.normalize() | Global min-max to [0, 1] |
.col_normalize() | Per-column min-max (MinMaxScaler) |
.z_normalize() | Global z-score |
.col_z_normalize() | Per-column z-score (StandardScaler) |
Predicates
.isnan() | list[list[bool]] | Element-wise NaN check |
.isfinite() | list[list[bool]] | Element-wise finite check |
.isinf() | list[list[bool]] | Element-wise infinity check |
.any_nan() | bool | True if any element is NaN |
.all_finite() | bool | True if all elements are finite |
Functional API
Module-level functions in rmath.array:
functional.py
import rmath.array as ra
z = ra.zeros(3, 4)
I = ra.eye(5)
d = ra.diag([1.0, 2.0, 3.0])
t = ra.transpose(z)
det = ra.det(I)
zeros(r, c) · ones(r, c) · eye(n) · full(r, c, v) · diag(vals) |
transpose(a) · matmul(a, b) · trace(a) · det(a) · inv(a) · solve(a, b) |
add_scalar · sub_scalar · mul_scalar · div_scalar |
add_array · sub_array · mul_array · div_array |
sum · mean · min · max · variance · std_dev |
norm_fro · norm_l1 · norm_inf |