import { m as w } from "../index-DSGwv2Yx.js";
import { t as f } from "../tensor2d-DTtQ1QcT.js";
import { e as y } from "../expand_dims-D0rBtgT1.js";
import { s as g } from "../sum-D39FeU5h.js";
import { c as T } from "../concat-Dqk7Xk7h.js";
const p = 16;
function A(o, t) {
  if (!t)
    return o.mean(1);
  const r = y(t, 2), i = w(o, r), e = g(i, 1), s = g(t, 1, !0), c = e.div(s.maximum(1e-9));
  return r.dispose(), i.dispose(), e.dispose(), s.dispose(), c;
}
function E(o, t, r = p) {
  const i = o.tokeniser, e = o.config.blockSize;
  let s = null, c = 0;
  for (; c < t.length; ) {
    const b = t.slice(c, c + p).map((n) => i.encode(n)), l = [], d = [];
    for (const n of b)
      n.length > e ? (l.push(n.slice(n.length - e, n.length)), d.push(new Array(e).fill(1))) : n.length < e ? (l.push(n.concat(new Array(e - n.length).fill(0))), d.push(
        new Array(n.length).fill(1).concat(new Array(e - n.length).fill(0))
      )) : (l.push(n), d.push(new Array(e).fill(1)));
    const k = f(l, [l.length, e], "int32"), m = f(d, [d.length, e], "float32"), u = o.model.forward({ skipLogits: !0, training: !1 }, k), a = A(u, m);
    if (m.dispose(), u.dispose(), s === null)
      s = a;
    else {
      const n = s;
      s = T([s, a], 0), n.dispose(), a.dispose();
    }
    c += r;
  }
  return s;
}
async function v(o, t, r = p) {
  const i = await E(o, t, r), e = await i.array();
  return i.dispose(), e;
}
export {
  A as meanPooling,
  v as sentenceEmbeddings,
  E as sentenceEmbeddingsTensor
};
