(batchSize: number, numOutcomes: number, numSamples: number)
| 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected