fuath / vectorious

Linear algebra in TypeScript.

Home Page:https://mateogianolio.github.io/vectorious

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vectorious

Backers on Open Collective Sponsors on Open Collective version CDNJS travis maintainability test coverage

A linear algebra library, written in TypeScript and accelerated with C++ bindings to BLAS.

Usage

greenkeeper

In node.js
# with BLAS bindings
$ npm install vectorious

# or, if you don't want BLAS bindings
$ npm install vectorious --no-optional
import {
  Matrix,
  Vector,
  NDArray,
} from 'vectorious';

const x: Matrix = Matrix.random(2, 2);
/*
Matrix {
  shape: [ 2, 2 ],
  data:
   Float32Array [
     0.7041265660588281,
     0.6186458305857421,
     0.032954109874604454,
     0.5198025534810546 ],
  type: [Function: Float32Array] }
*/

const y: Vector = Vector.random(4, -5, 5, Int8Array);
/*
Vector {
  type: [Function: Int8Array],
  data: Int8Array [ -2, 2, 2, -1 ],
  length: 4 }
*/

const z = new NDArray([[[1], [2]]]).add(new NDArray([[[3], [4]]]));
/*
NDArray {
  data: Float32Array [ 4, 6 ],
  length: 2,
  shape: [ 1, 2, 1 ],
  type: [Function: Float32Array] }
*/

Will use your local BLAS copy (if any). Some notes for different operating systems:

In browser

Download a release and use it like this:

<script src="vectorious.min.js"></script>

Or if you prefer to use a CDN:

<script src="https://cdnjs.cloudflare.com/ajax/libs/vectorious/5.3.1/vectorious.min.js"></script>
<script>
  var A = new Matrix([[1], [2], [3]]),
      B = new Matrix([[1, 3, 5]]),
      C = A.multiply(B);

  console.log('C:', C.toArray());
  /* C: [
    [1, 3, 5],
    [2, 6, 10],
    [3, 9, 15]
  ] */
</script>

Examples

Basic

Machine learning

Documentation

The documentation is located in the wiki section of this repository.

Go to wiki.

Benchmarks

Benchmarks are performed using Float32Array of size n (matrices are sized sqrt(n) x sqrt(n)).

Specs

Macbook Pro Early '15
Processor: 2,7 GHz Intel Core i5
Memory: 8 GB 1867 MHz DDR3
GPU: Intel Iris Graphics 6100 1536 MB

Results

Matrix
add augment binOp
determinant diag gauss
inverse lu multiply
plu product rank
rowAdd scale solve
subtract swap trace
transpose
Vector
add angle binOp
combine dot normalize
project scale subtract
NDArray
add copy dot
magnitude max min
product scale subtract

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

About

Linear algebra in TypeScript.

https://mateogianolio.github.io/vectorious

License:MIT License


Languages

Language:TypeScript 99.3%Language:JavaScript 0.7%