From e544a18b2a2c94d9547dda1b10a7d74bc3aa7cce Mon Sep 17 00:00:00 2001 From: Daniel Smilkov Date: Sun, 13 Aug 2017 09:23:56 -0400 Subject: [PATCH 1/2] migrate to typescript 2.4.x --- package.json | 2 +- src/math/activation_functions.ts | 16 ++++++++-------- src/math/cost_functions.ts | 4 ++-- src/math/math_cpu.ts | 2 +- src/math/math_cpu_test.ts | 12 ++++++------ src/math/ndarray.ts | 12 ++++++------ 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 354a92d507..76fd5f7bdb 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "tsify": "~3.0.1", "tslint": "~5.6.0", "typedoc": "~0.7.2", - "typescript": "2.3.4", + "typescript": "2.4.2", "watchify": "~3.9.0" }, "scripts": { diff --git a/src/math/activation_functions.ts b/src/math/activation_functions.ts index 0c357f2372..54a735b7bb 100644 --- a/src/math/activation_functions.ts +++ b/src/math/activation_functions.ts @@ -23,13 +23,13 @@ export interface ActivationFunction { } export class TanHFunc implements ActivationFunction { - output(math: NDArrayMath, x: NDArray) { + output(math: NDArrayMath, x: T) { return math.scope(() => { return math.tanh(x); }); } - der(math: NDArrayMath, x: NDArray, y: NDArray) { + der(math: NDArrayMath, x: T, y: T) { return math.scope(() => { const ySquared = math.elementWiseMul(y, y); // 1 - y^2. @@ -39,13 +39,13 @@ export class TanHFunc implements ActivationFunction { } export class ReLUFunc implements ActivationFunction { - output(math: NDArrayMath, x: NDArray) { + output(math: NDArrayMath, x: T) { return math.scope(() => { return math.relu(x); }); } - der(math: NDArrayMath, x: NDArray, y: NDArray) { + der(math: NDArrayMath, x: T, y: T) { return math.scope(() => { return math.step(x); }); @@ -53,13 +53,13 @@ export class ReLUFunc implements ActivationFunction { } export class SigmoidFunc implements ActivationFunction { - output(math: NDArrayMath, x: NDArray) { + output(math: NDArrayMath, x: T) { return math.scope(() => { return math.sigmoid(x); }); } - der(math: NDArrayMath, x: NDArray, y: NDArray) { + der(math: NDArrayMath, x: T, y: T) { return math.scope(() => { // y * (1 - y) = y - y^2 const ySquared = math.elementWiseMul(y, y); @@ -69,13 +69,13 @@ export class SigmoidFunc implements ActivationFunction { } export class SquareFunc implements ActivationFunction { - output(math: NDArrayMath, x: NDArray) { + output(math: NDArrayMath, x: T) { return math.scope(() => { return math.elementWiseMul(x, x); }); } - der(math: NDArrayMath, x: NDArray, y: NDArray) { + der(math: NDArrayMath, x: T, y: T) { return math.scope(() => { // dy/dx = 2*x. return math.scalarTimesArray(Scalar.TWO, x); diff --git a/src/math/cost_functions.ts b/src/math/cost_functions.ts index 44590a0878..5c17cc46ff 100644 --- a/src/math/cost_functions.ts +++ b/src/math/cost_functions.ts @@ -28,7 +28,7 @@ export interface ElementWiseCostFunction { export class SquareCostFunc implements ElementWiseCostFunction { private halfOne = Scalar.new(0.5); - cost(math: NDArrayMath, x1: NDArray, x2: NDArray): NDArray { + cost(math: NDArrayMath, x1: T, x2: T): T { const diff = math.sub(x1, x2); const diffSquared = math.elementWiseMul(diff, diff); const result = math.scalarTimesArray(this.halfOne, diffSquared); @@ -39,7 +39,7 @@ export class SquareCostFunc implements ElementWiseCostFunction { return result; } - der(math: NDArrayMath, x1: NDArray, x2: NDArray): NDArray { + der(math: NDArrayMath, x1: T, x2: T): T { return math.sub(x1, x2); } diff --git a/src/math/math_cpu.ts b/src/math/math_cpu.ts index 170c53b0e3..1967cb8313 100644 --- a/src/math/math_cpu.ts +++ b/src/math/math_cpu.ts @@ -69,7 +69,7 @@ export class NDArrayMathCPU extends NDArrayMath { const outputShape = concat3d_util.computeConcat3DOutputShape(x1.shape, x2.shape, axis); - const values = NDArray.zeros(outputShape); + const values = Array3D.zeros(outputShape); for (let i = 0; i < outputShape[0]; i++) { for (let j = 0; j < outputShape[1]; j++) { diff --git a/src/math/math_cpu_test.ts b/src/math/math_cpu_test.ts index 97bd3f84b5..f7e3e76957 100644 --- a/src/math/math_cpu_test.ts +++ b/src/math/math_cpu_test.ts @@ -245,8 +245,8 @@ describe('NDArrayMathCPU matMul', () => { }); it('A x B^t shapes do not match', () => { - const a = NDArray.zeros([2, 3]); - const b = NDArray.zeros([3, 2]); + const a = Array2D.zeros([2, 3]); + const b = Array2D.zeros([3, 2]); const f = () => { math.matMul( a, b, MatrixOrientation.REGULAR, MatrixOrientation.TRANSPOSED); @@ -255,8 +255,8 @@ describe('NDArrayMathCPU matMul', () => { }); it('A^t x B shapes do not match', () => { - const a = NDArray.zeros([2, 3]); - const b = NDArray.zeros([3, 2]); + const a = Array2D.zeros([2, 3]); + const b = Array2D.zeros([3, 2]); const f = () => { math.matMul( a, b, MatrixOrientation.TRANSPOSED, MatrixOrientation.REGULAR); @@ -265,8 +265,8 @@ describe('NDArrayMathCPU matMul', () => { }); it('A^t x B^t shapes do not match', () => { - const a = NDArray.zeros([3, 2]); - const b = NDArray.zeros([3, 2]); + const a = Array2D.zeros([3, 2]); + const b = Array2D.zeros([3, 2]); const f = () => { math.matMul( a, b, MatrixOrientation.TRANSPOSED, MatrixOrientation.TRANSPOSED); diff --git a/src/math/ndarray.ts b/src/math/ndarray.ts index d12b293b62..861d9e1836 100644 --- a/src/math/ndarray.ts +++ b/src/math/ndarray.ts @@ -98,9 +98,9 @@ export class NDArray { } /** Creates a ndarray of zeros with the specified shape. */ - static zeros(shape: number[]): T { + static zeros(shape: number[]): NDArray { const values = new Float32Array(util.sizeFromShape(shape)); - return NDArray.make(shape, {values}); + return NDArray.make(shape, {values}); } /** Creates a ndarray of zeros with the same shape as the specified ndarray. @@ -389,7 +389,7 @@ export class Array1D extends NDArray { } static zeros(shape: [number]): Array1D { - return NDArray.zeros(shape); + return NDArray.zeros(shape) as Array1D; } } @@ -440,7 +440,7 @@ export class Array2D extends NDArray { } static zeros(shape: [number, number]): Array2D { - return NDArray.zeros(shape); + return NDArray.zeros(shape) as Array2D; } } @@ -495,7 +495,7 @@ export class Array3D extends NDArray { } static zeros(shape: [number, number, number]): Array3D { - return NDArray.zeros(shape); + return NDArray.zeros(shape) as Array3D; } } @@ -558,7 +558,7 @@ export class Array4D extends NDArray { } static zeros(shape: [number, number, number, number]): Array4D { - return NDArray.zeros(shape); + return NDArray.zeros(shape) as Array4D; } } From 7d6c04796e668eb8dacd21af462696fb3b6564fa Mon Sep 17 00:00:00 2001 From: Daniel Smilkov Date: Sun, 13 Aug 2017 10:54:52 -0400 Subject: [PATCH 2/2] shorten travis log by supressing npm run err statements --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a094925fa0..1457e4bf4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,5 @@ node_js: "8" install: - npm install script: - - npm run build - - npm run lint + - npm run build --silent + - npm run lint --silent