import { ReduceProgram as s } from "./utils/reductions.js";
class i extends s {
  hasGamma;
  constructor(a, t, e = !1) {
    super(a, t, { reductionOp: "mean", elementwise: !0 }, !1), this.shaderKey = "RMSNorm32", e && this.variableNames.push("gamma"), this.variableComponents = [1, 1], this.hasGamma = e;
  }
  getPreprocessSnippet() {
    return "candidate = candidate * candidate;";
  }
  getPostprocessSnippet() {
    return "bestValue = inverseSqrt(bestValue + 1e-8);";
  }
  getWriteSnippet() {
    return `
            let X = f32(x[offset + k]);
            ${this.hasGamma ? "let gamma = gamma[k];" : ""}
            let normalized = X * bestValue;
            let outVal = normalized ${this.hasGamma ? " * gamma" : ""};
            result[offset + k] = f32(outVal);
        `;
  }
}
export {
  i as default
};
