Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit edb0eba

Browse files
authored
Migrate from tsc 2.3.x to tsc 2.4.x (#38)
* migrate to typescript 2.4.x * shorten travis log by supressing npm run err statements * Merge master into tsc
1 parent b1c1fdf commit edb0eba

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ node_js: "8"
33
install:
44
- npm install
55
script:
6-
- npm run build
7-
- npm run lint
6+
- npm run build --silent
7+
- npm run lint --silent

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"tsify": "~3.0.1",
2626
"tslint": "~5.6.0",
2727
"typedoc": "~0.7.2",
28-
"typescript": "2.3.4",
28+
"typescript": "2.4.2",
2929
"watchify": "~3.9.0"
3030
},
3131
"scripts": {

src/math/activation_functions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export interface ActivationFunction {
2323
}
2424

2525
export class TanHFunc implements ActivationFunction {
26-
output(math: NDArrayMath, x: NDArray) {
26+
output<T extends NDArray>(math: NDArrayMath, x: T) {
2727
return math.scope(() => {
2828
return math.tanh(x);
2929
});
3030
}
3131

32-
der(math: NDArrayMath, x: NDArray, y: NDArray) {
32+
der<T extends NDArray>(math: NDArrayMath, x: T, y: T) {
3333
return math.scope(() => {
3434
const ySquared = math.elementWiseMul(y, y);
3535
// 1 - y^2.
@@ -39,27 +39,27 @@ export class TanHFunc implements ActivationFunction {
3939
}
4040

4141
export class ReLUFunc implements ActivationFunction {
42-
output(math: NDArrayMath, x: NDArray) {
42+
output<T extends NDArray>(math: NDArrayMath, x: T) {
4343
return math.scope(() => {
4444
return math.relu(x);
4545
});
4646
}
4747

48-
der(math: NDArrayMath, x: NDArray, y: NDArray) {
48+
der<T extends NDArray>(math: NDArrayMath, x: T, y: T) {
4949
return math.scope(() => {
5050
return math.step(x);
5151
});
5252
}
5353
}
5454

5555
export class SigmoidFunc implements ActivationFunction {
56-
output(math: NDArrayMath, x: NDArray) {
56+
output<T extends NDArray>(math: NDArrayMath, x: T) {
5757
return math.scope(() => {
5858
return math.sigmoid(x);
5959
});
6060
}
6161

62-
der(math: NDArrayMath, x: NDArray, y: NDArray) {
62+
der<T extends NDArray>(math: NDArrayMath, x: T, y: T) {
6363
return math.scope(() => {
6464
// y * (1 - y) = y - y^2
6565
const ySquared = math.elementWiseMul(y, y);
@@ -69,13 +69,13 @@ export class SigmoidFunc implements ActivationFunction {
6969
}
7070

7171
export class SquareFunc implements ActivationFunction {
72-
output(math: NDArrayMath, x: NDArray) {
72+
output<T extends NDArray>(math: NDArrayMath, x: T) {
7373
return math.scope(() => {
7474
return math.elementWiseMul(x, x);
7575
});
7676
}
7777

78-
der(math: NDArrayMath, x: NDArray, y: NDArray) {
78+
der<T extends NDArray>(math: NDArrayMath, x: T, y: T) {
7979
return math.scope(() => {
8080
// dy/dx = 2*x.
8181
return math.scalarTimesArray(Scalar.TWO, x);

src/math/cost_functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface ElementWiseCostFunction {
2828
export class SquareCostFunc implements ElementWiseCostFunction {
2929
private halfOne = Scalar.new(0.5);
3030

31-
cost(math: NDArrayMath, x1: NDArray, x2: NDArray): NDArray {
31+
cost<T extends NDArray>(math: NDArrayMath, x1: T, x2: T): T {
3232
const diff = math.sub(x1, x2);
3333
const diffSquared = math.elementWiseMul(diff, diff);
3434
const result = math.scalarTimesArray(this.halfOne, diffSquared);
@@ -39,7 +39,7 @@ export class SquareCostFunc implements ElementWiseCostFunction {
3939
return result;
4040
}
4141

42-
der(math: NDArrayMath, x1: NDArray, x2: NDArray): NDArray {
42+
der<T extends NDArray>(math: NDArrayMath, x1: T, x2: T): T {
4343
return math.sub(x1, x2);
4444
}
4545

src/math/math_cpu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class NDArrayMathCPU extends NDArrayMath {
6969
const outputShape =
7070
concat3d_util.computeConcat3DOutputShape(x1.shape, x2.shape, axis);
7171

72-
const values = NDArray.zeros<Array3D>(outputShape);
72+
const values = Array3D.zeros(outputShape);
7373

7474
for (let i = 0; i < outputShape[0]; i++) {
7575
for (let j = 0; j < outputShape[1]; j++) {

src/math/math_cpu_test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ describe('NDArrayMathCPU matMul', () => {
245245
});
246246

247247
it('A x B^t shapes do not match', () => {
248-
const a = NDArray.zeros<Array2D>([2, 3]);
249-
const b = NDArray.zeros<Array2D>([3, 2]);
248+
const a = Array2D.zeros([2, 3]);
249+
const b = Array2D.zeros([3, 2]);
250250
const f = () => {
251251
math.matMul(
252252
a, b, MatrixOrientation.REGULAR, MatrixOrientation.TRANSPOSED);
@@ -255,8 +255,8 @@ describe('NDArrayMathCPU matMul', () => {
255255
});
256256

257257
it('A^t x B shapes do not match', () => {
258-
const a = NDArray.zeros<Array2D>([2, 3]);
259-
const b = NDArray.zeros<Array2D>([3, 2]);
258+
const a = Array2D.zeros([2, 3]);
259+
const b = Array2D.zeros([3, 2]);
260260
const f = () => {
261261
math.matMul(
262262
a, b, MatrixOrientation.TRANSPOSED, MatrixOrientation.REGULAR);
@@ -265,8 +265,8 @@ describe('NDArrayMathCPU matMul', () => {
265265
});
266266

267267
it('A^t x B^t shapes do not match', () => {
268-
const a = NDArray.zeros<Array2D>([3, 2]);
269-
const b = NDArray.zeros<Array2D>([3, 2]);
268+
const a = Array2D.zeros([3, 2]);
269+
const b = Array2D.zeros([3, 2]);
270270
const f = () => {
271271
math.matMul(
272272
a, b, MatrixOrientation.TRANSPOSED, MatrixOrientation.TRANSPOSED);

src/math/ndarray.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ export class NDArray {
9999
}
100100

101101
/** Creates a ndarray of zeros with the specified shape. */
102-
static zeros<T extends NDArray>(shape: number[]): T {
102+
static zeros(shape: number[]): NDArray {
103103
const values = new Float32Array(util.sizeFromShape(shape));
104-
return NDArray.make<T>(shape, {values});
104+
return NDArray.make(shape, {values});
105105
}
106106

107107
/** Creates a ndarray of zeros with the same shape as the specified ndarray.
@@ -390,7 +390,7 @@ export class Array1D extends NDArray {
390390
}
391391

392392
static zeros(shape: [number]): Array1D {
393-
return NDArray.zeros<Array1D>(shape);
393+
return NDArray.zeros(shape) as Array1D;
394394
}
395395
}
396396

@@ -441,7 +441,7 @@ export class Array2D extends NDArray {
441441
}
442442

443443
static zeros(shape: [number, number]): Array2D {
444-
return NDArray.zeros<Array2D>(shape);
444+
return NDArray.zeros(shape) as Array2D;
445445
}
446446
}
447447

@@ -496,7 +496,7 @@ export class Array3D extends NDArray {
496496
}
497497

498498
static zeros(shape: [number, number, number]): Array3D {
499-
return NDArray.zeros<Array3D>(shape);
499+
return NDArray.zeros(shape) as Array3D;
500500
}
501501
}
502502

@@ -559,7 +559,7 @@ export class Array4D extends NDArray {
559559
}
560560

561561
static zeros(shape: [number, number, number, number]): Array4D {
562-
return NDArray.zeros<Array4D>(shape);
562+
return NDArray.zeros(shape) as Array4D;
563563
}
564564
}
565565

0 commit comments

Comments
 (0)