flatmat.js

by G. Lathoud, February 2017

flatmat.js is a library of fast linear algebra functions. API description & speed tests below.

2-D matrices are stored flat: as 1-D arrays of numbers. Most code is automatically generated for performance (see flatorize).

Contents:

[to GitHub]

API

Speed test: matrix multiplication


        

        

Comparison with a hand-written loop implementation.


        

        

Speed test: matrix inversion


        

        

Comparison with an implementation for matrices stored as 2-D arrays.

As of 2017-02-23 2-D arrays had roughly 2 times the speed of the 1-D flatmat implementation (just above). Not good? On the other hand, for matrix multiplication (and xvmxv) 1-D goes ca 5 to 10 times faster. So there is a tradeoff, depending on the type of application.


        

        

Comparison with an implementation directly in 1-D.


        

        

Speed test: vector-matrix product (x-V)^T * M * (x-V)

Measure the speed of the product (x-V)^T * M * (x-V) where x and V are vectors, and M a square matrix. This is useful when computing the exponent term in a Gaussian probability density function.


        

        

Comparison with a hand-written implementation (loops).


        

        

Code source

The source files used for the tests. Also browsable on GitHub