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

Commit f55434a

Browse files
authored
Add a script to manually invoke clang-format on TS files. (#1854)
* Add a script to manually invoke clang-format on TS files. This solves the problem of VSCode picking up various versions of clang-format for formatting saves. I ran this on the repo and a few files are currently out-of-style. We can also add a precommit hook for this if we want as well: https://www.npmjs.com/package/clang-format * Fix block
1 parent f184337 commit f55434a

22 files changed

+498
-561
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"build:bazel": "bazel build //...",
5858
"build-npm": "./scripts/build-npm.sh",
5959
"build-test-snippets": "yarn tsc --project ./scripts/test_snippets/tsconfig.json",
60+
"format-all": "clang-format -i -style=Google --glob=src/**/*.ts",
6061
"link-local": "yalc link",
6162
"publish-local": "rimraf dist/ && yarn build && rollup -c && yalc push",
6263
"lint": "tslint -p . -t verbose",

src/backends/cpu/backend_cpu.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export class MathBackendCPU implements KernelBackend {
7979
public blockSize = 48;
8080

8181
private data: DataStorage<TensorData<DataType>>;
82-
private fromPixels2DContext: CanvasRenderingContext2D
83-
| OffscreenCanvasRenderingContext2D;
82+
private fromPixels2DContext: CanvasRenderingContext2D|
83+
OffscreenCanvasRenderingContext2D;
8484
private firstUse = true;
8585

8686
constructor() {
@@ -134,12 +134,11 @@ export class MathBackendCPU implements KernelBackend {
134134

135135
const isPixelData = (pixels as PixelData).data instanceof Uint8Array;
136136
const isImageData =
137-
typeof(ImageData) !== 'undefined' && pixels instanceof ImageData;
138-
const isVideo =
139-
typeof(HTMLVideoElement) !== 'undefined'
140-
&& pixels instanceof HTMLVideoElement;
141-
const isImage = typeof(HTMLImageElement) !== 'undefined'
142-
&& pixels instanceof HTMLImageElement;
137+
typeof (ImageData) !== 'undefined' && pixels instanceof ImageData;
138+
const isVideo = typeof (HTMLVideoElement) !== 'undefined' &&
139+
pixels instanceof HTMLVideoElement;
140+
const isImage = typeof (HTMLImageElement) !== 'undefined' &&
141+
pixels instanceof HTMLImageElement;
143142

144143
let vals: Uint8ClampedArray|Uint8Array;
145144
// tslint:disable-next-line:no-any

src/backends/webgl/addn_gpu.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export class AddNProgram implements GPGPUProgram {
2929
const snippets: string[] = [];
3030
// Get target elements from every input tensor.
3131
this.variableNames.forEach(variable => {
32-
snippets.push(
33-
`float v${variable} = get${variable}AtOutCoords();`
34-
);
32+
snippets.push(`float v${variable} = get${variable}AtOutCoords();`);
3533
});
3634

3735
// Calculate the sum of all elements.
38-
const operation = this.variableNames.map(variable => {
39-
return `v${variable}`;
40-
}).join(' + ');
36+
const operation = this.variableNames
37+
.map(variable => {
38+
return `v${variable}`;
39+
})
40+
.join(' + ');
4141

4242
this.userCode = `
4343
void main() {

src/backends/webgl/addn_packed_gpu.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export class AddNPackedProgram implements GPGPUProgram {
3030
const snippets: string[] = [];
3131
// Get target elements from every input tensor.
3232
this.variableNames.forEach(variable => {
33-
snippets.push(
34-
`vec4 v${variable} = get${variable}AtOutCoords();`
35-
);
33+
snippets.push(`vec4 v${variable} = get${variable}AtOutCoords();`);
3634
});
3735

3836
// Calculate the sum of all elements.
39-
const operation = this.variableNames.map(variable => {
40-
return `v${variable}`;
41-
}).join(' + ');
37+
const operation = this.variableNames
38+
.map(variable => {
39+
return `v${variable}`;
40+
})
41+
.join(' + ');
4242

4343
this.userCode = `
4444
void main() {

src/backends/webgl/crop_and_resize_gpu.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,48 @@
1515
* =============================================================================
1616
*/
1717

18-
import { GPGPUProgram } from './gpgpu_math';
18+
import {GPGPUProgram} from './gpgpu_math';
1919

2020
export class CropAndResizeProgram implements GPGPUProgram {
2121
variableNames = ['Image', 'Boxes', 'BoxInd'];
2222
outputShape: number[] = [];
2323
userCode: string;
2424

2525
constructor(
26-
imageShape: [number, number, number, number], boxShape: [number, number],
27-
cropSize: [number, number], method: 'bilinear' | 'nearest',
28-
extrapolationValue: number) {
26+
imageShape: [number, number, number, number], boxShape: [number, number],
27+
cropSize: [number, number], method: 'bilinear'|'nearest',
28+
extrapolationValue: number) {
2929
const [batch, imageHeight, imageWidth, depth] = imageShape;
30-
const [numBoxes,] = boxShape;
30+
const [numBoxes, ] = boxShape;
3131
const [cropHeight, cropWidth] = cropSize;
3232
this.outputShape = [numBoxes, cropHeight, cropWidth, depth];
3333
const methodId = method === 'bilinear' ? 1 : 0;
3434

3535
const [inputHeightFloat, inputWidthFloat] =
36-
[`${imageHeight - 1}.0`, `${imageWidth - 1}.0`];
36+
[`${imageHeight - 1}.0`, `${imageWidth - 1}.0`];
3737

3838
const [heightRatio, heightScale, inY] = cropHeight > 1 ?
39-
[
40-
`${(imageHeight-1)/(cropHeight-1)}`,
41-
'(y2-y1) * height_ratio',
42-
`y1*${inputHeightFloat} + float(y)*(height_scale)`,
43-
] :
44-
[
45-
'0.0',
46-
'0.0',
47-
`0.5 * (y1+y2) * ${inputHeightFloat}`,
48-
];
39+
[
40+
`${(imageHeight - 1) / (cropHeight - 1)}`,
41+
'(y2-y1) * height_ratio',
42+
`y1*${inputHeightFloat} + float(y)*(height_scale)`,
43+
] :
44+
[
45+
'0.0',
46+
'0.0',
47+
`0.5 * (y1+y2) * ${inputHeightFloat}`,
48+
];
4949
const [widthRatio, widthScale, inX] = cropWidth > 1 ?
50-
[
51-
`${(imageWidth-1)/(cropWidth-1)}`,
52-
'(x2-x1) * width_ratio',
53-
`x1*${inputWidthFloat} + float(x)*(width_scale)`,
54-
] :
55-
[
56-
'0.0',
57-
'0.0',
58-
`0.5 * (x1+x2) * ${inputWidthFloat}`,
59-
];
50+
[
51+
`${(imageWidth - 1) / (cropWidth - 1)}`,
52+
'(x2-x1) * width_ratio',
53+
`x1*${inputWidthFloat} + float(x)*(width_scale)`,
54+
] :
55+
[
56+
'0.0',
57+
'0.0',
58+
`0.5 * (x1+x2) * ${inputWidthFloat}`,
59+
];
6060

6161
// Reference implementation
6262
// tslint:disable-next-line:max-line-length

src/backends/webgl/fill_gpu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
* =============================================================================
1616
*/
1717

18-
import {GPGPUProgram} from './gpgpu_math';
1918
import {GPGPUContext} from './gpgpu_context';
19+
import {GPGPUProgram} from './gpgpu_math';
2020

2121
export class FillProgram implements GPGPUProgram {
2222
variableNames: string[];

src/backends/webgl/pad_packed_gpu.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
* =============================================================================
1616
*/
1717

18+
import {getChannels} from '../packing_util';
19+
1820
import {GPGPUProgram} from './gpgpu_math';
1921
import {getCoordsDataType} from './shader_compiler';
20-
import {getChannels} from '../packing_util';
2122

2223
export class PadPackedProgram implements GPGPUProgram {
2324
variableNames = ['x'];
@@ -42,20 +43,17 @@ export class PadPackedProgram implements GPGPUProgram {
4243
rank === 1 ? 'source' : `vec2(${source.slice(-2).join()})`;
4344

4445
const componentSetup = [
45-
`${dtype} rc = outputLoc;`,
46-
`${coords[rank - 1]} += 1;
46+
`${dtype} rc = outputLoc;`, `${coords[rank - 1]} += 1;
4747
if(${cLimit}) {
4848
`,
49-
rank === 1 ? '' :
50-
`}
49+
rank === 1 ? '' : `}
5150
rc = outputLoc;
5251
${coords[rank - 2]} += 1;
5352
if(${coords[rank - 2]} < ${this.outputShape[rank - 2]}) {`,
54-
rank === 1 ? '' :
55-
` ${coords[rank - 1]} += 1;
53+
rank === 1 ? '' : ` ${coords[rank - 1]} += 1;
5654
if(${cLimit}) {`
5755
];
58-
56+
5957
const paddingArea = rank === 1 ?
6058
'rc < start || rc >= end' :
6159
'any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))';

src/backends/webgl/slice_packed_gpu.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
* =============================================================================
1616
*/
1717

18+
import {getChannels} from '../packing_util';
19+
1820
import {GPGPUContext} from './gpgpu_context';
1921
import {GPGPUProgram} from './gpgpu_math';
2022
import {getCoordsDataType} from './shader_compiler';
21-
import {getChannels} from '../packing_util';
2223

2324
export class SlicePackedProgram implements GPGPUProgram {
2425
variableNames = ['source'];
@@ -40,7 +41,7 @@ export class SlicePackedProgram implements GPGPUProgram {
4041

4142
const innerDims =
4243
this.rank === 1 ? 'sourceLoc' : `vec2(${sourceLoc.slice(-2).join()})`;
43-
const getChannel =
44+
const getChannel =
4445
`getChannel(getSource(${sourceLoc.join()}), ${innerDims})`;
4546
const upperRow = `
4647
result.x = ${getChannel};

src/backends/webgl/transpose_packed_gpu.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
* =============================================================================
1616
*/
1717

18+
import {getVecChannels} from '../packing_util';
19+
1820
import {GPGPUProgram} from './gpgpu_math';
1921
import {getCoordsDataType} from './shader_compiler';
20-
import { getVecChannels } from '../packing_util';
2122

2223
export class TransposePackedProgram implements GPGPUProgram {
2324
variableNames = ['A'];

src/io/browser_files.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ export class BrowserDownloads implements IOHandler {
6363
}
6464

6565
async save(modelArtifacts: ModelArtifacts): Promise<SaveResult> {
66-
if (typeof(document) === 'undefined') {
67-
throw new Error('Browser downloads are not supported in ' +
66+
if (typeof (document) === 'undefined') {
67+
throw new Error(
68+
'Browser downloads are not supported in ' +
6869
'this environment since `document` is not present');
6970
}
7071
const weightsURL = window.URL.createObjectURL(new Blob(

0 commit comments

Comments
 (0)