import { isPackedTensor as d } from "../../utilities/packed.js";
import { a as k, e as l } from "../../index-DSGwv2Yx.js";
import { reshape16 as u } from "../reshape16.js";
import P from "./transpose16_shared_program.js";
import b from "./transpose16_program.js";
import { t as T } from "../../transpose-Qxz-4os3.js";
function w(a) {
  const { inputs: h, attrs: i } = a, { x: e } = h, { perm: r } = i, p = a.backend, m = d(e);
  if (m && r[r.length - 1] !== e.shape.length - 1) {
    const o = e.shape.length, c = o === 4 ? r.map((s) => s - 1).filter((s) => s >= 0) : r, t = o === 4 ? u(e, [e.shape[0] * e.shape[1], e.shape[2], e.shape[3]]) : e, f = new P(t.shape, c), n = p.runWebGPUProgram(f, [t], "packedF16");
    if (o === 4) {
      t.dispose();
      const s = l().makeTensorFromTensorInfo(n), g = u(s, [
        e.shape[0],
        e.shape[1],
        n.shape[1],
        n.shape[2]
      ]);
      return s.dispose(), g;
    }
    return n;
  }
  if (m) {
    const o = new b(e.shape, r);
    return p.runWebGPUProgram(o, [e], "packedF16");
  } else
    return T(e, r);
}
const F = {
  kernelName: "Transpose16",
  backendName: "webgpu",
  kernelFunc: w
};
k(F);
