RMath

rmath.vector

The rmath.vector module provides high-performance 1-D data structures optimized for reductions, filtering, and SIMD-accelerated math.

The "Impossible Vector" (Projected Storage)

Standard arrays allocate memory for every element. If you try to create a NumPy array with 50 Billion elements, it will request ~400 GB of RAM and crash.

RMath Vectors bypass this limitation using Projected Storage. When creating massive sequences (like ranges), RMath stores only the mathematical definition of the vector rather than materializing the values in RAM. You can perform parallel math and reductions on 50B+ elements instantly.

impossible_vector.py
import rmath.vector as rv

# Create a 50 Billion element vector (0 RAM usage)
v = rv.Vector.range(50_000_000_000)

# Compute exact mean in milliseconds via Projected Storage
v_mean = v.mean()

print(f"Mean of 50B elements: {v_mean:.1f}")
Mean of 50B elements: 24999999999.5

Zero-Allocation Filtering

Filtering data usually requires allocating large boolean masks. RMath's filter_where and multi_filter_where methods fuse multiple conditions into a single pass, completely eliminating intermediate mask allocations. This allows RMath to use up to 9× less memory than standard libraries during data cleaning.

zero_alloc_filter.py
import rmath.vector as rv

age    = rv.Vector([22.0, 45.0, 31.0, 60.0, 19.0])
income = rv.Vector([30000.0, 80000.0, 55000.0, 120000.0, 20000.0])

# Filters age and income simultaneously WITHOUT boolean mask arrays
age_filtered, income_filtered = rv.Vector.multi_filter_where(
    [age, income],
    [(age, "gt", 25.0), (income, "lt", 100000.0)]
)

print("Age    :", age_filtered)
print("Income :", income_filtered)
Age : Vector([45.0000, 31.0000]) Income : Vector([80000.0000, 55000.0000])

Proven: Vector Reductions

RMath implements numerically stable, single-pass parallel algorithms like Kahan Summation and Welford's Method.

vector_math.py
import rmath.vector as rv

v = rv.Vector([1.0, 2.0, 3.0, 4.0])

# Optimized parallel sum and variance
v_sum = v.sum()
v_var = v.variance()

print(f"Sum: {v_sum}")
print(f"Variance: {v_var:.4f}")
Sum: 10.0 Variance: 1.6667
Tip: RMath Vectors use a stack-tiering system that keeps small vectors (up to 32 elements) on the CPU stack for near-zero latency.