@@ -200,6 +200,7 @@ def test_set_data(self):
200200 np .testing .assert_equal (tuple (item [0 ].shape ), (2 , 1 , 2 , 2 ))
201201 np .testing .assert_allclose (item [0 ], np .array ([[[[81 , 91 ], [121 , 131 ]]], [[[101 , 111 ], [141 , 151 ]]]]), rtol = 1e-4 )
202202 np .testing .assert_allclose (item [1 ], np .array ([[[0 , 1 ], [2 , 4 ], [0 , 2 ]], [[0 , 1 ], [2 , 4 ], [2 , 4 ]]]), rtol = 1e-5 )
203+
203204 # simulate another epoch, the cache content should not be modified
204205 for item in DataLoader (dataset , batch_size = 2 , shuffle = False , num_workers = num_workers ):
205206 np .testing .assert_equal (tuple (item [0 ].shape ), (2 , 1 , 2 , 2 ))
@@ -217,6 +218,29 @@ def test_set_data(self):
217218 )
218219 np .testing .assert_allclose (item [1 ], np .array ([[[0 , 1 ], [2 , 4 ], [0 , 2 ]], [[0 , 1 ], [2 , 4 ], [2 , 4 ]]]), rtol = 1e-5 )
219220
221+ def test_partial_cache_preserves_uncached_items (self ):
222+ dataset = GridPatchDataset (
223+ data = [[1 ], [2 ]], patch_iter = identity_generator , cache = True , cache_rate = 0.5 , progress = False
224+ )
225+
226+ self .assertEqual (list (dataset ), [(1 , 0 ), (2 , 0 )])
227+
228+ def test_cache_without_coordinates (self ):
229+ dataset = GridPatchDataset (
230+ data = [[1 , 2 ]], patch_iter = identity_generator , with_coordinates = False , cache = True , progress = False
231+ )
232+
233+ self .assertEqual (list (dataset ), [1 , 2 ])
234+
235+ def test_zero_sized_cache (self ):
236+ for cache_kwargs in ({"cache_rate" : 0.0 }, {"cache_num" : 0 }):
237+ with self .subTest (** cache_kwargs ):
238+ dataset = GridPatchDataset (
239+ data = [[1 ], [2 ]], patch_iter = identity_generator , cache = True , progress = False , ** cache_kwargs
240+ )
241+
242+ self .assertEqual (list (dataset ), [(1 , 0 ), (2 , 0 )])
243+
220244
221245if __name__ == "__main__" :
222246 unittest .main ()
0 commit comments