import { P as w } from "./backend_util-qwSFfxYx.js";
import { a8 as f } from "./index-DSGwv2Yx.js";
function g(o, s) {
  let r = !1, t;
  for (o <= w ? (t = o, r = !0) : t = f(o, Math.floor(Math.sqrt(o))); !r; )
    t > s || t === o ? r = !0 : t = f(o, t + 1);
  return t;
}
function c(o, s, r) {
  const t = [], p = o.length;
  for (let h = 0; h < p; h++)
    h !== s ? t.push(o[h]) : t.push(r);
  return t;
}
function O(o, s, r, t) {
  const p = s.shape.length, h = o.shape.length;
  if (t !== 0 && (t < -p || t > p))
    throw new Error(`Expect batchDims in the range of [-${p}, ${p}], but got ${t}`);
  if (t < 0 && (t += p), t > h)
    throw new Error(`batchDims (${t}) must be less than rank(x) (
    ${h}).`);
  if (r < t)
    throw new Error(`batchDims (${t}) must be less than or equal to axis (${r}).`);
  for (let e = 0; e < t; ++e)
    if (o.shape[e] !== s.shape[e])
      throw new Error(`x.shape[${e}]: ${o.shape[e]} should be equal to indices.shape[${e}]: ${s.shape[e]}.`);
  const $ = o.shape[r], l = [];
  let a = 1, n = 1, u = 1;
  for (let e = 0; e < t; ++e)
    l.push(o.shape[e]), a *= o.shape[e];
  for (let e = t; e < r; e++)
    l.push(o.shape[e]), n *= o.shape[e];
  for (let e = t; e < p; e++)
    l.push(s.shape[e]);
  for (let e = r + 1; e < h; e++)
    l.push(o.shape[e]), u *= o.shape[e];
  return { batchSize: a, sliceSize: u, outerSize: n, dimSize: $, outputShape: l };
}
export {
  c as a,
  O as c,
  g as s
};
