import { b as d } from "../matMul16-BIT70Vya.js";
import { transpose16 as w } from "./transpose16.js";
import { reshape16 as n } from "./reshape16.js";
import { isPackedTensor as p } from "../utilities/packed.js";
import { d as x } from "../tfjs_backend-Bk3PmK91.js";
function E(e, s, h = !1, c = !1) {
  if (!p(e) && !p(s))
    return x(e, s);
  if (e.rank < 2 || s.rank < 2)
    throw new Error(
      `dot requires both inputs to be rank >= 2 but got x shape = ${e.shape} and y shape = ${s.shape}`
    );
  if (s.rank >= 3) {
    const r = e.shape.slice(-1)[0], i = s.shape.slice(-2)[0];
    if (r !== i)
      throw new Error(
        `If rank y >= 3, then the second last dim of y must equal the last dim of x but got x shape = ${e.shape} and  y shape = ${s.shape}`
      );
  }
  if (!p(e) || !p(s))
    throw new Error("dot16 requires both inputs to be packed Tensors.");
  if (e.rank === 2 && s.rank === 2)
    return d(e, s, h, c);
  {
    const r = e.shape.slice(), i = r.pop();
    e = n(e, [-1, i]);
    const a = s.shape.slice(), l = a.pop(), m = a.pop(), k = [...a, l], f = Array.from({ length: s.rank }, (o, t) => t === 0 ? s.rank - 2 : t <= s.rank - 2 ? t - 1 : t);
    if (f.every((o, t) => o === t))
      s = n(s, [m, -1]);
    else {
      const o = w(s, f);
      s = n(o, [m, -1]), o.dispose();
    }
    const y = [...r, ...k], u = d(e, s, h, c);
    e.dispose(), s.dispose();
    const D = n(u, y);
    return u.dispose(), D;
  }
}
export {
  E as dot16
};
