--- /tmp/tj/check/check_r45u3f_a028b118.py 2026-11-15 15:01:54.946384718 +0100 +++ check/chk_rom.py 2026-11-15 17:19:43.405967158 +0100 @@ -630,6 +630,11 @@ Y = X.copy(); Y[j::o] = 0; nr.append(Y); nw.append(w) rows, wts = nr, nw tw = int(sum(wts)) + _mg = {} + for X, w in zip(rows, wts): + kb = X.tobytes(); _mg[kb] = _mg.get(kb, 0) + w + rows = [np.frombuffer(kb, dtype=np.int8).copy() for kb in _mg]; wts = list(_mg.values()) + assert int(sum(wts)) == tw out = {} nd = len(GL["divs"]); ndc = len(GL["divsc"]); NPl, NGl = GL["NP"], GL["NG"] for c0 in range(0, len(wts), GL["CH"]): @@ -652,18 +657,20 @@ for k_, g, a in GL["ajf"]: tail += g * a * Sf[:, k_ // NGl, :, k_ % NGl] J = np.floor(1 + GL["capk"] * (Qf + tail) / np.maximum(s, 1)).astype(np.int64) assert (s >= 0).all() and float(Sf.min()) >= 0 - assert n1 * int(W.max()) * GL["PER2"] < 2 ** 53, "float64 exactness bound (chunk)" - Wc = W.astype(np.float64); jmin = int(J.min()); G_ = int(J.max()) - jmin + 1 - XP = np.empty((n1, 1 + nd)); E1 = np.zeros((G_, n1)); ar = np.arange(n1) + assert float(Sf.max()) < 2 ** 52 and np.array_equal(Sf, np.round(Sf)), "Sf entiers exacts" + assert n1 * int(W.max()) * GL["PER2"] < 2 ** 62, "int64 exactness bound (chunk)" + Si = Sf.astype(np.int64) + Wc = W; jmin = int(J.min()); G_ = int(J.max()) - jmin + 1 + XP = np.empty((n1, 1 + nd), dtype=np.int64); E1 = np.zeros((G_, n1), dtype=np.int64); ar = np.arange(n1) for P in range(NPl): XP[:, 0] = Wc * s[:, P] - XP[:, 1:] = (Wc[:, None, None] * Sf[:, :, P, :]).reshape(n1, nd) - E1[:] = 0.0; E1[J[:, P] - jmin, ar] = 1.0 - sums = E1 @ XP # exact: all partial sums < 2^53 + XP[:, 1:] = (Wc[:, None, None] * Si[:, :, P, :]).reshape(n1, nd) + E1[:] = 0; E1[J[:, P] - jmin, ar] = 1 + sums = E1 @ XP # exact int64 (bound asserted above) mP = GL["multp"][P] for gi_ in np.flatnonzero(E1.sum(axis=1) > 0): j = jmin + int(gi_) - vec = sums[gi_].astype(np.int64).astype(object) * mP + vec = sums[gi_].astype(object) * mP if j in out: out[j] += vec else: out[j] = vec return cnt_, tw, out @@ -681,14 +688,48 @@ sys.exit(3) A1, QJ, SJ = {}, {}, {} totw = 0 - with get_context("fork").Pool(WORKERS) as pool: - for cnt_, tw, out in pool.imap_unordered(orbit_sums_f, items, chunksize=2): - totw += cnt_ * tw - for j, vec in out.items(): - req(j >= 1) - A1[j] = A1.get(j, 0) + cnt_ * int(vec[0]) - v = SJ.setdefault(j, [0] * len(divs)) - for i in range(len(divs)): v[i] += cnt_ * int(vec[1 + i]) + import os as _os + _SL = _os.environ.get("TRANCHE"); _CB = _os.environ.get("RECOMBINE") + def _acc(res): + global totw + cnt_, tw, out = res + totw += cnt_ * tw + for j, vec in out.items(): + req(j >= 1) + A1[j] = A1.get(j, 0) + cnt_ * int(vec[0]) + v = SJ.setdefault(j, [0] * len(divs)) + for i in range(len(divs)): v[i] += cnt_ * int(vec[1 + i]) + if _SL: + i0, i1 = map(int, _SL.split(":")); i1 = min(i1, len(items)) + def _dump(upto): + tmp = _os.environ["SORTIE"] + ".tmp" + json.dump(dict(i0=i0, i1=upto, n=len(items), totw=str(totw), A1={str(j): str(x) for j, x in A1.items()}, + SJ={str(j): [str(x) for x in v] for j, v in SJ.items()}), open(tmp, "w")) + _os.replace(tmp, _os.environ["SORTIE"]) + with get_context("fork").Pool(WORKERS) as pool: + pos_ = i0 + for res in pool.imap(orbit_sums_f, items[i0:i1], chunksize=1): + _acc(res); pos_ += 1; _dump(pos_) + if (pos_ - i0) % 10 == 0: log(f"[tranche] {pos_}/{len(items)}") + _dump(i1) + log(f"[tranche] orbites {i0}:{i1} sur {len(items)} ecrites dans {_os.environ['SORTIE']}"); sys.exit(4) + elif _CB: + cover = [] + for fn in _CB.split(","): + dd = json.load(open(fn)); req(dd["n"] == len(items)); cover.append((dd["i0"], dd["i1"])) + totw += int(dd["totw"]) + for js, x in dd["A1"].items(): A1[int(js)] = A1.get(int(js), 0) + int(x) + for js, vv in dd["SJ"].items(): + v = SJ.setdefault(int(js), [0] * len(divs)) + for i in range(len(divs)): v[i] += int(vv[i]) + cover.sort(); pos = 0 + for a_, b_ in cover: + req(a_ == pos, ("tranches non contigues", a_, pos)); pos = b_ + req(pos == len(items), "tranches incompletes") + log(f"[recombine] {len(cover)} tranches couvrent exactement les {len(items)} orbites") + else: + with get_context("fork").Pool(WORKERS) as pool: + for res in pool.imap_unordered(orbit_sums_f, items, chunksize=2): _acc(res) for j in SJ: # v3: exact Q sums from the exact S sums (natural order), then reorder QJ[j] = sum(Bn_nat[k] * SJ[j][k] for k in range(len(divs))) v_ = SJ[j]; SJ[j] = [v_[int(inv_col[i])] for i in range(len(divs))]