All Projects → glathoud → flatorize

glathoud / flatorize

Licence: Apache-2.0 license
Generate fast implementations of mathematical expressions. Inclues a linear algebra library.

Programming Languages

javascript
184084 projects - #8 most used programming language
c
50402 projects - #5 most used programming language
HTML
75241 projects
d
599 projects
python
139335 projects - #7 most used programming language
shell
77523 projects
CSS
56736 projects

Projects that are alternatives of or similar to flatorize

Tiramisu
A polyhedral compiler for expressing fast and portable data parallel algorithms
Stars: ✭ 685 (+3705.56%)
Mutual labels:  linear-algebra, code-generation
linnea
Linnea is an experimental tool for the automatic generation of optimized code for linear algebra problems.
Stars: ✭ 60 (+233.33%)
Mutual labels:  linear-algebra, code-generation
mathcore
Advanced .NET math library (.NET Standard).
Stars: ✭ 24 (+33.33%)
Mutual labels:  linear-algebra
react-native-math-view
Math view for react native! No WebView!
Stars: ✭ 49 (+172.22%)
Mutual labels:  mathematical-expressions
susa
High Performance Computing (HPC) and Signal Processing Framework
Stars: ✭ 55 (+205.56%)
Mutual labels:  linear-algebra
scalagen
WIP - Scalameta powered code generation
Stars: ✭ 38 (+111.11%)
Mutual labels:  code-generation
EmbedSanitizer
EmbedSantizer is a runtime race detection tool which extends ThreadSanitizer to detect data races in 32-bit ARM applications.
Stars: ✭ 16 (-11.11%)
Mutual labels:  clang
NumNet
Numpy style scientific programming package
Stars: ✭ 17 (-5.56%)
Mutual labels:  linear-algebra
LSQR-cpp
This is a c++ port initially performed by Luis Ibanez of the LSQR library of Chris Paige and Michael Saunders. The same methodology was applied to the LSMR library of David Fong and Michael Saunders.
Stars: ✭ 19 (+5.56%)
Mutual labels:  linear-algebra
FunStripe
An F# library to connect to the Stripe API, including code generators to update the model and requests.
Stars: ✭ 35 (+94.44%)
Mutual labels:  code-generation
SKLinearAlgebra
Swift extensions for Linear Algebra with SceneKit
Stars: ✭ 53 (+194.44%)
Mutual labels:  linear-algebra
vuo
A realtime visual programming language for interactive media.
Stars: ✭ 103 (+472.22%)
Mutual labels:  clang
NAGPythonExamples
Examples and demos showing how to call functions from the NAG Library for Python
Stars: ✭ 46 (+155.56%)
Mutual labels:  linear-algebra
Templates
CodeSmith Generator Templates
Stars: ✭ 52 (+188.89%)
Mutual labels:  code-generation
clangbuilder
Building Clang ♡ Utility and Environment
Stars: ✭ 101 (+461.11%)
Mutual labels:  clang
linalg
Linear algebra library based on LAPACK
Stars: ✭ 42 (+133.33%)
Mutual labels:  linear-algebra
perses
Language-agnostic program reducer.
Stars: ✭ 57 (+216.67%)
Mutual labels:  clang
brian2cuda
A brian2 extension to simulate spiking neural networks on GPUs
Stars: ✭ 46 (+155.56%)
Mutual labels:  code-generation
Linq.Expression.Optimizer
System.Linq.Expression expressions optimizer. http://thorium.github.io/Linq.Expression.Optimizer
Stars: ✭ 81 (+350%)
Mutual labels:  mathematical-expressions
dtt
A C++ header-only for data transfer between linear algebra libraries (Eigen, Armadillo, OpenCV, ArrayFire, LibTorch).
Stars: ✭ 74 (+311.11%)
Mutual labels:  linear-algebra

flatorize

Generate fast implementations of mathematical expressions.

For the hurried

Here is a practical, editable use case - a good starting point to look at the basics.

Idea

Think like this:

Matrix multiplication a * b: Each row of a with each column of b

...write code like you think, without caring about performance...

# Python   c = a * b
c = [[ sum(x*y for x,y in zip(ra,cb)) for cb in zip(*b) ] for ra in a ]
// JavaScript
function matmulrows_zip( a, b )
{
    return a.map( function (ra) { 
        return zip.apply( null, b ).map( function (cb) {
            return sum( 
                zip( ra, cb )
                    .map( function (xy) { return xy[ 0 ] * xy[ 1 ]; } )
            );
        } );
    } );
}

// --> Well encapsulated code, but slow due to function call overhead.

...and let flatorize transform the above into very fast JavaScript code:

// Generated "flatorized" code == factorized + flattened
// 
// - factorized: avoid repeating computations.
// - flattened:  no function call.

function anonymous(a, b) {
/* function (a,b) { return symbol_matmulrows_zip_gen( a, b, 3, 4, 2 ); } */
var
  _0 = a[0]
, _1 = _0[0]
, _2 = _0[1]
, _3 = _0[2]
, _4 = _0[3]
, _5 = a[1]
, _6 = _5[0]
, _7 = _5[1]
, _8 = _5[2]
, _9 = _5[3]
, _a = a[2]
, _b = _a[0]
, _c = _a[1]
, _d = _a[2]
, _e = _a[3]
, _f = b[0]
, _g = _f[0]
, _h = _f[1]
, _i = b[1]
, _j = _i[0]
, _k = _i[1]
, _l = b[2]
, _m = _l[0]
, _n = _l[1]
, _o = b[3]
, _p = _o[0]
, _q = _o[1]
;
return [ [ (_1 * _g) + (_2 * _j) + (_3 * _m) + (_4 * _p), (_1 * _h) + (_2 * _k) + (_3 * _n) + (_4 * _q) ], [ (_6 * _g) + (_7 * _j) + (_8 * _m) + (_9 * _p), (_6 * _h) + (_7 * _k) + (_8 * _n) + (_9 * _q) ], [ (_b * _g) + (_c * _j) + (_d * _m) + (_e * _p), (_b * _h) + (_c * _k) + (_d * _n) + (_e * _q) ] ];

}

Speedups exceed +1000% in many cases, including matrix multiplication and the Discrete Fourier Transform (full results).

A plugin permits to generate even faster JavaScript code using TypedArray, in an asm.js-compatible way. For usage explanations, see the live page.

A plugin permits to generate fast C code as well. For usage explanations, see the live page.

A plugin permits to generate fast D code as well. For usage explanations, see the live page.

More

For more details read the article:

See also the slides and video from the Budapest 2014 nodebp/bpjs meetup.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].