Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure class methods into individual files #161

Merged
merged 37 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b97f75f
NDArray restructured, tests passing
mateogianolio Apr 9, 2019
a2c113b
finishing touches on NDArray
mateogianolio Apr 9, 2019
b3277fa
prepare Vector and Matrix, fix tslint
mateogianolio Apr 9, 2019
653acda
Merge branch 'master' into improvement/restructure
mateogianolio Apr 9, 2019
1d31f9a
Merge branch 'master' into improvement/restructure
mateogianolio Apr 16, 2019
37c0158
restructure methods of Vector
mateogianolio Apr 16, 2019
13d069e
disable duplication checks
mateogianolio Apr 16, 2019
b4fe396
...
mateogianolio May 2, 2019
44dcbc1
improve types, replace *.call(this, ...) with this.*(...)
mateogianolio Jun 2, 2019
737d48c
passing tests and lint
mateogianolio Jun 3, 2019
a97d1d2
Merge branch 'master' into improvement/restructure
mateogianolio Jun 3, 2019
103f920
Merge branch 'master' into improvement/restructure
mateogianolio Jul 10, 2019
00844e7
upd dependencies, fix vulns, upd benchmarks, upd docs
mateogianolio Jul 30, 2019
f68addb
fix conflicts
mateogianolio Jul 30, 2019
a5e027d
fix docs
mateogianolio Jul 30, 2019
8a9298e
improve docs
mateogianolio Jul 30, 2019
41a9fff
merge w/ master and resolve conflict
mateogianolio Jul 30, 2019
fd55b76
upd travis buildspec
mateogianolio Jul 30, 2019
8fba48e
upgrade matplotnode to 0.4.1
mateogianolio Jul 30, 2019
e9b9499
upgrade matplotnode to 0.4.2
mateogianolio Jul 30, 2019
8fa6fb7
add libpython-dev to travis buildspec
mateogianolio Jul 30, 2019
9a57349
upd g++ to 4.9
mateogianolio Jul 30, 2019
2f9437d
rm clang
mateogianolio Jul 30, 2019
2d4cf97
nyc config updates
mateogianolio Jul 30, 2019
d9c610a
fix issues with inheritance, split up tests into separate files, rear…
mateogianolio Aug 4, 2019
966e8b9
upgrade deps
mateogianolio Aug 4, 2019
7f6679e
fix #39
mateogianolio Aug 4, 2019
429ea5c
improvements
mateogianolio Aug 4, 2019
ce5b6bd
minor cleanup
mateogianolio Aug 4, 2019
d6a9d81
cleanup jacobi method
mateogianolio Aug 5, 2019
5887608
add lapack optimisations, rename some methods
mateogianolio Aug 5, 2019
ea67e85
dist + docs
mateogianolio Aug 5, 2019
4969c7c
...
mateogianolio Aug 5, 2019
bc9835b
benchmarks
mateogianolio Aug 6, 2019
df5e1fa
add dtype
mateogianolio Aug 6, 2019
b2067ef
improvements
mateogianolio Aug 6, 2019
3d71147
switch version from 6.0.0 to 6.0.0-beta.0
mateogianolio Aug 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "A high performance linear algebra library.",
"main": "built/index.js",
"scripts": {
"test:node": "nyc mocha -r ts-node/register ./src/*.spec.ts",
"test:browser": "mochify --plugin tsify ./src/*.spec.ts",
"test:node": "nyc mocha -r ts-node/register \"./src/**/*.spec.ts\"",
"test:browser": "mochify --plugin tsify \"./src/**/*.spec.ts\"",
"test": "npm run test:node && npm run test:browser",
"lint": "tslint -p . -c tslint.json 'src/*.ts'",
"benchmark": "ts-node ./src/NDArray.bench.ts && ts-node ./src/Vector.bench.ts && ts-node ./src/Matrix.bench.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/Matrix.bench.ts → src/Matrix/index.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bench } from './bench';
import { Matrix } from './Matrix';
import { bench } from '../bench';
import { Matrix } from './';

const { floor, random, sqrt } = Math;
const r: (n: number) => Matrix = (n: number): Matrix => Matrix.random(floor(sqrt(n)), floor(sqrt(n)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
throws,
} from 'assert';

import { Matrix, Vector } from './';
import { Matrix } from './';
import { Vector } from '../';

const round: (value: number, precision: number) => number = (value: number, precision: number): number =>
Number(value.toFixed(precision));
Expand Down
File renamed without changes.
82 changes: 37 additions & 45 deletions src/Matrix.ts → src/Matrix/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NDArray } from './NDArray';
import { TypedArray, TypedArrayConstructor } from './types';
import { Vector } from './Vector';
import { NDArray } from '../NDArray';
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
import { IMatrix, TypedArray, TypedArrayConstructor } from '../types';
import { Vector } from '../Vector';

let nblas: any;
try {
Expand All @@ -10,37 +10,34 @@ try {
const magicHelper: (n: number, x: number, y: number) => number = (n: number, x: number, y: number): number =>
(x + y * 2 + 1) % n;

export class Matrix extends NDArray {
export class Matrix extends NDArray implements IMatrix {
/**
* Static method. Adds two matrices `a` and `b` together.
*/
public static add(a: Matrix, b: Matrix): Matrix {
return a.copy()
.add(b);
public static add(x: Matrix, y: Matrix): Matrix {
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
return x.copy().add(y);
}

/**
* Static method. Augments two matrices `a` and `b` of matching dimensions
* (appends `b` to `a`).
*/
public static augment(a: Matrix, b: Matrix): Matrix {
return a.copy()
.augment(b);
public static augment(x: Matrix, y: Matrix): Matrix {
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
return x.copy().augment(y);
}

/**
* Static method. Perform binary operation on two matrices `a` and `b` together.
*/
public static binOp(a: Matrix, b: Matrix, op: (a: number, b: number, index?: number) => number): Matrix {
return a.copy()
.binOp(b, op);
public static binOp(x: Matrix, y: Matrix, op: (a: number, b: number, index?: number) => number): Matrix {
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
return x.copy().binOp(y, op);
}

/**
* Static method. Checks the equality of two matrices `a` and `b`.
*/
public static equals(a: Matrix, b: Matrix): boolean {
return a.equals(b);
public static equals(x: Matrix, y: Matrix): boolean {
return x.equals(y);
}

/**
Expand Down Expand Up @@ -95,10 +92,10 @@ export class Matrix extends NDArray {
}

/**
* Static method. Multiplies two matrices `a` and `b` of matching dimensions.
* Static method. Multiplies two matrices `x` and `y` of matching dimensions.
*/
public static multiply(a: Matrix, b: Matrix): Matrix {
return a.multiply(b);
public static multiply(x: Matrix, y: Matrix): Matrix {
return x.multiply(y);
}

/**
Expand All @@ -113,16 +110,14 @@ export class Matrix extends NDArray {
* Static method. Performs LU factorization on current matrix.
*/
public static plu(matrix: Matrix): [Matrix, Int32Array] {
return matrix.copy()
.plu();
return matrix.copy().plu();
}

/**
* Static method. Hadamard product of matrices
*/
public static product(a: Matrix, b: Matrix): Matrix {
return a.copy()
.product(b);
public static product(x: Matrix, y: Matrix): Matrix {
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
return x.copy().product(y);
}

/**
Expand All @@ -144,25 +139,22 @@ export class Matrix extends NDArray {
/**
* Static method. Finds the rank of the matrix using row echelon form
*/
public static rank(matrix: Matrix): number {
return matrix.copy()
.rank();
public static rank(x: Matrix): number {
return x.copy().rank();
}

/**
* Static method. Multiplies all elements of a matrix `a` with a specified `scalar`.
* Static method. Multiplies all elements of a matrix `x` with a specified `scalar`.
*/
public static scale(a: Matrix, scalar: number): Matrix {
return a.copy()
.scale(scalar);
public static scale(x: Matrix, scalar: number): Matrix {
return x.copy().scale(scalar);
}

/**
* Static method. Subtracts the matrix `b` from matrix `a`.
* Static method. Subtracts the matrix `y` from matrix `x`.
*/
public static subtract(a: Matrix, b: Matrix): Matrix {
return a.copy()
.subtract(b);
public static subtract(x: Matrix, y: Matrix): Matrix {
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
return x.copy().subtract(y);
}

/**
Expand All @@ -184,9 +176,9 @@ export class Matrix extends NDArray {
/**
* Augments `matrix` with current matrix.
*/
public augment(matrix: Matrix): Matrix {
public augment(x: Matrix): Matrix {
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
const [r1, c1] = this.shape;
const [r2, c2] = matrix.shape;
const [r2, c2] = x.shape;

if (r2 === 0 || c2 === 0) {
return this;
Expand All @@ -197,7 +189,7 @@ export class Matrix extends NDArray {
}

const { data: d1 } = this;
const { data: d2 } = matrix;
const { data: d2 } = x;
const length: number = c1 + c2;
const data: TypedArray = new this.type(length * r1);

Expand All @@ -223,18 +215,18 @@ export class Matrix extends NDArray {
}

/**
* Perform binary operation on `matrix` to the current matrix.
* Perform binary operation on `x` to the current matrix.
*/
public binOp(matrix: Matrix, op: (a: number, b: number, index?: number) => number): Matrix {
public binOp(x: Matrix, op: (a: number, b: number, index?: number) => number): Matrix {
const [r1, c1] = this.shape;
const [r2, c2] = matrix.shape;
const [r2, c2] = x.shape;

if (r1 !== r2 || c1 !== c2) {
throw new Error('sizes do not match!');
}

const { data: d1, length } = this;
const { data: d2 } = matrix;
const { data: d2 } = x;

let i: number;
for (i = 0; i < length; i += 1) {
Expand Down Expand Up @@ -519,18 +511,18 @@ export class Matrix extends NDArray {
}

/**
* Multiplies two matrices `a` and `b` of matching dimensions.
* Multiplies two matrices `x` and `y` of matching dimensions.
*/
public multiply(matrix: Matrix): Matrix {
public multiply(x: Matrix): Matrix {
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
mateogianolio marked this conversation as resolved.
Show resolved Hide resolved
const [r1, c1] = this.shape;
const [r2, c2] = matrix.shape;
const [r2, c2] = x.shape;

if (c1 !== r2) {
throw new Error('sizes do not match');
}

const { data: d1 } = this;
const { data: d2 } = matrix;
const { data: d2 } = x;
const data: TypedArray = new this.type(r1 * c2);

try {
Expand Down
Loading