Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mateogianolio committed Aug 6, 2019
1 parent df5e1fa commit b2067ef
Show file tree
Hide file tree
Showing 99 changed files with 1,021 additions and 1,563 deletions.
60 changes: 9 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Follow the installation instructions in [nlapack](https://github.com/nperf/nlapack) and [nblas](https://github.com/nperf/nblas) to get maximum performance.

##### In node.js
#### In node.js

```bash
# with C++ bindings
Expand Down Expand Up @@ -39,21 +39,7 @@ Matrix {
*/
```

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

* **OSX** - by default included in the Accelerate framework
* **Debian/Ubuntu** - different options, easiest is to `apt-get install libblas-dev`
* **Windows** - https://icl.cs.utk.edu/lapack-for-windows/

##### In browser

Download a [**release**](https://github.com/mateogianolio/vectorious/releases) and use it like this:

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

Or if you prefer to use a CDN:
#### In browser

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/vectorious/6.0.0/vectorious.min.js"></script>
Expand All @@ -77,53 +63,25 @@ Or if you prefer to use a CDN:
### Examples

**Basic**

* [**Solving linear systems of equations**](https://github.com/mateogianolio/vectorious/tree/master/examples/solve.js)
* [**Using low-level BLAS routines**](https://github.com/mateogianolio/vectorious/tree/master/examples/blas.js)

**Machine learning**
* [**Neural network**](https://github.com/mateogianolio/vectorious/tree/master/examples/neural-network.js) (by [@lucidrains](https://github.com/lucidrains))
* [**Logistic regression**](https://github.com/mateogianolio/vectorious/tree/master/examples/logistic-regression.js)

### [Documentation](https://github.com/mateogianolio/vectorious/wiki)
### Documentation

### Benchmarks
* [**API Documentation**](https://mateogianolio.github.io/vectorious)
* [**Usage guides**](https://github.com/mateogianolio/vectorious/wiki)

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

#### Specs
Run benchmarks with

```bash
$ npm run benchmark
```
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](benchmarks/Matrix/add.png) | ![augment](benchmarks/Matrix/augment.png) | ![binOp](benchmarks/Matrix/binOp.png) |
| ![determinant](benchmarks/Matrix/determinant.png) | ![diag](benchmarks/Matrix/diag.png) | ![gauss](benchmarks/Matrix/gauss.png) |
| ![inverse](benchmarks/Matrix/inverse.png) | ![lu](benchmarks/Matrix/lu.png) | ![multiply](benchmarks/Matrix/multiply.png) |
| ![plu](benchmarks/Matrix/plu.png) | ![product](benchmarks/Matrix/product.png) | ![rank](benchmarks/Matrix/rank.png) |
| ![rowAdd](benchmarks/Matrix/rowAdd.png) | ![scale](benchmarks/Matrix/scale.png) | ![solve](benchmarks/Matrix/solve.png) |
| ![subtract](benchmarks/Matrix/subtract.png) | ![swap](benchmarks/Matrix/swap.png) | ![trace](benchmarks/Matrix/trace.png) |
| ![transpose](benchmarks/Matrix/transpose.png) | | |

| Vector | | |
|---------|--------|--------|
| ![add](benchmarks/Vector/add.png) | ![angle](benchmarks/Vector/angle.png) | ![binOp](benchmarks/Vector/binOp.png) |
| ![combine](benchmarks/Vector/combine.png) | ![dot](benchmarks/Vector/dot.png) | ![normalize](benchmarks/Vector/normalize.png) |
| ![project](benchmarks/Vector/project.png) | ![scale](benchmarks/Vector/scale.png) | ![subtract](benchmarks/Vector/subtract.png) |

| NDArray | | |
|---------|--------|--------|
| ![add](benchmarks/NDArray/add.png) | ![copy](benchmarks/NDArray/copy.png) | ![dot](benchmarks/NDArray/dot.png) |
| ![magnitude](benchmarks/NDArray/magnitude.png) | ![max](benchmarks/NDArray/max.png) | ![min](benchmarks/NDArray/min.png) |
| ![product](benchmarks/NDArray/product.png) | ![scale](benchmarks/NDArray/scale.png) | ![subtract](benchmarks/NDArray/subtract.png) |


## Contributors

Expand Down
2 changes: 1 addition & 1 deletion dist/vectorious.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

733 changes: 297 additions & 436 deletions docs/classes/matrix.html

Large diffs are not rendered by default.

546 changes: 222 additions & 324 deletions docs/classes/ndarray.html

Large diffs are not rendered by default.

642 changes: 262 additions & 380 deletions docs/classes/vector.html

Large diffs are not rendered by default.

400 changes: 207 additions & 193 deletions docs/index.html

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions docs/interfaces/indarray.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h3>data</h3>
<div class="tsd-signature tsd-kind-icon">data<span class="tsd-signature-symbol">:</span> <a href="../index.html#typedarray" class="tsd-signature-type">TypedArray</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/mateogianolio/vectorious/blob/bc9835b/src/types.ts#L37">types.ts:37</a></li>
<li>Defined in <a href="https://github.com/mateogianolio/vectorious/blob/df5e1fa/src/types.ts#L37">types.ts:37</a></li>
</ul>
</aside>
</section>
Expand All @@ -116,7 +116,7 @@ <h3>dtype</h3>
<div class="tsd-signature tsd-kind-icon">dtype<span class="tsd-signature-symbol">:</span> <a href="../index.html#dtype" class="tsd-signature-type">DType</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/mateogianolio/vectorious/blob/bc9835b/src/types.ts#L38">types.ts:38</a></li>
<li>Defined in <a href="https://github.com/mateogianolio/vectorious/blob/df5e1fa/src/types.ts#L38">types.ts:38</a></li>
</ul>
</aside>
</section>
Expand All @@ -126,7 +126,7 @@ <h3>length</h3>
<div class="tsd-signature tsd-kind-icon">length<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/mateogianolio/vectorious/blob/bc9835b/src/types.ts#L39">types.ts:39</a></li>
<li>Defined in <a href="https://github.com/mateogianolio/vectorious/blob/df5e1fa/src/types.ts#L39">types.ts:39</a></li>
</ul>
</aside>
</section>
Expand All @@ -136,7 +136,7 @@ <h3>shape</h3>
<div class="tsd-signature tsd-kind-icon">shape<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">[]</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/mateogianolio/vectorious/blob/bc9835b/src/types.ts#L40">types.ts:40</a></li>
<li>Defined in <a href="https://github.com/mateogianolio/vectorious/blob/df5e1fa/src/types.ts#L40">types.ts:40</a></li>
</ul>
</aside>
</section>
Expand Down Expand Up @@ -194,6 +194,9 @@ <h3>shape</h3>
<li class=" tsd-kind-variable tsd-is-not-exported">
<a href="../index.html#benchmark" class="tsd-kind-icon">benchmark</a>
</li>
<li class=" tsd-kind-variable tsd-is-not-exported">
<a href="../index.html#execsync" class="tsd-kind-icon">exec<wbr>Sync</a>
</li>
<li class=" tsd-kind-variable tsd-is-not-exported">
<a href="../index.html#floor" class="tsd-kind-icon">floor</a>
</li>
Expand Down
Binary file removed docs/media/Matrix/augment.png
Binary file not shown.
Binary file removed docs/media/Matrix/det.png
Binary file not shown.
Binary file removed docs/media/Matrix/diag.png
Binary file not shown.
Binary file removed docs/media/Matrix/eig.png
Binary file not shown.
Binary file removed docs/media/Matrix/gauss.png
Binary file not shown.
Binary file removed docs/media/Matrix/inv.png
Binary file not shown.
Binary file removed docs/media/Matrix/lu.png
Binary file not shown.
Binary file removed docs/media/Matrix/lu_factor.png
Binary file not shown.
Binary file removed docs/media/Matrix/magic.png
Binary file not shown.
Binary file removed docs/media/Matrix/multiply.png
Binary file not shown.
Binary file removed docs/media/Matrix/rank.png
Binary file not shown.
Binary file removed docs/media/Matrix/rowAdd.png
Binary file not shown.
Binary file removed docs/media/Matrix/solve.png
Binary file not shown.
Binary file removed docs/media/Matrix/square.png
Binary file not shown.
Binary file removed docs/media/Matrix/swap.png
Binary file not shown.
Binary file removed docs/media/Matrix/toArray.png
Binary file not shown.
Binary file removed docs/media/Matrix/toString.png
Binary file not shown.
Binary file removed docs/media/Matrix/trace.png
Binary file not shown.
Binary file removed docs/media/Matrix/transpose.png
Binary file not shown.
Binary file removed docs/media/NDArray/abs.png
Binary file not shown.
Binary file removed docs/media/NDArray/acos.png
Binary file not shown.
Binary file removed docs/media/NDArray/acosh.png
Binary file not shown.
Binary file removed docs/media/NDArray/add.png
Binary file not shown.
Binary file removed docs/media/NDArray/asin.png
Binary file not shown.
Binary file removed docs/media/NDArray/asinh.png
Binary file not shown.
Binary file removed docs/media/NDArray/atan.png
Diff not rendered.
Binary file removed docs/media/NDArray/atanh.png
Diff not rendered.
Binary file removed docs/media/NDArray/binOp.png
Diff not rendered.
Binary file removed docs/media/NDArray/cbrt.png
Diff not rendered.
Binary file removed docs/media/NDArray/ceil.png
Diff not rendered.
Binary file removed docs/media/NDArray/check.png
Diff not rendered.
Binary file removed docs/media/NDArray/copy.png
Diff not rendered.
Binary file removed docs/media/NDArray/cos.png
Diff not rendered.
Binary file removed docs/media/NDArray/cosh.png
Diff not rendered.
Binary file removed docs/media/NDArray/dot.png
Diff not rendered.
Binary file removed docs/media/NDArray/each.png
Diff not rendered.
Binary file removed docs/media/NDArray/equals.png
Diff not rendered.
Binary file removed docs/media/NDArray/equidimensional.png
Diff not rendered.
Binary file removed docs/media/NDArray/equilateral.png
Diff not rendered.
Binary file removed docs/media/NDArray/exp.png
Diff not rendered.
Binary file removed docs/media/NDArray/expm1.png
Diff not rendered.
Binary file removed docs/media/NDArray/eye.png
Diff not rendered.
Binary file removed docs/media/NDArray/fill.png
Diff not rendered.
Binary file removed docs/media/NDArray/floor.png
Diff not rendered.
Binary file removed docs/media/NDArray/fround.png
Diff not rendered.
Binary file removed docs/media/NDArray/get.png
Diff not rendered.
Binary file removed docs/media/NDArray/log.png
Diff not rendered.
Binary file removed docs/media/NDArray/log10.png
Diff not rendered.
Binary file removed docs/media/NDArray/log1p.png
Diff not rendered.
Binary file removed docs/media/NDArray/log2.png
Diff not rendered.
Binary file removed docs/media/NDArray/map.png
Diff not rendered.
Binary file removed docs/media/NDArray/max.png
Diff not rendered.
Binary file removed docs/media/NDArray/min.png
Diff not rendered.
Binary file removed docs/media/NDArray/norm.png
Diff not rendered.
Binary file removed docs/media/NDArray/ones.png
Diff not rendered.
Binary file removed docs/media/NDArray/pow.png
Diff not rendered.
Binary file removed docs/media/NDArray/product.png
Diff not rendered.
Binary file removed docs/media/NDArray/random.png
Diff not rendered.
Binary file removed docs/media/NDArray/range.png
Diff not rendered.
Binary file removed docs/media/NDArray/reduce.png
Diff not rendered.
Binary file removed docs/media/NDArray/reshape.png
Diff not rendered.
Binary file removed docs/media/NDArray/round.png
Diff not rendered.
Binary file removed docs/media/NDArray/scale.png
Diff not rendered.
Binary file removed docs/media/NDArray/set.png
Diff not rendered.
Binary file removed docs/media/NDArray/sign.png
Diff not rendered.
Binary file removed docs/media/NDArray/sin.png
Diff not rendered.
Binary file removed docs/media/NDArray/sinh.png
Diff not rendered.
Binary file removed docs/media/NDArray/sqrt.png
Diff not rendered.
Binary file removed docs/media/NDArray/subtract.png
Diff not rendered.
Binary file removed docs/media/NDArray/tan.png
Diff not rendered.
Binary file removed docs/media/NDArray/tanh.png
Diff not rendered.
Binary file removed docs/media/NDArray/trunc.png
Diff not rendered.
Binary file removed docs/media/NDArray/zeros.png
Diff not rendered.
Binary file removed docs/media/Vector/angle.png
Diff not rendered.
Binary file removed docs/media/Vector/combine.png
Diff not rendered.
Binary file removed docs/media/Vector/cross.png
Diff not rendered.
Binary file removed docs/media/Vector/normalize.png
Diff not rendered.
Binary file removed docs/media/Vector/project.png
Diff not rendered.
Binary file removed docs/media/Vector/push.png
Diff not rendered.
Binary file removed docs/media/Vector/toArray.png
Diff not rendered.
Binary file removed docs/media/Vector/toString.png
Diff not rendered.
2 changes: 1 addition & 1 deletion src/Matrix/diagonal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Matrix.prototype.diagonal = function<T extends Matrix>(this: T): T {
const [r, c] = this.shape;
const l2: number = Math.min(r, c);

return this.reshape([l1]).slice(0, l1, l2 + 1);
return this.reshape(l1).slice(0, l1, l2 + 1);
};
39 changes: 1 addition & 38 deletions src/Matrix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,235 +4,198 @@ import { TypedArrayConstructor } from '../types';
export class Matrix extends NDArray {
/**
* Augments `x` and `y`.
* ![](media://Matrix/augment.png)
*/
public static augment: <T extends Matrix>(x: T, y: T) => T;

/**
* Gets the determinant of `x`.
* ![](media://Matrix/det.png)
*/
public static det: <T extends Matrix>(x: T) => number;

/**
* Gets the diagonal of `x`.
* ![](media://Matrix/diagonal.png)
*/
public static diagonal: <T extends Matrix>(x: T) => T;

/**
* Gets eigenvalues and eigenvectors of `x` using the Jacobi method.
* Accelerated with LAPACK `?geev`.
* ![](media://Matrix/eig.png)
*/
public static eig: <T extends Matrix>(x: T) => [T, T];

/**
* Gauss-Jordan elimination (i.e. returns the reduced row echelon form) of `x`.
* ![](media://Matrix/gauss.png)
*/
public static gauss: <T extends Matrix>(x: T) => T;

/**
* Determines the inverse of `x`.
* Accelerated with LAPACK `?getri`.
* ![](media://Matrix/inv.png)
*/
public static inv: <T extends Matrix>(x: T) => T;

/**
* Performs full LU decomposition on `x`.
* Accelerated with LAPACK `?getrf`.
* ![](media://Matrix/lu.png)
*/
public static lu: <T extends Matrix>(x: T) => [T, T, Int32Array];

/**
* Performs LU factorization on `x`.
* Accelerated with LAPACK `?getrf`.
* ![](media://Matrix/lu_factor.png)
*/
public static lu_factor: <T extends Matrix>(x: T) => [T, Int32Array];

/**
* Creates a magic square matrix of `size`
* ![](media://Matrix/magic.png)
*/
public static magic: <T extends Matrix>(size: number, type?: TypedArrayConstructor) => T;

/**
* Multiplies two matrices `x` and `y` of matching dimensions.
* Accelerated with BLAS `?gemm`.
* ![](media://Matrix/multiply.png)
*/
public static multiply: <T extends Matrix>(x: T, y: T) => T;

/**
* Finds the rank of `x` using gaussian elimination.
* ![](media://Matrix/rank.png)
*/
public static rank: <T extends Matrix>(x: T) => number;

/**
* Adds a multiple of one row multiplied by `scalar` to another inside `x`.
* ![](media://Matrix/rowAdd.png)
*/
public static rowAdd: <T extends Matrix>(x: T, dest: number, source: number, scalar?: number) => T;

/**
* Solves the equation AX = B (where A is `x` and B is `y`).
* Accelerated with LAPACK `?gesv`.
* ![](media://Matrix/solve.png)
*/
public static solve: <T extends Matrix>(x: T, y: T) => T;

/**
* Asserts if `x` is square.
* ![](media://Matrix/square.png)
*/
public static square: <T extends Matrix>(x: T) => void;

/**
* Swaps two rows `i` and `j` in `x`.
* ![](media://Matrix/swap.png)
*/
public static swap: <T extends Matrix>(x: T, i: number, j: number) => T;

/**
* Converts current matrix into a two-dimensional array
* ![](media://Matrix/toArray.png)
*/
public static toArray: <T extends Matrix>(x: T) => number[][];

/**
* Converts `x` into a readable formatted string
* ![](media://Matrix/toString.png)
*/
public static toString: <T extends Matrix>(x: T) => string;

/**
* Gets the trace of `x` (the sum of all diagonal elements).
* ![](media://Matrix/trace.png)
*/
public static trace: <T extends Matrix>(x: T) => number;

/**
* Transposes `x` (mirror across the diagonal).
* ![](media://Matrix/transpose.png)
*/
public static transpose: <T extends Matrix>(x: T) => T;

/**
* Augments `x` with current matrix.
* ![](media://Matrix/augment.png)
*/
public augment!: <T extends Matrix>(x: T) => this;

/**
* Gets the determinant of current matrix using LU factorization.
* ![](media://Matrix/det.png)
*/
public det!: () => number;

/**
* Gets the diagonal of current matrix.
* ![](media://Matrix/diagonal.png)
*/
public diagonal!: () => this;

/**
* Gets eigenvalues and eigenvectors of the current matrix using the Jacobi method.
* Accelerated with LAPACK `?geev`.
* ![](media://Matrix/eig.png)
*/
public eig!: <T extends Matrix>() => [T, T];

/**
* Gauss-Jordan elimination (i.e. returns the reduced row echelon form) of current matrix.
* ![](media://Matrix/gauss.png)
*/
public gauss!: () => this;

/**
* Determines the inverse of current matrix using Gaussian elimination.
* Accelerated with LAPACK `?getri`.
* ![](media://Matrix/inv.png)
*/
public inv!: () => this;

/**
* Performs full LU decomposition on current matrix.
* Accelerated with LAPACK `?getrf`.
* ![](media://Matrix/lu.png)
*/
public lu!: <T extends Matrix>() => [T, T, Int32Array];

/**
* Performs LU factorization on current matrix.
* Accelerated with LAPACK `?getrf`.
* ![](media://Matrix/lu_factor.png)
*/
public lu_factor!: () => [this, Int32Array];

/**
* Multiplies current matrix with `x`.
* Accelerated with BLAS `?gemm`.
* ![](media://Matrix/multiply.png)
*/
public multiply!: <T extends Matrix>(x: T) => this;

/**
* Finds the rank of current matrix using gaussian elimination.
* ![](media://Matrix/rank.png)
*/
public rank!: () => number;

/**
* Adds a multiple of one row multiplied by `scalar` to another inside current matrix.
* ![](media://Matrix/rowAdd.png)
*/
public rowAdd!: (dest: number, source: number, scalar?: number) => this;

/**
* Solves the equation AX = B (where A is current matrix and B is `x`).
* Accelerated with LAPACK `?gesv`.
* ![](media://Matrix/solve.png)
*/
public solve!: <T extends Matrix>(x: T) => this;

/**
* Asserts if current matrix is square.
* ![](media://Matrix/square.png)
*/
public square!: () => void;

/**
* Swaps two rows `i` and `j` in current matrix
* ![](media://Matrix/swap.png)
*/
public swap!: (i: number, j: number) => this;

/**
* Converts current matrix into a two-dimensional array
* ![](media://Matrix/toArray.png)
*/
public toArray!: () => number[][];

/**
* Converts current matrix into a readable formatted string.
* ![](media://Matrix/toString.png)
*/
public toString!: () => string;

/**
* Gets the trace of the matrix (the sum of all diagonal elements).
* ![](media://Matrix/trace.png)
*/
public trace!: () => number;

/**
* Transposes current matrix (mirror across the diagonal).
* ![](media://Matrix/transpose.png)
*/
public transpose!: () => this;

Expand All @@ -258,9 +221,9 @@ export class Matrix extends NDArray {
import './augment';
import './det';
import './diagonal';
import './eig';
import './gauss';
import './inv';
import './eig';
import './lu';
import './lu_factor';
import './magic';
Expand Down
2 changes: 1 addition & 1 deletion src/Matrix/transpose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Matrix.prototype.transpose = function<T extends Matrix>(this: T): T {
}
}

return this.reshape([c, r]);
return this.reshape(c, r);
};
Loading

0 comments on commit b2067ef

Please sign in to comment.