Skip to content

Commit 7eb7ae5

Browse files
authored
[tfjs-layers] Have tfjs-layers inherit the global lint setting (tensorflow#1893)
DEV - Upgrade layers to typescript 3.5.3 - Have tfjs-layers inherit the global lint setting. - Fix lint issues.
1 parent 94d41fe commit 7eb7ae5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+353
-511
lines changed

tfjs-layers/.vscode/tasks.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"command": "yarn",
6+
"label": "lint",
7+
"type": "shell",
8+
"args": [
9+
"lint"
10+
],
11+
"problemMatcher": {
12+
"base": "$tslint5",
13+
"owner": "tslint-type-checked",
14+
"fileLocation": "absolute"
15+
}
16+
},
17+
{
18+
"command": "yarn",
19+
"label": "build",
20+
"type": "shell",
21+
"args": ["build", "--pretty", "false", "--noEmit"],
22+
"problemMatcher": [
23+
"$tsc"
24+
]
25+
}
26+
]
27+
}

tfjs-layers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"ts-node": "7.0.0",
3333
"tslint": "~5.11.0",
3434
"tslint-no-circular-imports": "^0.5.0",
35-
"typescript": "3.3.3333",
35+
"typescript": "3.5.3",
3636
"yalc": "~1.0.0-pre.21"
3737
},
3838
"scripts": {

tfjs-layers/src/activations_test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
*/
1414
import {scalar, tensor1d, tensor2d, tensor3d} from '@tensorflow/tfjs-core';
1515

16-
import {Elu, HardSigmoid, Linear, Relu, Relu6, Selu, Sigmoid, Softmax, LogSoftmax, Softplus, Softsign, Tanh} from './activations';
16+
import {Elu, HardSigmoid, Linear, LogSoftmax, Relu, Relu6, Selu, Sigmoid, Softmax, Softplus, Softsign, Tanh} from './activations';
1717
import {describeMathCPUAndGPU, expectNoLeakedTensors, expectTensorsClose} from './utils/test_utils';
1818

19-
2019
describeMathCPUAndGPU('linear activation', () => {
2120
const initVals = new Float32Array([-1, 2, 0, 4, -5, 6]);
2221
const expectedVals = new Float32Array([-1, 2, 0, 4, -5, 6]);
@@ -88,7 +87,6 @@ describeMathCPUAndGPU('selu activation', () => {
8887
});
8988
});
9089

91-
9290
describeMathCPUAndGPU('relu activation', () => {
9391
const initVals = new Float32Array([-1, 2, 0, 4, -5, 6]);
9492
const expectedVals = new Float32Array([0, 2, 0, 4, 0, 6]);
@@ -286,15 +284,15 @@ describeMathCPUAndGPU('logsoftmax activation', () => {
286284
expectTensorsClose(logsoftmax(initX), expectedVals);
287285
});
288286
it('2D', () => {
289-
const initX = tensor2d([[0, 1, 3, 9,], [0, 1, 3, 9]]);
287+
const initX = tensor2d([[0, 1, 3, 9], [0, 1, 3, 9]]);
290288
const expectedVals = tensor2d(
291-
[[-9.003, -8.003, -6.003, -0.003], [-9.003, -8.003, -6.003, -0.003]]);
289+
[[-9.003, -8.003, -6.003, -0.003], [-9.003, -8.003, -6.003, -0.003]]);
292290
expectTensorsClose(logsoftmax(initX), expectedVals);
293291
});
294292
it('3D', () => {
295-
const initX = tensor3d([[[0, 1, 3, 9,], [0, 1, 3, 9]]]);
293+
const initX = tensor3d([[[0, 1, 3, 9], [0, 1, 3, 9]]]);
296294
const expectedVals = tensor3d(
297-
[[[-9.003, -8.003, -6.003, -0.003], [-9.003, -8.003, -6.003, -0.003]]]);
295+
[[[-9.003, -8.003, -6.003, -0.003], [-9.003, -8.003, -6.003, -0.003]]]);
298296
expectTensorsClose(logsoftmax(initX), expectedVals);
299297
});
300298
it('Does not leak', () => {

tfjs-layers/src/backend/tfjs_backend.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ export function concatAlongFirstAxis(a: Tensor, b: Tensor): Tensor {
317317
return tfc.concat4d([a as Tensor4D, b as Tensor4D], 0);
318318
default:
319319
throw new ValueError(
320-
'concatAlongFirstAxis() received an unsupported tensor rank: ' +
321-
a.rank);
320+
`concatAlongFirstAxis() received an unsupported ` +
321+
`tensor rank: ${a.rank}`);
322322
}
323323
}
324324

@@ -343,7 +343,6 @@ export function tile(x: Tensor, n: number|number[]): Tensor {
343343

344344
/* Creation of random tensors. */
345345

346-
347346
/**
348347
* Get a tensor with normal distribution of values.
349348
*
@@ -547,7 +546,7 @@ export function pow(x: Tensor, a: Tensor|number): Tensor {
547546
throw new NotImplementedError(
548547
`Non-int32 dtype (${a.dtype}) is not supported by pow() yet`);
549548
}
550-
return tfc.pow(x, a as Tensor);
549+
return tfc.pow(x, a);
551550
});
552551
}
553552

@@ -559,8 +558,8 @@ function reshapeBias(xRank: number, bias: Tensor, dataFormat: string) {
559558

560559
if (bias.rank !== 1 && bias.rank !== xRank) {
561560
throw new ValueError(
562-
'Unexpected bias dimensions: ' + bias.rank +
563-
'; expected it to be 1 or ' + xRank);
561+
`Unexpected bias dimensions: ${bias.rank}` +
562+
`; expected it to be 1 or ${xRank}`);
564563
}
565564

566565
if (xRank === 5) {

tfjs-layers/src/backend/tfjs_backend_test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {LayerVariable} from '../variables';
2222

2323
import * as K from './tfjs_backend';
2424

25-
2625
describe('TensorMath', () => {
2726
it('Setting and getting backend', () => {
2827
// Default deeplearn.js backend is WebGL (GPU).
@@ -318,7 +317,6 @@ describeMathCPUAndGPU('sliceAlongLastAxis', () => {
318317
});
319318
});
320319

321-
322320
describeMathCPUAndGPU('sliceAlongAxis', () => {
323321
it('1D', () => {
324322
const array1DData = [10, 20, 30, 40];
@@ -359,7 +357,6 @@ describeMathCPUAndGPU('sliceAlongAxis', () => {
359357
tensor3d([[[1], [3]], [[5], [7]]], [2, 2, 1]));
360358
});
361359

362-
363360
it('4D', () => {
364361
const array4DData = [[[[10, 1]]], [[[20, 2]]], [[[30, 3]]], [[[40, 4]]]];
365362
const x = tensor4d(array4DData, [4, 1, 1, 2]);
@@ -674,7 +671,6 @@ describeMathCPUAndGPU('Gather', () => {
674671
});
675672
});
676673

677-
678674
describeMathCPUAndGPU('Square', () => {
679675
it('Element-wise square', () => {
680676
expectTensorsClose(

tfjs-layers/src/base_callbacks.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ export class BaseLogger extends BaseCallback {
252252
} else {
253253
this.totals[key] = 0;
254254
}
255-
this.totals[key] = tidy(
256-
() => add((this.totals[key] as Scalar), mul(value, batchSize)) as
257-
Scalar);
255+
const total: Scalar =
256+
tidy(() => add((this.totals[key]), mul(value, batchSize)));
257+
this.totals[key] = total;
258258
if (oldTotalsToDispose != null) {
259259
oldTotalsToDispose.dispose();
260260
}
@@ -272,8 +272,8 @@ export class BaseLogger extends BaseCallback {
272272
logs[key] = this.totals[key] as number / this.seen;
273273
} else {
274274
tidy(() => {
275-
logs[key] = mul(div(1, this.seen) as Scalar,
276-
this.totals[key] as Scalar) as Scalar;
275+
const log: Scalar = mul(div(1, this.seen), this.totals[key]);
276+
logs[key] = log;
277277
(this.totals[key] as Tensor).dispose();
278278
keep(logs[key] as Scalar);
279279
});
@@ -470,7 +470,7 @@ export function standardizeCallbacks(
470470
callbacks = {} as BaseCallback;
471471
}
472472
if (callbacks instanceof BaseCallback) {
473-
return [callbacks as BaseCallback];
473+
return [callbacks];
474474
}
475475
if (Array.isArray(callbacks) && callbacks[0] instanceof BaseCallback) {
476476
return callbacks as BaseCallback[];

tfjs-layers/src/base_callbacks_test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import * as tfl from './index';
2121
import {disposeTensorsInLogs, Logs, resolveScalarsInLogs, UnresolvedLogs} from './logs';
2222
import {describeMathCPUAndGPU} from './utils/test_utils';
2323

24-
2524
describe('BaseLogger Callback', () => {
2625
it('Records and averages losses in an epoch', async () => {
2726
const baseLogger = new BaseLogger();
@@ -170,7 +169,6 @@ describeMathCPUAndGPU('disposeTensorsInLogs', () => {
170169
});
171170
});
172171

173-
174172
describe('History Callback', () => {
175173
it('onTrainBegin', async () => {
176174
const history = new History();

tfjs-layers/src/callbacks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export abstract class Callback extends BaseCallback {
2424
if (!(model instanceof LayersModel)) {
2525
throw new Error('model must be a LayersModel, not some other Container');
2626
}
27-
this.model = model as LayersModel;
27+
this.model = model;
2828
}
2929
}
3030

tfjs-layers/src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function getUniqueTensorName(scopedName: string): string {
9393
nameMap.set(scopedName, nameMap.get(scopedName) + 1);
9494

9595
if (index > 0) {
96-
const result = scopedName + '_' + index;
96+
const result = `${scopedName}_${index}`;
9797
// Mark the composed name as used in case someone wants
9898
// to call getUniqueTensorName("name_1").
9999
nameMap.set(result, 1);

tfjs-layers/src/common_test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import {checkDataFormat, checkPaddingMode, checkPoolMode, getUniqueTensorName, isValidTensorName} from './common';
1616
import {VALID_DATA_FORMAT_VALUES, VALID_PADDING_MODE_VALUES, VALID_POOL_MODE_VALUES} from './keras_format/common';
1717

18-
1918
describe('checkDataFormat', () => {
2019
it('Valid values', () => {
2120
const extendedValues = VALID_DATA_FORMAT_VALUES.concat([undefined, null]);
@@ -85,7 +84,6 @@ describe('checkPoolMode', () => {
8584
});
8685
});
8786

88-
8987
describe('isValidTensorName', () => {
9088
it('Valid tensor names', () => {
9189
expect(isValidTensorName('a')).toEqual(true);

0 commit comments

Comments
 (0)