MCPcopy Create free account
hub / github.com/tensorflow/tfjs / constructor

Method constructor

tfjs-backend-webgl/src/pad_gpu.ts:27–70  ·  view source on GitHub ↗
(
      xShape: number[], paddings: Array<[number, number]>,
      constantValue: number)

Source from the content-addressed store, hash-verified

25 customUniforms = [{name: 'value', type: 'float' as UniformType}];
26
27 constructor(
28 xShape: number[], paddings: Array<[number, number]>,
29 constantValue: number) {
30 this.outputShape = paddings.map(
31 (p, i) => p[0] /* beforePad */ + xShape[i] + p[1] /* afterPad */);
32 const rank = xShape.length;
33 const type = getCoordsDataType(rank);
34
35 const start = paddings.map(p => p[0]).join(',');
36 const end = paddings.map((p, i) => p[0] + xShape[i]).join(',');
37 const unpackedCoords =
38 ['coords[0]', 'coords[1]', 'coords[2]', 'coords[3]'].slice(0, rank);
39
40 if (rank === 1) {
41 this.userCode = `
42 int start = ${start};
43 int end = ${end};
44
45 void main() {
46 int outC = getOutputCoords();
47 if (outC < start || outC >= end) {
48 setOutput(value);
49 } else {
50 setOutput(getX(outC - start));
51 }
52 }
53 `;
54 return;
55 }
56 this.userCode = `
57 ${type} start = ${type}(${start});
58 ${type} end = ${type}(${end});
59
60 void main() {
61 ${type} outC = getOutputCoords();
62 if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {
63 setOutput(value);
64 } else {
65 ${type} coords = outC - start;
66 setOutput(getX(${unpackedCoords}));
67 }
68 }
69 `;
70 }
71}

Callers

nothing calls this directly

Calls 3

getCoordsDataTypeFunction · 0.90
joinMethod · 0.80
sliceMethod · 0.65

Tested by

no test coverage detected