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

Method constructor

tfjs-backend-webgl/src/segment_gpu.ts:26–161  ·  view source on GitHub ↗
(
      segOpInfo: backend_util.segment_util.SegOpInfo,
      segOpType: 'unsortedSegmentSum')

Source from the content-addressed store, hash-verified

24 userCode: string;
25
26 constructor(
27 segOpInfo: backend_util.segment_util.SegOpInfo,
28 segOpType: 'unsortedSegmentSum') {
29 const windowSize = segOpInfo.windowSize;
30 const batchSize = segOpInfo.batchSize;
31 const inSize = segOpInfo.inSize;
32 const numSegments = segOpInfo.numSegments;
33 const outSize = numSegments * Math.ceil(inSize / windowSize);
34 this.outputShape = [batchSize, outSize];
35
36 const initializationValue = '0.0';
37 const returnValue = `sumValue`;
38
39 const windowSizeNearestVec4 = Math.floor(windowSize / 4) * 4;
40 const windowSizeVec4Remainder = windowSize % 4;
41
42 const updateSnippet = `
43 sumValue += dot(values, segFilter);
44 `;
45
46 let checkValueOutOfBounds = '';
47 if (inSize % windowSize > 0) {
48 checkValueOutOfBounds = `
49 if (inIdx < 0 || inIdx >= ${inSize}) {
50 return initializationValue;
51 }
52 `;
53 }
54
55 let checkSegmentIdOutOfBounds = '';
56 if (inSize % windowSize > 0) {
57 checkSegmentIdOutOfBounds = `
58 if (inIdx < 0 || inIdx >= ${inSize}) {
59 return -1.0;
60 }
61 `;
62 }
63
64 this.userCode = `
65 const float initializationValue = ${initializationValue};
66
67 float getValue(int batch, int inIdx) {
68 ${checkValueOutOfBounds}
69 return getX(batch, inIdx);
70 }
71
72 float getSegmentIdAtIndex(int inIdx) {
73 ${checkSegmentIdOutOfBounds}
74 return getSegmentIds(inIdx);
75 }
76
77 void main() {
78 ivec2 coords = getOutputCoords();
79 int batch = coords[0];
80 int outIdx = coords[1];
81 int inOffset = int(floor(float(outIdx) / float(
82 ${numSegments})) * float(${windowSize}));
83 int currentSeg = int(mod(float(outIdx), float(${numSegments})));

Callers

nothing calls this directly

Calls 2

ceilMethod · 0.80
floorMethod · 0.80

Tested by

no test coverage detected