import { f as c, c as r } from "../../webgpu_util-DuofJBMo.js";
import { e as u } from "../../webgpu_program-CbjdYLYk.js";
import { a as p } from "../../index-DSGwv2Yx.js";
class l {
  outputShape;
  shaderKey = "Unpack16";
  dispatchLayout;
  dispatch;
  workgroupSize = [64, 1, 1];
  variableNames = ["x"];
  size = !0;
  uniforms;
  outputComponent = 4;
  variableComponents = [2];
  scaling = !1;
  constructor(t) {
    this.outputShape = [...t.slice(0, -1), t[t.length - 1] * 2], this.dispatchLayout = c(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize, [4, 1, 1]);
  }
  useScaling() {
    this.shaderKey += "_Scaled", this.uniforms = "scaling : f32,", this.scaling = !0;
  }
  getUserCode() {
    return `
                ${u("index")} {
                    let outIndex = index;
                    if (outIndex < uniforms.size) {
                        let xvec2 = x[index];
                        let v1 = vec4<f32>(
                            unpack2x16float(u32(xvec2.x)),
                            unpack2x16float(u32(xvec2.y))
                        ) ${this.scaling ? "* uniforms.scaling" : ""};
                        result[outIndex] = v1;
                    }
                }`;
  }
}
function h(e) {
  const { x: t } = e.inputs, { scaling: a } = e.attrs, i = e.backend, n = new l(t.shape), s = a !== 1;
  s && n.useScaling();
  const o = [{ type: "float32", data: [1 / a] }];
  return i.runWebGPUProgram(n, [t], "float32", s ? o : void 0);
}
const d = {
  kernelName: "Unpack16",
  backendName: "webgpu",
  kernelFunc: h
};
p(d);
