smartcore icon indicating copy to clipboard operation
smartcore copied to clipboard

SIMD and Optimath

Open Mec-iS opened this issue 11 months ago • 3 comments

Consider improvements based on Optimath https://docs.rs/optimath/latest/optimath/

Mec-iS avatar Jan 27 '25 23:01 Mec-iS

https://towardsdatascience.com/nine-rules-for-simd-acceleration-of-your-rust-code-part-1-c16fe639ce21/

Mec-iS avatar Feb 28 '25 10:02 Mec-iS

optimath and simd may incrementally boost your current linalg module performance

but its still O(n^3) code

if youre willing to venture beyond linear algebra and scalar calculus https://crates.io/crates/geonum achieves O(1) operations regardless of dimension

it consumes minimal memory since multivectors are represented with just 2 components (length and angle) instead of the 2^n components required by traditional geometric algebra

geonums machine_learning_test.rs suite demonstrates:

  • perceptron classification in 50,000D space with O(1) vs O(n) complexity
  • linear regression without expensive gram matrix computation
  • neural networks with O(1) forward/backward passes vs O(n²) matrix multiplications
  • clustering with O(1) distance calculations vs O(n) euclidean distances
  • dimensionality reduction without O(n³) eigendecomposition

at just 16 dimensions, geonum is 4300× faster than tensor implementation and maintains consistent ~78ns performance even in million-dimensional spaces

so while optimath/simd provides instruction-level parallelism for existing operations, geonum swaps them out with a more scalable design

encoding orthogonality relationships directly with angles instead of computing them repeatedly eliminates the computational bottleneck entirely (orders of magnitude improvement beyond whats possible with traditional optimizations)

try it out: https://github.com/mxfactorial/geonum/tree/develop?tab=readme-ov-file#learn-with-ai

mxfactorial avatar Apr 30 '25 22:04 mxfactorial

Thanks for this suggestion.

Geometric algebra is indeed interesting and it may be worthwhile considering a feature in smartcore for this. For sure it would be an option for users looking for something different than the current linear algebra options.

Something like:

  1. Add Feature Flag
smartcore = { ..., features = ["geoalgebra"] }
  1. Implement Adapter Layer
impl From<Geonum> for Array1<f64> {
    fn from(g: Geonum) -> Self {
        // Convert angle/length to coordinates
    }
}
  1. Algorithm Mods
  • LinearRegression → GeometricRegression
  • Kernel methods using wedge products
  • Angle-based clustering

I am not an expert on this but if you want to consider opening a PR I would be glad to learn, help and follow along.

Mec-iS avatar May 01 '25 05:05 Mec-iS