/wasmles

Web Assembly Linear Equation Solver built with Rust

Primary LanguageRust

npm (tag) npm bundle size NPM

@flowcircuits/wasmles

An easy to use Web Assembly linear equation solver built with Rust

Installation

yarn add @flowcircuits/wasmles

Usage

Browser

import { LinearEquation } from "@flowcircuits/wasmles";
import wasmInit, { solveLinearEquations } from "@flowcircuits/wasmles/browser";

const linearEquations: LinearEquation[] = [
    { variables: { a: 2, b: 8, c: -1 }, constant: 6 },
    { variables: { a: 1, b: -4, c: 2 }, constant: -6 },
    { variables: { a: 4, b: 2, c: 1 }, constant: 10 },
];

wasmInit().then(() => {
    const solutionMap = solveLinearEquations(linearEquations);
    const solution = Object.fromEntries(solutionMap);
    console.log(solution);
    // {
    //     a: 6,
    //     b: -2,
    //     c: -10,
    // }
});

Node

import { LinearEquation } from "@flowcircuits/wasmles";
import { solveLinearEquations } from "@flowcircuits/wasmles/node";

const linearEquations: LinearEquation[] = [
    { variables: { a: 2, b: 8, c: -1 }, constant: 6 },
    { variables: { a: 1, b: -4, c: 2 }, constant: -6 },
    { variables: { a: 4, b: 2, c: 1 }, constant: 10 },
];

const solutionMap = solveLinearEquations(linearEquations);
const solution = Object.fromEntries(solutionMap);
console.log(solution);
// {
//     a: 6,
//     b: -2,
//     c: -10,
// }

Development

Build

yarn build

Test

yarn test