import "../index-DSGwv2Yx.js";
import { t as p } from "../tensor-D8e0Gd7c.js";
function h(n) {
  const e = n.reduce((s, o) => s + o.length, 0), a = new Float32Array(e);
  let t = 0;
  for (const s of n)
    a.set(s, t), t += s.length;
  return a;
}
async function d(n) {
  const e = {
    spec: [],
    data: new Float32Array()
  }, a = [];
  for (const t of n) {
    if (!t || !Array.isArray(t.shape) || t.shape.length === 0) {
      console.warn("Skipping weight with invalid shape:", t);
      continue;
    }
    const s = t.min(), o = t.max(), c = (await s.data())[0], r = (await o.data())[0] - c;
    e.spec.push({
      shape: t.shape,
      min: c,
      scale: r
    }), s.dispose(), o.dispose();
    const i = await t.data();
    a.push(i);
  }
  return e.data = h(a), e;
}
async function u(n) {
  const e = [];
  let a = 0;
  for (const t of n.spec) {
    const s = t.shape.reduce((r, i) => r * i, 1), o = n.data.slice(a, a + s);
    a += s;
    const c = p(o, t.shape, "float32");
    e.push(c);
  }
  return e;
}
export {
  d as exportWeights,
  u as importWeights
};
