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
Home • Documentation • Benchmarks
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
const M = new eig.Matrix([[1, 2], [3, 4]])
M.print("M");
M.inverse();
M.print("Minv");
eig.GC.flush();
})();
This minimal example can be found under ./example
The documentation is available at eigen.js
Make sure Emscripten is intalled & activated in your terminal session
source path/to/emsdk/emsdk_env.sh
emcc -v
Dowload the latest versions of Eigen and OSPQ (optional, see below), and put then in the lib
directory
lib/eigen
lib/ospq
Now compile osqp for a Webassembly target
cd lib/ospq
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
The documentation is generated from classes descriptions using documentation.js
documentation build src/classes/ -f json -o docs/doc.json