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.

example.py
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

SignatureDescription
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.

OperatorExplicitDescription
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
-vNegate 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

MethodReturnsDescription
.sum()floatParallel Kahan-sum
.prod()floatProduct of all elements
.mean()floatArithmetic mean
.variance()floatSample variance (n ≥ 2)
.std_dev()floatSample standard deviation
.min()floatMinimum value
.max()floatMaximum value
.any()boolTrue if any element is nonzero
.all()boolTrue if all elements are nonzero

Filtering & Predicates

MethodReturnsDescription
.filter_gt(threshold)VectorKeep elements > threshold
.filter_lt(threshold)VectorKeep elements < threshold
.filter_by_mask(mask)VectorKeep elements where mask is true
.gt_mask(t)VectorBoolean mask: element > t
.lt_mask(t)VectorBoolean mask: element < t
.eq_mask(v)VectorBoolean mask: element == v
.where_(mask, other)VectorConditional 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

MethodReturnsDescription
.sort()VectorParallel unstable sort (ascending)
.sort_desc()VectorSort descending
.argsort()list[int]Indices that would sort the vector
.reverse()VectorReverse element order
.unique()VectorSorted unique elements

Cumulative

.cumsum()VectorRunning sum
.cumprod()VectorRunning product
.diff()VectorFirst differences (length n-1)

Shaping & Slicing

.head(n)VectorFirst n elements
.tail(n)VectorLast n elements
.chunks(size)list[Vector]Split into chunks
.append(val)VectorAdd one element
.extend(other)VectorConcatenate two vectors
.to_list()list[float]Convert to Python list
.len()intNumber of elements
.is_empty()boolTrue 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()VectorMagnitude of each complex element
.to_phases()VectorPhase 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)