Core Module
rmath.vector
1-D parallel math engine. Supports operator overloading, method chaining,
and 80+ operations — all running on Rayon with zero GIL holding.
import rmath.vector as rv
v = rv.Vector.linspace(0, 10, 1_000_000)
result = v.sin().exp().sum() # chained, parallel
# Operators
v2 = v + 5.0
dot = v @ v2 # dot product
Constructors
| Signature | Description |
Vector(data) | Create from any sequence of floats |
Vector.range(start, stop, step=1.0) | Evenly spaced values (like Python range for floats) |
Vector.linspace(start, stop, num) | num evenly spaced points between start and stop |
Vector.sum_range(start, stop, step) | Sum of range without allocating a vector |
Operators
All operators work with both float and Vector operands.
| Operator | Explicit | Description |
v + x | .add_scalar(s) / .add_vec(v2) | Addition |
v - x | .sub_scalar(s) / .sub_vec(v2) | Subtraction |
v * x | .mul_scalar(s) / .mul_vec(v2) | Multiplication |
v / x | .div_scalar(s) / .div_vec(v2) | Division |
v @ v2 | .dot(v2) | Dot product → float |
-v | — | Negate all elements |
| — | .pow_scalar(exp) | Element-wise power |
| — | .clamp(lo, hi) | Clamp elements to range |
Element-wise Math
All return a new Vector.
Rounding & Roots
.abs() · .sqrt() · .cbrt() · .ceil() · .floor() · .round() · .trunc() |
Trigonometric
.sin() · .cos() · .tan() |
.asin() · .acos() · .atan() |
.sinh() · .cosh() · .tanh() |
Exponential & Logarithmic
.exp() · .exp2() · .expm1() |
.log() · .log2() · .log10() · .log1p() |
Other
.sigmoid() | Logistic sigmoid |
.clip(lo, hi) | Clamp elements |
.hypot_scalar(y) | sqrt(x² + y²) per element |
.atan2_scalar(x) | Two-arg arctangent per element |
.lerp_scalar(other, t) | Linear interpolation per element |
Reductions
| Method | Returns | Description |
.sum() | float | Parallel Kahan-sum |
.prod() | float | Product of all elements |
.mean() | float | Arithmetic mean |
.variance() | float | Sample variance (n ≥ 2) |
.std_dev() | float | Sample standard deviation |
.min() | float | Minimum value |
.max() | float | Maximum value |
.any() | bool | True if any element is nonzero |
.all() | bool | True if all elements are nonzero |
Filtering & Predicates
| Method | Returns | Description |
.filter_gt(threshold) | Vector | Keep elements > threshold |
.filter_lt(threshold) | Vector | Keep elements < threshold |
.filter_by_mask(mask) | Vector | Keep elements where mask is true |
.gt_mask(t) | Vector | Boolean mask: element > t |
.lt_mask(t) | Vector | Boolean mask: element < t |
.eq_mask(v) | Vector | Boolean mask: element == v |
.where_(mask, other) | Vector | Conditional select |
.isnan() | list[bool] | NaN check per element |
.isfinite() | list[bool] | Finite check per element |
.isinf() | list[bool] | Infinity check per element |
.is_integer() | list[bool] | Integer check per element |
.is_prime() | list[bool] | Primality check per element |
Sorting & Reordering
| Method | Returns | Description |
.sort() | Vector | Parallel unstable sort (ascending) |
.sort_desc() | Vector | Sort descending |
.argsort() | list[int] | Indices that would sort the vector |
.reverse() | Vector | Reverse element order |
.unique() | Vector | Sorted unique elements |
Cumulative
.cumsum() | Vector | Running sum |
.cumprod() | Vector | Running product |
.diff() | Vector | First differences (length n-1) |
Shaping & Slicing
.head(n) | Vector | First n elements |
.tail(n) | Vector | Last n elements |
.chunks(size) | list[Vector] | Split into chunks |
.append(val) | Vector | Add one element |
.extend(other) | Vector | Concatenate two vectors |
.to_list() | list[float] | Convert to Python list |
.len() | int | Number of elements |
.is_empty() | bool | True if length is 0 |
ComplexVector
A container for complex-valued (f64 + i·f64) vectors.
ComplexVector(real, imag) | Create from two sequences of floats |
.to_mags() | Vector | Magnitude of each complex element |
.to_phases() | Vector | Phase angle of each element |
Functional API
Module-level functions in rmath.vector:
Constructors
rand(n) · randn(n) · rand_seeded(n, seed) · randn_seeded(n, seed) |
arange(start, stop, step) · range(start, stop, step) · linspace(start, stop, num) |
zeros(n) · ones(n) · full(n, val) |
Math (all take Vector, return Vector)
sin · cos · tan · asin · acos · atan |
sinh · cosh · tanh |
exp · exp2 · expm1 · log · log2 · log10 · log1p |
sqrt · cbrt · abs · ceil · floor · round · trunc · fract · signum · recip |
Reductions (all return float)
vsum · prod · mean · median · variance · pop_variance · std_dev · pop_std_dev |
vmin · vmax · argmin · argmax · percentile(v, q) |
norm · norm_l1 · norm_inf · norm_lp(v, p) · dot(v1, v2) |