Skip to content

NippunSharma/mljs_linalg

Repository files navigation

@ml.js/linalg is a linear algebra library for the browser based on armadillo.

@ml.js/linalg uses Web Assembly to run armadillo code (in C++) in the browser.

Steps to install.

This library can be installed directly via npm:

npm install "@ml.js/linalg"

Basic usage.

import { mljsInit } from "@ml.js/core";
import { Matrix } from "@ml.js/linalg";

await mljsInit(); // initialize mljs-core.

async getMatrix() {
  const A: Matrix<number> = new Matrix<number>({ n_rows: 2, n_cols: 2 }, "float");
  return A;
}

const A = await getMatrix();
A.funcFill((i, j) => i + j); // fill matrix A.
const B = A.t(); // transpose of A.

console.log(A.toString());
console.log(B.toString());

Steps to build.

  1. Clone github repo.
git clone --recurse-submodules https://github.com/NippunSharma/mljs_linalg
  1. Move to project dir.
cd mljs_linalg
mkdir -p build
  1. Build clapack object files first.
make clapack
  1. Build mljs_linalg.wasm binary along with mljs_linalg.js.
make mljs_linalg
  1. Now, generate the dist dir.
npm run build

Alternatively, you can directly execute npm run build and it will use the pre-existing binary file in resources/. However, if anything is changed in src/embind, it is recommended to rebuild the binary.