Package Exports
- matrixlib-js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (matrixlib-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
matrixlib-js
matrixlib-js is a JavaScript simple matrix calculation library.
Description
There is a single-threaded normal version matrixlib.js and a multi-threaded version of matrixlib-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:
Test matrixlib-js(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/matrixlib.js"></script>
const mt = MatrixLib();for multi thread version
<script src="js/matrixlib-multithread.js"></script>
const mt = MatrixLibMultiThread({
libUrl: `${window.location.protocol}//${window.location.hostname}${(() => {return window.location.port ? ':' + window.location.port : '';})()}${window.location.pathname}js/matrixlib.js`
});Browserify/Webpack
const Matrix = require('matrixlib-js');
const mt = MatrixLib();Sample code
const mt = MatrixLibMultiThread({
libUrl: `${window.location.protocol}//${window.location.hostname}${(() => {return window.location.port ? ':' + window.location.port : '';})()}/js/matrixlib.js`
});
(async () => {
let m1 = await mt.math.matrix.util.create(3, 3, 7);
let m2 = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
console.log('m1', m1);
console.log('m2', m2);
let dot = await mt.math.dot(m1, m2);
console.log('dot', dot);
let plus = await mt.math.plus(m1, m2);
console.log('plus', plus);
let minus = await mt.math.minus(m1, m2);
console.log('minus', minus);
let multi = await mt.math.multi(m1, m2);
console.log('multi', multi);
let div = await mt.math.div(m1, m2);
console.log('div', div);
let more = await mt.math.more(m1, m2);
console.log('more', more);
let less = await mt.math.less(m1, m2);
console.log('less', less);
let moreEq = await mt.math.moreEq(m1, m2);
console.log('moreEq', moreEq);
let lessEq = await mt.math.lessEq(m1, m2);
console.log('lessEq', lessEq);
let boolToInt = await mt.math.boolToInt(more);
console.log('boolToInt', boolToInt);
let sum = await mt.math.sum(m2);
console.log('sum', sum);
// let sumAxis = await mt.math.sum(m2, 1);
// console.log('sumAxis', sumAxis);
let pow = await mt.math.pow(m1, 2);
console.log('pow', pow);
let exp = await mt.math.exp(m2);
console.log('exp', exp);
let log = await mt.math.log(m2);
console.log('log', log);
let max = await mt.math.max(m2);
console.log('max', max);
let maximum = await mt.math.maximum(m1, m2);
console.log('maximum', maximum);
let maxIdx = await mt.math.maxIdx(m2);
console.log('maxIdx', maxIdx);
let matchCount = await mt.math.matchCount(m1, m2);
console.log('matchCount', matchCount);
let flatten = await mt.math.flatten(m2);
console.log('flatten', flatten);
console.log(
'shape',
mt.math.util.shape(m2)
);
console.log(
'rnorm',
mt.util.rnorm(0, 0.01)
);
console.log(
'create(arr)',
mt.math.arr.util.create(10, () => { return mt.util.rnorm(0, 0.1); })
);
console.log(
'create(matrix)',
mt.math.matrix.util.create(10, 5, () => { return mt.util.rnorm(0, 0.1); })
);
console.log(
'arange',
mt.math.arr.util.arange(-5, 5, 0.1, (x) => { return Math.round(x * Math.pow(10, 1)) / Math.pow(10, 1); })
);
})();Installation
$ npm install --save matrixlib-jsor
$ yarn add matrixlib-js