88from mdio .core .grid import _calculate_optimal_chunksize
99
1010
11- class MockArray :
12- """Mock array class that mimics numpy array attributes without allocating memory."""
13-
14- def __init__ (self , shape , dtype ):
15- """Initialize the mock array."""
16- self .shape = shape
17- self .dtype = np .dtype (dtype )
18- self .itemsize = self .dtype .itemsize
19-
20-
2111def test_small_grid_no_chunking ():
2212 """Test that small grids return -1 (no chunking needed)."""
2313 # Create a small grid that fits within INT32_MAX
@@ -27,8 +17,21 @@ def test_small_grid_no_chunking():
2717 Dimension (coords = range (0 , 100 , 1 ), name = "sample" ),
2818 ]
2919 grid = Grid (dims = dims )
30- grid .live_mask = MockArray ((100 , 100 ), bool )
20+ grid .live_mask = np .empty ((100 , 100 ), dtype = np .bool )
21+
22+ result = _calculate_live_mask_chunksize (grid )
23+ assert result == (100 , 100 )
24+
3125
26+ def test_grid_without_live_mask ():
27+ """Test that a grid without a live mask set up yet."""
28+ dims = [
29+ Dimension (coords = range (0 , 100 , 1 ), name = "dim1" ),
30+ Dimension (coords = range (0 , 100 , 1 ), name = "dim2" ),
31+ Dimension (coords = range (0 , 100 , 1 ), name = "sample" ),
32+ ]
33+ grid = Grid (dims = dims )
34+
3235 result = _calculate_live_mask_chunksize (grid )
3336 assert result == (100 , 100 )
3437
@@ -43,7 +46,7 @@ def test_large_2d_grid_chunking():
4346 Dimension (coords = range (0 , 100 , 1 ), name = "sample" ),
4447 ]
4548 grid = Grid (dims = dims )
46- grid .live_mask = MockArray ((50000 , 50000 ), bool )
49+ grid .live_mask = np . empty ((50000 , 50000 ), dtype = np . bool )
4750
4851 result = _calculate_live_mask_chunksize (grid )
4952
@@ -62,7 +65,7 @@ def test_large_3d_grid_chunking():
6265 Dimension (coords = range (0 , 100 , 1 ), name = "sample" ),
6366 ]
6467 grid = Grid (dims = dims )
65- grid .live_mask = MockArray ((1500 , 1500 , 1500 ), bool )
68+ grid .live_mask = np . empty ((1500 , 1500 , 1500 ), dtype = np . bool )
6669
6770 result = _calculate_live_mask_chunksize (grid )
6871
@@ -93,15 +96,15 @@ def test_prestack_land_survey_chunking():
9396 Dimension (coords = range (0 , 1000 , 1 ), name = "sample" ),
9497 ]
9598 grid = Grid (dims = dims )
96- grid .live_mask = MockArray ((1000 , 1000 , 100 , 36 ), bool )
99+ grid .live_mask = np . empty ((1000 , 1000 , 100 , 36 ), dtype = np . bool )
97100
98101 result = _calculate_live_mask_chunksize (grid )
99102 assert result == (334 , 334 , 100 , 36 )
100103
101104
102105def test_one_dim_full_chunk ():
103106 """Test one-dimensional volume where the whole dimension can be used as chunk."""
104- arr = MockArray ((100 ,), np .int8 )
107+ arr = np . empty ((100 ,), dtype = np .int8 )
105108 # With n_bytes = 100, max_elements_allowed = 100, thus optimal chunk should be (100,)
106109 result = _calculate_optimal_chunksize (arr , 100 )
107110 assert result == (100 ,)
@@ -112,7 +115,7 @@ def test_two_dim_optimal():
112115
113116 For a shape of (8,6) with n_bytes=20, the optimal chunk is expected to be (8,2).
114117 """
115- arr = MockArray ((8 , 6 ), np .int8 )
118+ arr = np . empty ((8 , 6 ), dtype = np .int8 )
116119 result = _calculate_optimal_chunksize (arr , 20 )
117120 assert result == (4 , 4 )
118121
@@ -122,7 +125,7 @@ def test_three_dim_optimal():
122125
123126 For a shape of (9,6,4) with n_bytes=100, the expected chunk is (9,2,4).
124127 """
125- arr = MockArray ((9 , 6 , 4 ), np .int8 )
128+ arr = np . empty ((9 , 6 , 4 ), dtype = np .int8 )
126129 result = _calculate_optimal_chunksize (arr , 100 )
127130 assert result == (5 , 5 , 4 )
128131
@@ -132,21 +135,21 @@ def test_minimal_chunk_for_large_dtype():
132135
133136 Using int32 (itemsize=4) with shape (4,5) and n_bytes=4 yields (1,1).
134137 """
135- arr = MockArray ((4 , 5 ), np .int32 )
138+ arr = np . empty ((4 , 5 ), dtype = np .int32 )
136139 result = _calculate_optimal_chunksize (arr , 4 )
137140 assert result == (1 , 1 )
138141
139142
140143def test_large_nbytes ():
141144 """Test that a very large n_bytes returns the full volume shape as the optimal chunk."""
142- arr = MockArray ((10 , 10 ), np .int8 )
145+ arr = np . empty ((10 , 10 ), dtype = np .int8 )
143146 result = _calculate_optimal_chunksize (arr , 1000 )
144147 assert result == (10 , 10 )
145148
146149
147150def test_two_dim_non_int8 ():
148151 """Test with a non-int8 dtype where n_bytes exactly covers the full volume in bytes."""
149- arr = MockArray ((6 , 8 ), np .int16 ) # int16 has itemsize 2
152+ arr = np . empty ((6 , 8 ), dtype = np .int16 ) # int16 has itemsize 2
150153 # Total bytes of full volume = 6*8*2 = 96, so optimal chunk should be (6,8)
151154 result = _calculate_optimal_chunksize (arr , 96 )
152155 assert result == (6 , 8 )
@@ -157,14 +160,14 @@ def test_irregular_dimensions():
157160
158161 For shape (7,5) with n_bytes=35, optimal chunk should be (7,5) since 7*5 = 35.
159162 """
160- arr = MockArray ((7 , 5 ), np .int8 )
163+ arr = np . empty ((7 , 5 ), dtype = np .int8 )
161164 result = _calculate_optimal_chunksize (arr , 35 )
162165 assert result == (7 , 5 )
163166
164167
165168def test_primes ():
166169 """Test volume with prime dimensions where divisors are limited."""
167- arr = MockArray ((7 , 5 ), np .int8 )
170+ arr = np . empty ((7 , 5 ), dtype = np .int8 )
168171 result = _calculate_optimal_chunksize (arr , 23 )
169172 assert result == (4 , 4 )
170173
@@ -203,7 +206,7 @@ def test_grid_gambit():
203206
204207 # Create grid and set live mask
205208 grid = Grid (dims = dims )
206- grid .live_mask = MockArray (shape , bool )
209+ grid .live_mask = np . empty (shape , dtype = np . bool )
207210
208211 result = _calculate_live_mask_chunksize (grid )
209212
0 commit comments