Flat math code for speed

3D example (not mine!): ocean wave simulation.

source: invertMatrix and premultiplyMatrix are "flat" ⇒ high speed!

Generate such code automatically

http://glat.info/flatorize

Instead of a value computation:

cplx =             function (re,im) { return [ re, im ]; };

...write an expression computation:

cplx = FZ('re,im', function (re,im) { return [ re, im ]; });

...which generates:

function cplx(re,im) { return [ re, im ]; }

Flat math code for speed

3D example (not mine!): ocean wave simulation.

source: invertMatrix and premultiplyMatrix are "flat" ⇒ high speed!

Generate such code automatically

http://glat.info/flatorize

Instead of a value computation:

cadd =             function (a,b) {
    return cplx( creal(a) + creal(b),
                 cimag(a) + cimag(b) );
}

...write an expression computation:

cadd = FZ('a,b',   function (a,b) { 
    return cplx( FZ.expr( creal(a), '+', creal(b) ),
                  FZ.expr( cimag(a), '+', cimag(b) ) ); 
});

...which generates:

function cadd(a,b) { 
    return [ (a[0]) + (b[0]), (a[1]) + (b[1]) ]; 
}

Flat math code for speed

3D example (not mine!): ocean wave simulation.

source: invertMatrix and premultiplyMatrix are "flat" ⇒ high speed!

Generate such code automatically

http://glat.info/flatorize

Instead of a value computation:

f = function(a,b,c) { 
    return csub( csub(a,cadd(b,c)), cadd(b,c) ); 
}

...write an expression computation:

f = FZ('a,b,c', function(a,b,c) { 
    return csub( csub(a,cadd(b,c)), cadd(b,c) ); 
});

...which generates:

function f(a, b, c) {
    var _0 = (b[0]) + (c[0]),
        _1 = (b[1]) + (c[1]);
    return [ - _0 + (- _0 + (a[0])), - _1 + (- _1 + (a[1])) ];
}

☆ Examples: complex, matmul, Discrete Fourier Transform.

Results. About an order of magnitude faster.

☆ Further speedup: try with asm.js.