This package has been deprecated

Author message:

This package has moved to matrixlib-js. To install, npm install --save matrixlib-js

matrix-js-lib

1.0.5 • Public • Published

matrix-js-lib

matrix-js-lib is a JavaScript simple matrix calculation library.

Description

There is a single-threaded normal version matrix.js and a multi-threaded version of matrix-multithread.js.

Both APIs are the same, but multithreaded versions will return Promise objects, so you should cook and burn or love it.

It seems that it can be used for machine learning in recent times.

DEMO:

matrix-multithread.js Demo

Test matrix-js-lib(single thread version) in your browser.

Features

  • You do not have to worry about the types of matrixes, arrays, and scalar values.

Usage

Browser

for single thread version

<script src="js/matrix.js"></script>
const mt = Matrix();

for multi thread version

<script src="js/matrix-multithread.js"></script>
const mt = MatrixMultiThread({
    libUrl: `${window.location.href}js/matrix.js`
});

Browserify/Webpack

const Matrix = require('matrix-js-lib');
const mt = Matrix();

Sample code

let m1 = mt.math.matrix.create(3, 3, 7); // single thread version.
let m1 = mt.math.matrix.util.create(3, 3, 7); // multi thread version.

// if multi thread version...
m1.then((d) => {
    console.log(d);
    return d; // return promise object.
}).then((d) => {
    // something code...
});

let m2 = [
     [1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]
 ];

let shape = mt.math.shape(m2); // single thread version.
let shape = mt.math.util.shape(m2); // multi thread version.

let plus = mt.math.plus(m1, m2);
let minus = mt.math.minus(m1, m2);
let multi = mt.math.multi(m1, m2);
let divi = mt.math.divi(m1, m2);
let dot = mt.math.matrix.dot(m1, m2); // math.matrix class
let sum = mt.math.sum(m2);
let sumAxis = mt.math.sum(m2, 1);
let pow = mt.math.pow(m2, 2);
let exp = mt.math.exp(m2);
let log = mt.math.log(m2);
let max = mt.math.max(m2);
let max2 = mt.math.max(3, 5);
let maxIdx = mt.math.maxIdx(m2);
let matchCount = mt.math.matchCount(m1, m2);
let colToRow = mt.math.matrix.colToRow(m2);

let rnorm = mt.math.rnorm(0.01, 1); // single thread version.
let rnorm = mt.math.util.rnorm(0.01, 1); // multi thread version.

let createArr = mt.math.arr.create(10, () => { // single thread version.
    return mt.math.rnorm(0, 0.1);
});
let createArr = mt.math.arr.util.create(10, () => { // multi thread version.
    return mt.math.rnorm(0, 0.1);
});

let arangeArr = mt.math.arr.arange(-5, 5, 0.1, (x) => { // single thread version.
    return Math.round(x * Math.pow(10, 1)) / Math.pow(10, 1);
});
let arangeArr = mt.math.arr.util.arange(-5, 5, 0.1, (x) => { // multi thread version.
    return Math.round(x * Math.pow(10, 1)) / Math.pow(10, 1);
});

Installation

$ npm install --save matrix-js-lib

Author

@webryone

License

MIT

Package Sidebar

Install

npm i matrix-js-lib

Weekly Downloads

1

Version

1.0.5

License

MIT

Last publish

Collaborators

  • kohei.k