test: separate topology identity from FP64 table validation

This commit is contained in:
Codex
2026-10-18 10:17:43 -07:00
parent 5dcd3e0dbe
commit 1779cf29f2
3 changed files with 126 additions and 4 deletions
@@ -193,6 +193,40 @@ class Host(unittest.TestCase):
with self.assertRaisesRegex(ValueError,'pinned reference'):
trajectory.load_references(path,path)
def test_n64_table_guard_and_balanced_mutation(self):
guard=trajectory.table_guard
plan=ref.Plan(64,(8,8,56,48)); tables=gpu.pack_plan(plan)
self.assertEqual(guard.validate_tables(plan,tables)['status'],'passed')
face=next(i for i,g in enumerate(plan.groups) if g.kind=='face')
changed={key:value.copy() for key,value in tables.items()}
changed['weights'][face,0,0]=np.nextafter(changed['weights'][face,0,0],np.inf)
self.assertEqual(guard.validate_tables(plan,changed)['status'],'passed')
for mutation in ('coordinate','order','dtype','shape','layout','padding','negative_zero','nan','inf','balanced'):
changed={key:value.copy() for key,value in tables.items()}
w=changed['weights']
if mutation=='coordinate': changed['incoming1'][0,0]^=1
elif mutation=='order': changed['origins']=changed['origins'][::-1].copy()
elif mutation=='dtype': changed['weights']=w.astype(np.float32)
elif mutation=='shape': changed['weights']=w.reshape(532,10,4)
elif mutation=='layout': changed['weights']=np.asfortranarray(w)
elif mutation=='padding': w[face,0,9]=1e-30
elif mutation=='negative_zero': w[face,0,9]=-0.
elif mutation=='nan': w[face,0,0]=np.nan
elif mutation=='inf': w[face,0,0]=np.inf
else:
w[face,:2,:2] += 2.**-30*np.array([[1.,-1.],[-1.,1.]])
np.testing.assert_array_equal(w[face].sum(axis=1),tables['weights'][face].sum(axis=1))
np.testing.assert_array_equal(w[face].mean(axis=0),tables['weights'][face].mean(axis=0))
with self.subTest(mutation=mutation), self.assertRaises(ValueError):
guard.validate_tables(plan,changed)
changed={key:value.copy() for key,value in tables.items()}
changed['weights'][-1,0,0]+=1.
with self.assertRaises(ValueError):
guard.validate_tables(SimpleNamespace(n=64,groups=plan.groups[:-1]),changed)
groups=list(plan.groups); groups[0]=replace(groups[0],samples=groups[0].samples[:-1])
with self.assertRaisesRegex(ValueError,'coverage/size'):
guard.validate_tables(SimpleNamespace(n=64,groups=groups),tables)
class Device(unittest.TestCase):
@classmethod