"""The ported builder against the prototype, on the same nudged random views.""" import glob, random, sys, time import numpy as np import corpus.convert as cv from functional import MACH, sample, window, works from measure import CONFIGS from build_tasks import records views = sample(sorted(glob.glob(sys.argv[1])), int(sys.argv[2]), nudge=True) recs = {} opts = CONFIGS["v17 + splitters as ports, big drills"] t = time.time(); old = [works(window(r, lab, x0, y0, opts)[0]) for r, lab, x0, y0 in views]; t_old = time.time() - t # Re-rasterise with lanes inside the raster. from functional import labelled new, t_new = [], 0.0 for r, lab, x0, y0 in views: r2 = r r2.drills = [(fx, fy, d) for (fx, fy), d in r.drills] r2.lanes = {k: {getattr(cv.str2item(n), "value", -1) or -1 for n in v} for k, v in lab.items()} t = time.time() e = cv.edit(r2, x0, y0, 32, random.Random(0)) w = cv.paste(r2, x0, y0, 32, e) t_new += time.time() - t _, outs = cv._machine_items(w) tot, cr = cv.deliveries(w, outs) new.append((tot > 0, cr > 0)) has = [bool(np.isin(r.ent[x0:x0 + 30, y0:y0 + 30], list(MACH)).any()) for r, _, x0, y0 in views] for name, res, tt in (("prototype", old, t_old), ("ported", new, t_new)): print(f"{name:10s} deliver {np.mean([a for a, _ in res]):.1%} machines {np.mean([b for (_, b), h in zip(res, has) if h]):.1%} {tt / len(views) * 1000:.0f} ms/window") print("disagree", sum(a != b for a, b in zip(old, new)))