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

Method constructor

tfjs-backend-webgl/src/multinomial_gpu.ts:27–51  ·  view source on GitHub ↗
(batchSize: number, numOutcomes: number, numSamples: number)

Source from the content-addressed store, hash-verified

25 customUniforms = [{name: 'seed', type: 'float' as UniformType}];
26
27 constructor(batchSize: number, numOutcomes: number, numSamples: number) {
28 this.outputShape = [batchSize, numSamples];
29
30 this.userCode = `
31 void main() {
32 ivec2 coords = getOutputCoords();
33 int batch = coords[0];
34
35 float r = random(seed);
36 float cdf = 0.0;
37
38 for (int i = 0; i < ${numOutcomes - 1}; i++) {
39 cdf += getProbs(batch, i);
40
41 if (r < cdf) {
42 setOutput(float(i));
43 return;
44 }
45 }
46
47 // If no other event happened, last event happened.
48 setOutput(float(${numOutcomes - 1}));
49 }
50 `;
51 }
52}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected