All Projects → BertrandBev → eigen-js

BertrandBev / eigen-js

Licence: other
⚡ Eigen-js is a port of the Eigen C++ linear algebra library

Programming Languages

C++
36643 projects - #6 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to eigen-js

eigen
Owl's OCaml Interface to Eigen3 C++ Library
Stars: ✭ 30 (-61.54%)
Mutual labels:  matrix, linear-algebra, eigen
Spmp
sparse matrix pre-processing library
Stars: ✭ 62 (-20.51%)
Mutual labels:  matrix, linear-algebra
Mathnet Numerics
Math.NET Numerics
Stars: ✭ 2,688 (+3346.15%)
Mutual labels:  matrix, linear-algebra
Peroxide
Rust numeric library with R, MATLAB & Python syntax
Stars: ✭ 191 (+144.87%)
Mutual labels:  matrix, linear-algebra
Owl
Owl - OCaml Scientific and Engineering Computing @ http://ocaml.xyz
Stars: ✭ 919 (+1078.21%)
Mutual labels:  matrix, linear-algebra
Notecalc3
NoteCalc is a handy calculator trying to bring the advantages of Soulver to the web.
Stars: ✭ 879 (+1026.92%)
Mutual labels:  matrix, linear-algebra
Nalgebra
Linear algebra library for Rust.
Stars: ✭ 2,433 (+3019.23%)
Mutual labels:  matrix, linear-algebra
Vectorious
Linear algebra in TypeScript.
Stars: ✭ 616 (+689.74%)
Mutual labels:  matrix, linear-algebra
Numphp
Mathematical PHP library for scientific computing
Stars: ✭ 120 (+53.85%)
Mutual labels:  matrix, linear-algebra
Eigen Git Mirror
THIS MIRROR IS DEPRECATED -- New url: https://gitlab.com/libeigen/eigen
Stars: ✭ 1,659 (+2026.92%)
Mutual labels:  matrix, linear-algebra
Node Sylvester
🐱 Sylvester is a vector, matrix, and geometry library for JavaScript, that runs in the browser and on the server.
Stars: ✭ 144 (+84.62%)
Mutual labels:  matrix, linear-algebra
Mumps.jl
A Julia Interface to MUMPS
Stars: ✭ 6 (-92.31%)
Mutual labels:  matrix, linear-algebra
Fmatvec
A fast vector/matrix library
Stars: ✭ 5 (-93.59%)
Mutual labels:  matrix, linear-algebra
Numeric
N-dimensional matrix class for Rust
Stars: ✭ 51 (-34.62%)
Mutual labels:  matrix, linear-algebra
Cgmath
A linear algebra and mathematics library for computer graphics.
Stars: ✭ 773 (+891.03%)
Mutual labels:  matrix, linear-algebra
Phpsci Carray
PHP library for scientific computing powered by C
Stars: ✭ 176 (+125.64%)
Mutual labels:  matrix, linear-algebra
Blasjs
Pure Javascript manually written 👌 implementation of BLAS, Many numerical software applications use BLAS computations, including Armadillo, LAPACK, LINPACK, GNU Octave, Mathematica, MATLAB, NumPy, R, and Julia.
Stars: ✭ 241 (+208.97%)
Mutual labels:  matrix, linear-algebra
Armadillo Code
Armadillo: fast C++ library for linear algebra & scientific computing - http://arma.sourceforge.net
Stars: ✭ 388 (+397.44%)
Mutual labels:  matrix, linear-algebra
Matrex
A blazing fast matrix library for Elixir/Erlang with C implementation using CBLAS.
Stars: ✭ 429 (+450%)
Mutual labels:  matrix, linear-algebra
Lacaml
OCaml bindings for BLAS/LAPACK (high-performance linear algebra Fortran libraries)
Stars: ✭ 101 (+29.49%)
Mutual labels:  matrix, linear-algebra

npm version Website shields.io Made with emscripten License: MIT

Eigen.js

Eigen.js is a port of the Eigen C++ linear algebra library

It uses a WebAssembly compiled subset of the Eigen library, and implements a garbage collection mechanism to manage memory

Live demo & documentation

An interactive documentation is available at eigen-js. Stress benchmarks can be found here

Usage

Eigen.js can be installed via npm or yarn

npm install eigen
yarn add eigen

In a node (v14) application or in the browser (using webpack)

// test.mjs
import eig from 'eigen';

(async () => {
  await eig.ready;
  let M = new eig.Matrix([[1, 2], [3, 4]]);
  M.print("M");
  M = M.inverse();
  M.print("Minv");
  eig.GC.flush();
})();

This minimal example can be found under ./example To run it, execute

cd example
node test.mjs

Which results in

M
[[1.00, 2.00]
 [3.00, 4.00]]
Minv
[[-2.00, 1.00]
 [1.50, -0.50]]

Allocation

The WebAssembly binary requires a manual memory management for objects allocated on the heap. Every time a matrix is created, it will be allocated on the heap and its memory won't be freed until its delete() method is invoked

// test.mjs
import eig from 'eigen';

(async () => {
  await eig.ready;
  let M = new eig.Matrix([[1, 2], [3, 4]]); // Memory is allocated for M
  M.print("M");
  M.delete(); // Memory is freed here
  M.print("M"); // This will trigger an error
})();

It can be cumbersome to call delete() on every object, especially for chained computations. Take for example const I2 = eig.Matrix.identity(2, 2).matAdd(eig.Matrix.identity(2, 2)). The identity matrix passed as an argument to matAdd(...) will be allocated but never freed, which will leak memory. To make things easier to manage, eig.GC keeps tracks of all the allocated objects on the heap and frees them all upon calling eig.GC.flush().

There could be instances where one would want to keep some matrices in memory while freeing a bunch of temporary ones used for computations. The method eig.GC.pushException(...matrices) whitelists its arguments to prevent eig.GC.flush() from flushing them. eig.GC.popException(...matrices) cancels any previous whitelisting.

// test.mjs
import eig from 'eigen';

(async () => {
  await eig.ready;
  const x = new eig.Matrix([[1, 2], [3, 4]]);
  eig.GC.pushException(x); // Whitelist x
  // Perform some computations
  const R = new eig.Matrix([[.1, 0], [.5, .1]]);
  x.matAddSelf(R.matMul(eig.Matrix.ones(2, 2)));
  // Free memory
  eig.GC.flush();
  x.print("x"); // x is still around!
})();

Documentation

The documentation is available at eigen.js

Build

Make sure Emscripten is intalled & activated in your terminal session

source path/to/emsdk/emsdk_env.sh
emcc -v

Install dependencies Eigen 3.3.9 and OSQP (optional, see below)

git submodule update --init --recursive

Now compile osqp for a Webassembly target

cd lib/osqp
mkdir build; cd build
emcmake cmake ..
emmake make

Once done, eigen.js can be compile to a wasm binary

# From the root directory
mkdir build
emcc -I lib/eigen -I lib/osqp/include -Isrc lib/osqp/build/out/libosqp.a -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=0 -O3 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 --bind -o build/eigen_gen.js src/cpp/embind.cc 

If you are not interested in the OSQP functionality, you can build without installing it with

emcc -D NO_OSQP -I lib/eigen  -Isrc -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=0 -O3 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 --bind -o build/eigen_gen.js src/cpp/embind.cc

Generate the documentation

The documentation is generated from classes descriptions using documentation.js

documentation build src/classes/ -f json -o docs/doc.json
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].