async function b(s) {
  if (!Array.isArray(s) && s.dtype !== "float32")
    throw new Error(`Unsupported dtype ${s.dtype} for weight statistics.`);
  const e = Array.isArray(s) ? s : await s.data(), a = e.length;
  let r = 0, l = 0, n = e[0], i = e[0], f = 0, d = !0, u = !1, y = 0;
  for (let c = 0; c < a; c++) {
    const t = e[c];
    r += t, l += t * t, t < n && (n = t), t > i && (i = t), t === 0 && f++, Math.abs(t) < 1e-8 && y++, Number.isNaN(t) && (u = !0);
  }
  const o = r / a, m = l / a - o * o, p = Math.sqrt(m), N = f / a;
  return {
    mean: o,
    std: p,
    min: n,
    max: i,
    sparsity: N,
    isFinite: d,
    hasNaN: u,
    closeToZeroCount: y
  };
}
async function h(s) {
  const e = s.trainableVariables, a = {};
  for (const r of e)
    a[r.name] = await b(r);
  return a;
}
export {
  b as createTensorStatistics,
  h as createWeightStatistics
};
