import { v as _, aE as P, o as A, n as I, E as v, aF as G, aG as J, aH as X, aI as q, aJ as Q, aK as Y } from "./index-DSGwv2Yx.js";
function it(t, n, e, o, s = "NHWC", f) {
  const l = t[3], r = [...n, l], c = nt(s);
  return j(t, r, e, f, o, null, null, c);
}
function ft(t, n, e, o, s, f, l = "channelsLast") {
  const [r, c] = T(n);
  let u;
  if (l === "channelsLast")
    u = [r, c, t[3], t[3]];
  else if (l === "channelsFirst")
    u = [r, c, t[1], t[1]];
  else
    throw new Error(`Unknown dataFormat ${l}`);
  return j(t, u, e, o, s, f, !1, l);
}
function ht(t, n, e, o, s, f, l = "NDHWC") {
  const [r, c, u] = K(n);
  let h, i;
  if (l === "NDHWC")
    i = "channelsLast", h = [r, c, u, t[4], t[4]];
  else if (l === "NCDHW")
    i = "channelsFirst", h = [r, c, u, t[1], t[1]];
  else
    throw new Error(`Unknown dataFormat ${l}`);
  return Z(t, h, e, o, s, !1, i, f);
}
function j(t, n, e, o, s, f, l = !1, r = "channelsLast") {
  let [c, u, h, i] = [-1, -1, -1, -1];
  if (r === "channelsLast")
    [c, u, h, i] = t;
  else if (r === "channelsFirst")
    [c, i, u, h] = t;
  else
    throw new Error(`Unknown dataFormat ${r}`);
  const [a, p, , $] = n, [w, g] = T(e), [x, y] = T(o), C = k(a, x), b = k(p, y), { padInfo: L, outHeight: E, outWidth: D } = d(s, u, h, w, g, C, b, f, r), M = l ? $ * i : $;
  let m;
  return r === "channelsFirst" ? m = [c, M, E, D] : r === "channelsLast" && (m = [c, E, D, M]), {
    batchSize: c,
    dataFormat: r,
    inHeight: u,
    inWidth: h,
    inChannels: i,
    outHeight: E,
    outWidth: D,
    outChannels: M,
    padInfo: L,
    strideHeight: w,
    strideWidth: g,
    filterHeight: a,
    filterWidth: p,
    effectiveFilterHeight: C,
    effectiveFilterWidth: b,
    dilationHeight: x,
    dilationWidth: y,
    inShape: t,
    outShape: m,
    filterShape: n
  };
}
function Z(t, n, e, o, s, f = !1, l = "channelsLast", r) {
  let [c, u, h, i, a] = [-1, -1, -1, -1, -1];
  if (l === "channelsLast")
    [c, u, h, i, a] = t;
  else if (l === "channelsFirst")
    [c, a, u, h, i] = t;
  else
    throw new Error(`Unknown dataFormat ${l}`);
  const [p, $, w, , g] = n, [x, y, C] = K(e), [b, L, E] = K(o), D = k(p, b), M = k($, L), m = k(w, E), { padInfo: F, outDepth: N, outHeight: R, outWidth: W } = tt(s, u, h, i, x, y, C, D, M, m, r), H = f ? g * a : g;
  let O;
  return l === "channelsFirst" ? O = [c, H, N, R, W] : l === "channelsLast" && (O = [c, N, R, W, H]), {
    batchSize: c,
    dataFormat: l,
    inDepth: u,
    inHeight: h,
    inWidth: i,
    inChannels: a,
    outDepth: N,
    outHeight: R,
    outWidth: W,
    outChannels: H,
    padInfo: F,
    strideDepth: x,
    strideHeight: y,
    strideWidth: C,
    filterDepth: p,
    filterHeight: $,
    filterWidth: w,
    effectiveFilterDepth: D,
    effectiveFilterHeight: M,
    effectiveFilterWidth: m,
    dilationDepth: b,
    dilationHeight: L,
    dilationWidth: E,
    inShape: t,
    outShape: O,
    filterShape: n
  };
}
function z(t, n, e, o, s) {
  o == null && (o = B(t, n, e));
  const f = t[0], l = t[1], r = U((f - n + 2 * o) / e + 1, s), c = U((l - n + 2 * o) / e + 1, s);
  return [r, c];
}
function S(t, n, e, o, s, f) {
  s == null && (s = B(t, n[0], o[0]));
  const l = [0, 0, 0, e];
  for (let r = 0; r < 3; r++)
    t[r] + 2 * s >= n[r] && (l[r] = U((t[r] - n[r] + 2 * s) / o[r] + 1, f));
  return l;
}
function B(t, n, e, o = 1) {
  const s = k(n, o);
  return Math.floor((t[0] * (e - 1) - e + s) / 2);
}
function T(t) {
  return typeof t == "number" ? [t, t, t] : t.length === 2 ? [t[0], t[1], 1] : t;
}
function K(t) {
  return typeof t == "number" ? [t, t, t] : t;
}
function k(t, n) {
  return n <= 1 ? t : t + (t - 1) * (n - 1);
}
function d(t, n, e, o, s, f, l, r, c) {
  let u, h, i;
  if (typeof t == "number") {
    u = { top: t, bottom: t, left: t, right: t, type: t === 0 ? "VALID" : "NUMBER" };
    const p = z([n, e], f, o, t, r);
    h = p[0], i = p[1];
  } else if (t === "same") {
    h = Math.ceil(n / o), i = Math.ceil(e / s);
    const a = Math.max(0, (h - 1) * o + f - n), p = Math.max(0, (i - 1) * s + l - e), $ = Math.floor(a / 2), w = a - $, g = Math.floor(p / 2), x = p - g;
    u = { top: $, bottom: w, left: g, right: x, type: "SAME" };
  } else if (t === "valid")
    u = { top: 0, bottom: 0, left: 0, right: 0, type: "VALID" }, h = Math.ceil((n - f + 1) / o), i = Math.ceil((e - l + 1) / s);
  else if (typeof t == "object") {
    const a = c === "channelsLast" ? t[1][0] : t[2][0], p = c === "channelsLast" ? t[1][1] : t[2][1], $ = c === "channelsLast" ? t[2][0] : t[3][0], w = c === "channelsLast" ? t[2][1] : t[3][1];
    u = { top: a, bottom: p, left: $, right: w, type: a === 0 && p === 0 && $ === 0 && w === 0 ? "VALID" : "EXPLICIT" }, h = U((n - f + a + p) / o + 1, r), i = U((e - l + $ + w) / s + 1, r);
  } else
    throw Error(`Unknown padding parameter: ${t}`);
  return { padInfo: u, outHeight: h, outWidth: i };
}
function tt(t, n, e, o, s, f, l, r, c, u, h) {
  let i, a, p, $;
  if (t === "valid" && (t = 0), typeof t == "number") {
    i = {
      top: t,
      bottom: t,
      left: t,
      right: t,
      front: t,
      back: t,
      type: t === 0 ? "VALID" : "NUMBER"
    };
    const g = S([n, e, o, 1], [r, c, u], 1, [s, f, l], t, h);
    a = g[0], p = g[1], $ = g[2];
  } else if (t === "same") {
    a = Math.ceil(n / s), p = Math.ceil(e / f), $ = Math.ceil(o / l);
    const w = (a - 1) * s + r - n, g = (p - 1) * f + c - e, x = ($ - 1) * l + u - o, y = Math.floor(w / 2), C = w - y, b = Math.floor(g / 2), L = g - b, E = Math.floor(x / 2), D = x - E;
    i = { top: b, bottom: L, left: E, right: D, front: y, back: C, type: "SAME" };
  } else
    throw Error(`Unknown padding parameter: ${t}`);
  return { padInfo: i, outDepth: a, outHeight: p, outWidth: $ };
}
function U(t, n) {
  if (!n)
    return Math.trunc(t);
  switch (n) {
    case "round":
      return Math.round(t);
    case "ceil":
      return Math.ceil(t);
    case "floor":
      return Math.floor(t);
    default:
      throw new Error(`Unknown roundingMode ${n}`);
  }
}
function V(t) {
  const [n, e, o] = T(t);
  return n === 1 && e === 1 && o === 1;
}
function at(t, n) {
  return V(t) || V(n);
}
function pt(t) {
  return T(t).every((n) => n > 0);
}
function nt(t) {
  if (t === "NHWC")
    return "channelsLast";
  if (t === "NCHW")
    return "channelsFirst";
  throw new Error(`Unknown dataFormat ${t}`);
}
function $t(t, n, e) {
  if (e != null) {
    if (typeof n == "string")
      throw Error(`Error in ${t}: pad must be an integer when using dimRoundingMode ${e} but got pad ${n}.`);
    if (typeof n == "number")
      _(P(n), () => `Error in ${t}: pad must be an integer when using dimRoundingMode ${e} but got pad ${n}.`);
    else if (typeof n == "object")
      n.forEach((o) => {
        o.forEach((s) => {
          _(P(s), () => `Error in ${t}: pad must be an integer when using dimRoundingMode ${e} but got pad ${s}.`);
        });
      });
    else
      throw Error(`Error in ${t}: Unknown padding parameter: ${n}`);
  }
}
function et(t) {
  const e = { x: I(t, "x", "sigmoid", "float32") };
  return v.runKernel(G, e);
}
const gt = /* @__PURE__ */ A({ sigmoid_: et });
function ot(t) {
  const e = { x: I(t, "x", "elu", "float32") };
  return v.runKernel(J, e);
}
const wt = /* @__PURE__ */ A({ elu_: ot });
function st(t, n = 0.2) {
  const o = { x: I(t, "x", "leakyRelu") }, s = { alpha: n };
  return v.runKernel(X, o, s);
}
const xt = /* @__PURE__ */ A({ leakyRelu_: st });
function rt(t, n) {
  const e = I(t, "x", "prelu"), o = I(n, "alpha", "prelu"), s = { x: e, alpha: o };
  return v.runKernel(q, s);
}
const Et = /* @__PURE__ */ A({ prelu_: rt });
function lt(t) {
  const e = { x: I(t, "x", "relu6") };
  return v.runKernel(Q, e);
}
const yt = /* @__PURE__ */ A({ relu6_: lt });
function ct(t, n = 0) {
  const o = { x: I(t, "x", "step") }, s = { alpha: n };
  return v.runKernel(Y, o, s);
}
const bt = /* @__PURE__ */ A({ step_: ct });
export {
  bt as a,
  j as b,
  $t as c,
  Z as d,
  wt as e,
  B as f,
  it as g,
  ft as h,
  ht as i,
  nt as j,
  at as k,
  xt as l,
  pt as m,
  Et as p,
  yt as r,
  gt as s,
  V as t
};
