import { o as d, n as u, v as p, E as k, bd as hs, be as ds, a5 as bs, bf as gs, bg as Es, J as W, bh as $s, bi as ys, bj as _s, bk as Ns, b as $, m as h, h as G, d as S, f as Ss, a1 as b, bl as ks, u as K, l as Is, a6 as L, a_ as ns, j as Ts, a2 as Ms } from "./index-DSGwv2Yx.js";
import { t as j } from "./tile-CsWlVKKz.js";
import { e as R } from "./expand_dims-D0rBtgT1.js";
import { t as x } from "./tensor1d-BMl0eZYV.js";
import { n as xs, a as As, b as ws } from "./non_max_suppression_impl-B2W7YjZB.js";
import { r as Os, l as ls, g as es, a as rs, m as Q, b as Gs, c as Ls, u as us, n as ps, s as Bs, d as Ds, e as Ws, f as Rs } from "./resize_nearest_neighbor-C6_0dAnK.js";
import { s as ms } from "./split-BN9LkEgS.js";
import { s as _ } from "./sum-D39FeU5h.js";
import { w as q, a as qs, n as zs, b as as, e as ss, l as Vs } from "./not_equal-CkQKkKZy.js";
import { s as T } from "./slice-BvItlgXu.js";
import { r as F } from "./range-BDxO73mk.js";
import { t as Cs } from "./tensor-D8e0Gd7c.js";
import { n as C, t as is } from "./transpose-Qxz-4os3.js";
import { r as O } from "./reshape-BIN71H3p.js";
import { s as U } from "./stack-z6QE7kmP.js";
import { z as vs } from "./zeros-Bw0puq_w.js";
import { s as Ps } from "./squeeze-O_YWJpw_.js";
import { c as J } from "./concat-Dqk7Xk7h.js";
import { m as w } from "./mat_mul-DP86qZtZ.js";
import { t as X } from "./tensor2d-DTtQ1QcT.js";
import { o as Ys } from "./ones-DbVB5N58.js";
import { r as fs } from "./relu-DTvZKBsZ.js";
import { e as js } from "./axis_util-QWWgLjut.js";
function Fs(t, a, n) {
  const r = u(t, "x", "bincount"), e = u(a, "weights", "bincount");
  p(r.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${r.dtype}`), p(n >= 0, () => `size must be non-negative, but got ${n}.`), p(e.size === r.size || e.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${r.shape}, weights shape: ${e.shape}.`);
  const s = { x: r, weights: e }, o = { size: n };
  return k.runKernel(hs, s, o);
}
const Us = /* @__PURE__ */ d({ bincount_: Fs });
function Zs(t, ...a) {
  const n = a.map((e, s) => u(e, `tensors${s}`, "einsum")), r = { equation: t };
  return k.runKernel(ds, n, r);
}
const V = /* @__PURE__ */ d({ einsum_: Zs });
function Hs(t, a, n, r = "float32") {
  a == null && (a = t);
  const e = bs([t, a], r), s = t <= a ? t : a;
  for (let i = 0; i < s; ++i)
    e.set(1, i, i);
  const o = O(e.toTensor(), [t, a]);
  if (n == null)
    return o;
  if (n.length === 1)
    return j(R(o, 0), [n[0], 1, 1]);
  if (n.length === 2)
    return j(R(R(o, 0), 0), [n[0], n[1], 1, 1]);
  if (n.length === 3)
    return j(R(R(R(o, 0), 0), 0), [
      n[0],
      n[1],
      n[2],
      1,
      1
    ]);
  throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${n.length}D.`);
}
const Ks = /* @__PURE__ */ d({ eye_: Hs });
function Js(t, a, n, r, e = "bilinear", s = 0) {
  const o = u(t, "image", "cropAndResize"), i = u(a, "boxes", "cropAndResize", "float32"), l = u(n, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
  p(o.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${o.rank}.`), p(i.rank === 2 && i.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${c},4] but had shape ${i.shape}.`), p(l.rank === 1 && l.shape[0] === c, () => `Error in cropAndResize: boxInd must be have size [${c}] but had shape ${i.shape}.`), p(r.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${r.length}.`), p(r[0] >= 1 && r[1] >= 1, () => `cropSize must be atleast [1,1], but was ${r}`), p(e === "bilinear" || e === "nearest", () => `method must be bilinear or nearest, but was ${e}`);
  const f = { image: o, boxes: i, boxInd: l }, m = { method: e, extrapolationValue: s, cropSize: r };
  return k.runKernel(gs, f, m);
}
const Xs = /* @__PURE__ */ d({ cropAndResize_: Js });
function Qs(t) {
  const a = u(t, "image", "flipLeftRight", "float32");
  p(a.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${a.rank}.`);
  const n = { image: a };
  return k.runKernel(Es, n, {});
}
const sn = /* @__PURE__ */ d({ flipLeftRight_: Qs });
function nn(t) {
  const a = u(t, "image", "grayscaleToRGB"), n = a.rank - 1, r = a.shape[n];
  p(a.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${a.rank}.`), p(r === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${r}.`);
  const e = new Array(a.rank);
  return e.fill(1, 0, n), e[n] = 3, j(a, e);
}
const en = /* @__PURE__ */ d({ grayscaleToRGB_: nn });
function tn(t) {
  const a = u(t, "image", "RGBToGrayscale"), n = a.rank - 1, r = a.shape[n];
  p(a.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${a.rank}.`), p(r === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${r}.`);
  const e = a.dtype, s = W(a, "float32"), o = x([0.2989, 0.587, 0.114]);
  let i;
  switch (a.rank) {
    case 2:
      i = V("ij,j->i", s, o);
      break;
    case 3:
      i = V("ijk,k->ij", s, o);
      break;
    case 4:
      i = V("ijkl,l->ijk", s, o);
      break;
    case 5:
      i = V("ijklm,m->ijkl", s, o);
      break;
    case 6:
      i = V("ijklmn,n->ijklm", s, o);
      break;
    default:
      throw new Error("Not a valid tensor rank.");
  }
  return i = R(i, -1), W(i, e);
}
const on = /* @__PURE__ */ d({ rgbToGrayscale_: tn });
function rn(t, a, n = 0, r = 0.5) {
  const e = u(t, "image", "rotateWithOffset", "float32");
  p(e.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${e.rank}.`);
  const s = { image: e }, o = { radians: a, fillValue: n, center: r };
  return k.runKernel($s, s, o);
}
const an = /* @__PURE__ */ d({ rotateWithOffset_: rn });
function z(t, a, n, r, e, s) {
  r == null && (r = 0.5), e == null && (e = Number.NEGATIVE_INFINITY), s == null && (s = 0);
  const o = t.shape[0];
  return n = Math.min(n, o), p(0 <= r && r <= 1, () => `iouThreshold must be in [0, 1], but was '${r}'`), p(t.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${t.rank}'`), p(t.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${t.shape[1]}`), p(a.rank === 1, () => "scores must be a 1D tensor"), p(a.shape[0] === o, () => `scores has incompatible shape with boxes. Expected ${o}, but was ${a.shape[0]}`), p(0 <= s && s <= 1, () => `softNmsSigma must be in [0, 1], but was '${s}'`), { maxOutputSize: n, iouThreshold: r, scoreThreshold: e, softNmsSigma: s };
}
function cn(t, a, n, r = 0.5, e = Number.NEGATIVE_INFINITY) {
  const s = u(t, "boxes", "nonMaxSuppression", "float32"), o = u(a, "scores", "nonMaxSuppression", "float32"), i = z(s, o, n, r, e);
  n = i.maxOutputSize, r = i.iouThreshold, e = i.scoreThreshold;
  const l = { maxOutputSize: n, iouThreshold: r, scoreThreshold: e };
  return k.runKernel(ys, { boxes: s, scores: o }, l);
}
const ln = /* @__PURE__ */ d({ nonMaxSuppression_: cn });
async function un(t, a, n, r = 0.5, e = Number.NEGATIVE_INFINITY) {
  const s = u(t, "boxes", "nonMaxSuppressionAsync"), o = u(a, "scores", "nonMaxSuppressionAsync"), i = z(s, o, n, r, e);
  n = i.maxOutputSize, r = i.iouThreshold, e = i.scoreThreshold;
  const l = await Promise.all([s.data(), o.data()]), c = l[0], f = l[1], { selectedIndices: m } = xs(c, f, n, r, e);
  return s !== t && s.dispose(), o !== a && o.dispose(), x(m, "int32");
}
const pn = un;
function mn(t, a, n, r = 0.5, e = Number.NEGATIVE_INFINITY, s = 0) {
  const o = u(t, "boxes", "nonMaxSuppression"), i = u(a, "scores", "nonMaxSuppression"), l = z(o, i, n, r, e, s);
  n = l.maxOutputSize, r = l.iouThreshold, e = l.scoreThreshold, s = l.softNmsSigma;
  const c = { boxes: o, scores: i }, f = { maxOutputSize: n, iouThreshold: r, scoreThreshold: e, softNmsSigma: s }, m = k.runKernel(_s, c, f);
  return { selectedIndices: m[0], selectedScores: m[1] };
}
const fn = /* @__PURE__ */ d({ nonMaxSuppressionWithScore_: mn });
async function hn(t, a, n, r = 0.5, e = Number.NEGATIVE_INFINITY, s = 0) {
  const o = u(t, "boxes", "nonMaxSuppressionAsync"), i = u(a, "scores", "nonMaxSuppressionAsync"), l = z(o, i, n, r, e, s);
  n = l.maxOutputSize, r = l.iouThreshold, e = l.scoreThreshold, s = l.softNmsSigma;
  const c = await Promise.all([o.data(), i.data()]), f = c[0], m = c[1], { selectedIndices: E, selectedScores: g } = As(f, m, n, r, e, s);
  return o !== t && o.dispose(), i !== a && i.dispose(), {
    selectedIndices: x(E, "int32"),
    selectedScores: x(g)
  };
}
const dn = hn;
function bn(t, a, n, r = 0.5, e = Number.NEGATIVE_INFINITY, s = !1) {
  const o = u(t, "boxes", "nonMaxSuppression"), i = u(a, "scores", "nonMaxSuppression"), l = z(
    o,
    i,
    n,
    r,
    e,
    null
    /* softNmsSigma */
  ), c = l.maxOutputSize, f = l.iouThreshold, m = l.scoreThreshold, E = { boxes: o, scores: i }, g = {
    maxOutputSize: c,
    iouThreshold: f,
    scoreThreshold: m,
    padToMaxOutputSize: s
  }, y = k.runKernel(Ns, E, g);
  return { selectedIndices: y[0], validOutputs: y[1] };
}
const gn = /* @__PURE__ */ d({ nonMaxSuppressionPadded_: bn });
async function En(t, a, n, r = 0.5, e = Number.NEGATIVE_INFINITY, s = !1) {
  const o = u(t, "boxes", "nonMaxSuppressionAsync"), i = u(a, "scores", "nonMaxSuppressionAsync"), l = z(
    o,
    i,
    n,
    r,
    e,
    null
    /* softNmsSigma */
  ), c = l.maxOutputSize, f = l.iouThreshold, m = l.scoreThreshold, [E, g] = await Promise.all([o.data(), i.data()]), { selectedIndices: y, validOutputs: M } = ws(E, g, c, f, m, s);
  return o !== t && o.dispose(), i !== a && i.dispose(), {
    selectedIndices: x(y, "int32"),
    validOutputs: $(M, "int32")
  };
}
const $n = En;
function yn(t, a = "binary", n = !1, r = 0.5) {
  const e = u(t, "image", "threshold"), s = 0.2989, o = 0.587, i = 0.114, l = e.shape[0] * e.shape[1];
  let c = h(x([r]), 255), f, m, E, g;
  if (p(e.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${e.rank}.`), p(e.shape[2] === 3 || e.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${e.shape[2]}.`), p(e.dtype === "int32" || e.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${e.dtype}.`), p(a === "otsu" || a === "binary", () => `Method must be binary or otsu, but was ${a}`), e.shape[2] === 3) {
    [f, m, E] = ms(e, [1, 1, 1], -1);
    const I = h(f, s), A = h(m, o), D = h(E, i);
    g = G(G(I, A), D);
  } else
    g = t;
  if (a === "otsu") {
    const I = Us(W(Os(g), "int32"), Cs([]), 256);
    c = _n(I, l);
  }
  const y = n ? ls(g, c) : es(g, c);
  return W(h(y, 255), "int32");
}
function _n(t, a) {
  let n = x([-1]), r = x([0]), e = x([0]), s, o, i, l, c, f;
  for (let m = 0; m < t.size - 1; m++) {
    s = T(t, 0, m + 1), o = T(t, m + 1), c = S(_(s), a), f = S(_(o), a);
    const E = _(h(s, F(0, s.size)));
    i = S(E, _(s));
    const g = Ss(o.shape, s.size), y = G(F(0, o.size), g), M = h(o, y);
    l = S(_(M), _(o));
    const I = b(i, l), A = b(i, l), D = h(c, f);
    e = h(h(D, I), A);
    const v = es(e, r);
    r = q(v, e, r), n = q(v, x([m]), n);
  }
  return n;
}
const Nn = /* @__PURE__ */ d({ threshold_: yn });
function Sn(t, a, n = "nearest", r = "constant", e = 0, s) {
  const o = u(t, "image", "transform", "float32"), i = u(a, "transforms", "transform", "float32");
  p(o.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${o.rank}.`), p(i.rank === 2 && (i.shape[0] === o.shape[0] || i.shape[0] === 1) && i.shape[1] === 8, () => "Error in transform: Input transform should be batch x 8 or 1 x 8"), p(s == null || s.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${s}.`);
  const l = { image: o, transforms: i }, c = { interpolation: n, fillMode: r, fillValue: e, outputShape: s };
  return k.runKernel(ks, l, c);
}
const kn = /* @__PURE__ */ d({ transform_: Sn });
function In(t, a, n) {
  const r = u(t, "a", "bandPart");
  p(r.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${r.rank}.`);
  const e = r.shape, [s, o] = r.shape.slice(-2);
  let i, l;
  typeof a == "number" ? (p(a % 1 === 0, () => `bandPart(): numLower must be an integer, got ${a}.`), p(a <= s, () => `bandPart(): numLower (${a}) must not be greater than the number of rows (${s}).`), i = u(a < 0 ? s : a, "numLower", "bandPart")) : (p(a.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = q(rs(a, 0), s, Q(a, s))), typeof n == "number" ? (p(n % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${n}.`), p(n <= o, () => `bandPart(): numUpper (${n}) must not be greater than the number of columns (${o}).`), l = u(n < 0 ? o : n, "numUpper", "bandPart")) : (p(n.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), l = q(rs(n, 0), o, Q(n, o)));
  const c = O(F(0, s, 1, "int32"), [-1, 1]), f = F(0, o, 1, "int32"), m = b(c, f), E = Gs(ls(m, i), Ls(m, C(l))), g = vs([s, o], r.dtype);
  return O(U(us(O(r, [-1, s, o])).map((y) => q(E, y, g))), e);
}
const Tn = /* @__PURE__ */ d({ bandPart_: In });
function Mn(t) {
  let a;
  if (Array.isArray(t)) {
    a = !1, p(t != null && t.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
    const e = t[0].shape[0];
    for (let s = 1; s < t.length; ++s)
      p(t[s].shape[0] === e, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${t[s].shape[0]} vs. ${e})`);
  } else
    a = !0, t = ms(t, t.shape[0], 0).map((e) => Ps(e, [0]));
  p(t.length <= t[0].shape[0], () => `Gram-Schmidt: Number of vectors (${t.length}) exceeds number of dimensions (${t[0].shape[0]}).`);
  const n = [], r = t;
  for (let e = 0; e < t.length; ++e)
    n.push(k.tidy(() => {
      let s = r[e];
      if (e > 0)
        for (let o = 0; o < e; ++o) {
          const i = h(_(h(n[o], s)), n[o]);
          s = b(s, i);
        }
      return S(s, ps(s, "euclidean"));
    }));
  return a ? U(n, 0) : n;
}
const xn = /* @__PURE__ */ d({ gramSchmidt_: Mn });
function An(t, a = !1) {
  if (p(t.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${t.rank}`), t.rank === 2)
    return cs(t, a);
  {
    const n = t.shape.slice(0, t.shape.length - 2).reduce((l, c) => l * c), r = us(O(t, [
      n,
      t.shape[t.shape.length - 2],
      t.shape[t.shape.length - 1]
    ]), 0), e = [], s = [];
    r.forEach((l) => {
      const [c, f] = cs(l, a);
      e.push(c), s.push(f);
    });
    const o = O(U(e, 0), t.shape), i = O(U(s, 0), t.shape);
    return [o, i];
  }
}
function cs(t, a = !1) {
  return k.tidy(() => {
    p(t.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${t.shape.length}D Tensor.`);
    const n = t.shape[0], r = t.shape[1];
    let e = Ks(n), s = K(t);
    const o = X([[1]], [1, 1]);
    let i = K(o);
    const l = n >= r ? r : n;
    for (let c = 0; c < l; ++c) {
      const f = s, m = i, E = e;
      [i, s, e] = k.tidy(() => {
        const g = T(s, [c, c], [n - c, 1]), y = ps(g), M = T(s, [c, c], [1, 1]), I = q(es(M, 0), X([[-1]]), X([[1]])), A = b(M, h(I, y)), D = S(g, A);
        D.shape[0] === 1 ? i = K(o) : i = J([
          o,
          T(D, [1, 0], [D.shape[0] - 1, D.shape[1]])
        ], 0);
        const v = C(S(w(I, A), y)), P = T(s, [c, 0], [n - c, r]), Z = h(v, i), ts = is(i);
        if (c === 0)
          s = b(P, w(Z, w(ts, P)));
        else {
          const H = b(P, w(Z, w(ts, P)));
          s = J([T(s, [0, 0], [c, r]), H], 0);
        }
        const os = is(Z), Y = T(e, [0, c], [n, e.shape[1] - c]);
        if (c === 0)
          e = b(Y, w(w(Y, i), os));
        else {
          const H = b(Y, w(w(Y, i), os));
          e = J([T(e, [0, 0], [n, c]), H], 1);
        }
        return [i, s, e];
      }), Is([f, m, E]);
    }
    return !a && n > r && (e = T(e, [0, 0], [n, r]), s = T(s, [0, 0], [r, r])), [e, s];
  });
}
const wn = /* @__PURE__ */ d({ qr_: An });
var N;
(function(t) {
  t[t.NONE = 0] = "NONE", t[t.MEAN = 1] = "MEAN", t[t.SUM = 2] = "SUM", t[t.SUM_BY_NONZERO_WEIGHTS = 3] = "SUM_BY_NONZERO_WEIGHTS";
})(N || (N = {}));
function On(t, a, n = N.SUM_BY_NONZERO_WEIGHTS) {
  const r = u(t, "losses", "computeWeightedLoss");
  let e = null;
  a != null && (e = u(a, "weights", "computeWeightedLoss"));
  const s = e == null ? r : h(r, e);
  if (n === N.NONE)
    return s;
  if (n === N.SUM)
    return _(s);
  if (n === N.MEAN) {
    if (e == null)
      return qs(s);
    {
      const o = r.size / e.size, i = S(_(s), _(e));
      return o > 1 ? S(i, $(o)) : i;
    }
  }
  if (n === N.SUM_BY_NONZERO_WEIGHTS) {
    if (e == null)
      return S(_(s), $(r.size));
    {
      const o = h(e, Ys(r.shape)), i = W(_(zs(o, $(0))), "float32");
      return S(_(s), i);
    }
  }
  throw Error(`Unknown reduction: ${n}`);
}
const B = /* @__PURE__ */ d({ computeWeightedLoss_: On });
function Gn(t, a, n, r = N.SUM_BY_NONZERO_WEIGHTS) {
  const e = u(t, "labels", "absoluteDifference"), s = u(a, "predictions", "absoluteDifference");
  let o = null;
  n != null && (o = u(n, "weights", "absoluteDifference")), L(e.shape, s.shape, "Error in absoluteDifference: ");
  const i = ns(b(e, s));
  return B(i, o, r);
}
const Ln = /* @__PURE__ */ d({ absoluteDifference_: Gn });
function Bn(t, a, n, r, e = N.SUM_BY_NONZERO_WEIGHTS) {
  const s = u(t, "labels", "cosineDistance"), o = u(a, "predictions", "cosineDistance");
  let i = null;
  r != null && (i = u(r, "weights", "cosineDistance")), L(s.shape, o.shape, "Error in cosineDistance: ");
  const l = $(1), c = b(l, _(h(s, o), n, !0));
  return B(c, i, e);
}
const Dn = /* @__PURE__ */ d({ cosineDistance_: Bn });
function Wn(t, a, n, r = N.SUM_BY_NONZERO_WEIGHTS) {
  let e = u(t, "labels", "hingeLoss");
  const s = u(a, "predictions", "hingeLoss");
  let o = null;
  n != null && (o = u(n, "weights", "hingeLoss")), L(e.shape, s.shape, "Error in hingeLoss: ");
  const i = $(1);
  e = b(h($(2), e), i);
  const l = fs(b(i, h(e, s)));
  return B(l, o, r);
}
const Rn = /* @__PURE__ */ d({ hingeLoss_: Wn });
function qn(t, a, n, r = 1, e = N.SUM_BY_NONZERO_WEIGHTS) {
  const s = u(t, "labels", "huberLoss"), o = u(a, "predictions", "huberLoss");
  let i = null;
  n != null && (i = u(n, "weights", "huberLoss")), L(s.shape, o.shape, "Error in huberLoss: ");
  const l = $(r), c = ns(b(o, s)), f = Q(c, l), m = b(c, f), E = G(h($(0.5), Ts(f)), h(l, m));
  return B(E, i, e);
}
const zn = /* @__PURE__ */ d({ huberLoss_: qn });
function Vn(t, a, n, r = 1e-7, e = N.SUM_BY_NONZERO_WEIGHTS) {
  const s = u(t, "labels", "logLoss"), o = u(a, "predictions", "logLoss");
  let i = null;
  n != null && (i = u(n, "weights", "logLoss")), L(s.shape, o.shape, "Error in logLoss: ");
  const l = $(1), c = $(r), f = C(h(s, as(G(o, c)))), m = h(b(l, s), as(G(b(l, o), c))), E = b(f, m);
  return B(E, i, e);
}
const Cn = /* @__PURE__ */ d({ logLoss_: Vn });
function vn(t, a, n, r = N.SUM_BY_NONZERO_WEIGHTS) {
  const e = u(t, "labels", "meanSquaredError"), s = u(a, "predictions", "meanSquaredError");
  let o = null;
  n != null && (o = u(n, "weights", "meanSquaredError")), L(e.shape, s.shape, "Error in meanSquaredError: ");
  const i = Bs(e, s);
  return B(i, o, r);
}
const Pn = /* @__PURE__ */ d({ meanSquaredError_: vn });
function Yn(t, a) {
  const n = u(t, "labels", "sigmoidCrossEntropyWithLogits"), r = u(a, "logits", "sigmoidCrossEntropyWithLogits");
  L(n.shape, r.shape, "Error in sigmoidCrossEntropyWithLogits: ");
  const e = fs(r), s = h(r, n), o = Ds(ss(C(ns(r))));
  return G(b(e, s), o);
}
function jn(t, a, n, r = 0, e = N.SUM_BY_NONZERO_WEIGHTS) {
  let s = u(t, "multiClassLabels", "sigmoidCrossEntropy");
  const o = u(a, "logits", "sigmoidCrossEntropy");
  let i = null;
  if (n != null && (i = u(n, "weights", "sigmoidCrossEntropy")), L(s.shape, o.shape, "Error in sigmoidCrossEntropy: "), r > 0) {
    const c = $(r), f = $(1), m = $(0.5);
    s = G(h(s, b(f, c)), h(m, c));
  }
  const l = Yn(s, o);
  return B(l, i, e);
}
const Fn = /* @__PURE__ */ d({ sigmoidCrossEntropy_: jn });
function Un(t, a, n = -1) {
  if (n === -1 && (n = a.rank - 1), n !== a.rank - 1)
    throw Error(`Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank ${a.rank} and dim was ${n}`);
  return Ms((e, s, o) => {
    const l = Vs(s, [n], !0), c = b(W(s, "float32"), l);
    o([e, c]);
    const f = C(h(c, e));
    return { value: _(f, [n]), gradFunc: (g, y) => {
      const [M, I] = y, A = js(g.shape, [n]);
      return [
        h(O(g, A), b(W(M, "float32"), ss(I))),
        h(O(g, A), b(ss(I), W(M, "float32")))
      ];
    } };
  })(t, a);
}
function Zn(t, a, n, r = 0, e = N.SUM_BY_NONZERO_WEIGHTS) {
  let s = u(t, "onehotLabels", "softmaxCrossEntropy");
  const o = u(a, "logits", "softmaxCrossEntropy");
  let i = null;
  if (n != null && (i = u(n, "weights", "softmaxCrossEntropy")), L(s.shape, o.shape, "Error in softmaxCrossEntropy: "), r > 0) {
    const c = $(r), f = $(1), m = $(s.shape[1]);
    s = G(h(s, b(f, c)), S(c, m));
  }
  const l = Un(s, o);
  return B(l, i, e);
}
const Hn = /* @__PURE__ */ d({ softmaxCrossEntropy_: Zn });
const $e = {
  flipLeftRight: sn,
  grayscaleToRGB: en,
  resizeNearestNeighbor: Ws,
  resizeBilinear: Rs,
  rgbToGrayscale: on,
  rotateWithOffset: an,
  cropAndResize: Xs,
  nonMaxSuppression: ln,
  nonMaxSuppressionAsync: pn,
  nonMaxSuppressionWithScore: fn,
  nonMaxSuppressionWithScoreAsync: dn,
  nonMaxSuppressionPadded: gn,
  nonMaxSuppressionPaddedAsync: $n,
  threshold: Nn,
  transform: kn
}, ye = {
  bandPart: Tn,
  gramSchmidt: xn,
  qr: wn
}, _e = {
  absoluteDifference: Ln,
  computeWeightedLoss: B,
  cosineDistance: Dn,
  hingeLoss: Rn,
  huberLoss: zn,
  logLoss: Cn,
  meanSquaredError: Pn,
  sigmoidCrossEntropy: Fn,
  softmaxCrossEntropy: Hn
};
export {
  _e as a,
  Ks as e,
  $e as i,
  ye as l
};
