import { a as m } from "../../index-DSGwv2Yx.js";
class f {
  variableNames = ["a", "b"];
  outputShape;
  userCode;
  customUniforms = [
    { name: "dropoutRate", type: "float" },
    { name: "seed", type: "float" }
  ];
  constructor(t, r, o) {
    this.outputShape = [t, r, o, o], this.userCode = `
        float random(ivec4 coords) {
            float x = float(coords.x * 4096 + coords.y * 256 + coords.z * 16 + coords.w);
            return fract(sin(seed + x) * 43758.5453123);
        }
        void main() {
            ivec4 coords = getOutputCoords();
            float a = getA(coords.x, coords.y, coords.z, coords.w);
            float b = getB(coords.x, coords.y, coords.z, coords.w);
            
            float keepProb = 1.0 - dropoutRate;
            float rand = random(coords);
            float mask = step(rand, keepProb);
            setOutput(a * b * mask / keepProb);
        }
        `;
  }
}
function b(e) {
  const { inputs: t, attrs: r } = e, { a: o, b: s } = t, { dropoutRate: a, seed: c } = r, n = e.backend, d = o.shape[0], u = o.shape[2], p = o.shape[1], l = new f(d, p, u);
  return n.runWebGLProgram(l, [o, s], "float32", [
    [a ?? 0],
    [c ?? Math.random() * 1e4]
  ]);
}
const i = {
  kernelName: "MulDropout",
  backendName: "webgl",
  kernelFunc: b
};
m(i);
