import { b as u, c as m, e as l } from "../../webgpu_program-CbjdYLYk.js";
import { f, c as g } from "../../webgpu_util-DuofJBMo.js";
import { a as S, N as k } from "../../index-DSGwv2Yx.js";
import { p as y, a as $ } from "../../slice_util-DPY56GzQ.js";
function x(o) {
  switch (o) {
    case 1:
      return "1D";
    case 2:
      return "2D";
    case 3:
      return "3D";
    case 4:
      return "4D";
  }
  return "";
}
class b {
  variableNames = ["source"];
  uniforms;
  outputShape;
  shaderKey;
  rank;
  dispatchLayout;
  dispatch;
  workPerThread = 1;
  workgroupSize = [64, 1, 1];
  start;
  size = !0;
  constructor(e, t) {
    this.outputShape = t, this.rank = t.length, this.dispatchLayout = f(this.outputShape), this.dispatch = g(this.dispatchLayout, this.outputShape, this.workgroupSize, [
      this.workPerThread,
      1,
      1
    ]), this.start = e, this.uniforms = `start : ${u(e.length)}, `, this.shaderKey = "slice";
  }
  getUserCode() {
    const e = u(this.rank);
    let t;
    return this.start.length === 1 ? t = this.outputShape.map(() => "sourceLoc = uniforms.start + coords;") : t = this.outputShape.map((r, s) => `sourceLoc.${c[s]} = uniforms.start.${m(s)} + coords.${c[s]};`), `
      ${l("index")} {
        if (index < uniforms.size) {
          var sourceLoc : ${e};
          let coords = getCoordsFromIndex(index);
          ${t.join(`
`)}
          result[index] = source[getIndexFromCoords${x(this.rank)}(sourceLoc, uniforms.sourceShape)];
        }
      }
    `;
  }
}
const c = ["x", "y", "z", "w", "u", "v"];
function w(o) {
  const { inputs: e, backend: t, attrs: n } = o, { x: r } = e, { begin: s, size: p } = n, [i, a] = y(r, s, p);
  if ($(r, i, a), k(a) === 0)
    return t.makeTensorInfo(a, r.dtype, []);
  const h = new b(i, a), d = [{ type: "int32", data: i }];
  return t.runWebGPUProgram(h, [r], r.dtype, d);
}
const C = {
  kernelName: "Slice16",
  backendName: "webgpu",
  kernelFunc: w
};
S(C);
export {
  w as slice
};
