Reject non-integral, bool and out-of-range block-layout indices
One _index helper guards block_cell (block, y, x), slot (block_cell, q) and map_cut_links (fluid_idx, dir) before addressing; previously e.g. block_cell(-1, 0, 0) returned -49 and fractional values were truncated. Adds focused rejection tests and Astra's one-block seam reproducer (build(4,8,4,8), receiver (2,0), dir 2 -> west-halo slot 90). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2a68d7e7c7
commit
118635aebd
2 files changed
+43
-8
No files matched your search
@@ -257,6 +257,28 @@ class BlockLayoutTests(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
layout.map_cut_links([CutLink(fluid_idx=5 * 16 + 5, dir=0, q=.6, body_id=0)])
|
||||
|
||||
def test_public_indices_are_rejected_not_truncated(self):
|
||||
layout = BlockLayout2D.build(4, 8, 4, 8) # one block, nx=8, ny=4
|
||||
for args in ((-1, 0, 0), (1, 0, 0), (True, 0, 0), (0.0, 0, 0), (0, 0.5, 0),
|
||||
(0, 1, 2.0), (0, -1, 0), (0, 4, 0), (0, 0, 8), (0, False, 0)):
|
||||
with self.subTest(block_cell=args), self.assertRaises(ValueError):
|
||||
layout.block_cell(*args)
|
||||
cells = int(np.prod(layout.local_shape))
|
||||
for args in ((-1, 1), (cells, 1), (True, 1), (1.0, 1), (0, NQ), (0, -1), (0, 1.0),
|
||||
(0, True), (np.array([0, cells]), 1)):
|
||||
with self.subTest(slot=args), self.assertRaises(ValueError):
|
||||
layout.slot(*args)
|
||||
for idx, d in ((5.7, 1), (True, 1), (-1, 1), (32, 1), (5, 1.0), (5, 9), (5, True), (5, 0)):
|
||||
with self.subTest(fluid_idx=idx, dir=d), self.assertRaises(ValueError):
|
||||
layout.map_cut_links([CutLink(fluid_idx=idx, dir=d, q=.6, body_id=0)])
|
||||
|
||||
def test_one_block_seam_reproducer(self):
|
||||
# Receiver (2,0) -x wraps to x=7; the write must land in the west halo.
|
||||
layout = BlockLayout2D.build(4, 8, 4, 8)
|
||||
mapped = layout.map_cut_links([CutLink(fluid_idx=2 * 8, dir=2, q=.6, body_id=0)])
|
||||
lx = layout.local_shape[1]
|
||||
self.assertEqual(int(mapped.write[0]), int(layout.slot(3 * lx + 0, 1)))
|
||||
|
||||
def test_tables_are_readonly(self):
|
||||
layout = BlockLayout2D.build(6, 8, 3, 4)
|
||||
for array in (layout.origins, layout.owner, layout.halo_dst, layout.halo_src, layout.halo_kind):
|
||||
|
||||
Reference in new issue
Block a user