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

Method constructor

tfjs-backend-webgl/src/mirror_pad_gpu.ts:26–74  ·  view source on GitHub ↗
(
      xShape: number[], paddings: Array<[number, number]>,
      mode: 'reflect'|'symmetric')

Source from the content-addressed store, hash-verified

24 userCode: string;
25
26 constructor(
27 xShape: number[], paddings: Array<[number, number]>,
28 mode: 'reflect'|'symmetric') {
29 this.outputShape = paddings.map(
30 (p, i) => p[0] /* beforePad */ + xShape[i] + p[1] /* afterPad */);
31 const rank = xShape.length;
32 const dtype = getCoordsDataType(rank);
33
34 const start = paddings.map(p => p[0]).join(',');
35 const end = paddings.map((p, i) => p[0] + xShape[i]).join(',');
36 const unpackedCoords =
37 ['coords[0]', 'coords[1]', 'coords[2]', 'coords[3]'].slice(0, rank);
38 const offset = mode === 'reflect' ? 0 : 1;
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) {
48 outC = start * 2 - outC - ${offset};
49 } else if(outC >= end) {
50 outC = (end - 1) * 2 - outC + ${offset};
51 }
52 setOutput(getX(outC - start));
53 }
54 `;
55 return;
56 }
57 this.userCode = `
58 ${dtype} start = ${dtype}(${start});
59 ${dtype} end = ${dtype}(${end});
60
61 void main() {
62 ${dtype} outC = getOutputCoords();
63 for (int i = 0; i < ${rank}; i++) {
64 if (outC[i] < start[i]) {
65 outC[i] = start[i] * 2 - outC[i] - ${offset};
66 } else if(outC[i] >= end[i]) {
67 outC[i] = (end[i] - 1) * 2 - outC[i] + ${offset};
68 }
69 }
70 ${dtype} coords = outC - start;
71 setOutput(getX(${unpackedCoords}));
72 }
73 `;
74 }
75}

Callers

nothing calls this directly

Calls 3

getCoordsDataTypeFunction · 0.90
joinMethod · 0.80
sliceMethod · 0.65

Tested by

no test coverage detected