def testBasic(self): graph = Graph() opDataProvider = OpArrayPiperWithAccessCount(graph=graph) opCache = OpUnblockedArrayCache(graph=graph) data = np.random.random((100, 100, 100)).astype(np.float32) opDataProvider.Input.setValue(vigra.taggedView(data, 'zyx')) opCache.Input.connect(opDataProvider.Output) assert opCache.CleanBlocks.value == [] roi = ((30, 30, 30), (50, 50, 50)) cache_data = opCache.Output(*roi).wait() assert (cache_data == data[roiToSlice(*roi)]).all() assert opDataProvider.accessCount == 1 assert opCache.CleanBlocks.value == [roiToSlice(*roi)] # Request the same data a second time. # Access count should not change. cache_data = opCache.Output(*roi).wait() assert (cache_data == data[roiToSlice(*roi)]).all() assert opDataProvider.accessCount == 1 assert opCache.CleanBlocks.value == [roiToSlice(*roi)] # Now invalidate a part of the data # The cache will discard it, so the access count should increase. opDataProvider.Input.setDirty((30, 30, 30), (31, 31, 31)) assert opCache.CleanBlocks.value == [] cache_data = opCache.Output(*roi).wait() assert (cache_data == data[roiToSlice(*roi)]).all() assert opDataProvider.accessCount == 2 # Repeat this next part just for safety for _ in range(10): # Make sure the cache is empty opDataProvider.Input.setDirty((30, 30, 30), (31, 31, 31)) opDataProvider.accessCount = 0 # Create many requests for the same data. # Upstream data should only be accessed ONCE. pool = RequestPool() for _ in range(10): pool.add(opCache.Output(*roi)) pool.wait() assert opDataProvider.accessCount == 1 # Also, make sure requests for INNER rois of stored blocks are also serviced from memory opDataProvider.accessCount = 0 inner_roi = ((35, 35, 35), (45, 45, 45)) cache_data = opCache.Output(*inner_roi).wait() assert (cache_data == data[roiToSlice(*inner_roi)]).all() assert opDataProvider.accessCount == 0 assert opCache.CleanBlocks.value == [roiToSlice(*roi)]
def testBasic(self): graph = Graph() opDataProvider = OpArrayPiperWithAccessCount(graph=graph) opCache = OpUnblockedArrayCache(graph=graph) data = np.random.random((100, 100, 100)).astype(np.float32) opDataProvider.Input.setValue(vigra.taggedView(data, "zyx")) opCache.Input.connect(opDataProvider.Output) assert opCache.CleanBlocks.value == [] roi = ((30, 30, 30), (50, 50, 50)) cache_data = opCache.Output(*roi).wait() assert (cache_data == data[roiToSlice(*roi)]).all() assert opDataProvider.accessCount == 1 assert opCache.CleanBlocks.value == [roiToSlice(*roi)] # Request the same data a second time. # Access count should not change. cache_data = opCache.Output(*roi).wait() assert (cache_data == data[roiToSlice(*roi)]).all() assert opDataProvider.accessCount == 1 assert opCache.CleanBlocks.value == [roiToSlice(*roi)] # Now invalidate a part of the data # The cache will discard it, so the access count should increase. opDataProvider.Input.setDirty((30, 30, 30), (31, 31, 31)) assert opCache.CleanBlocks.value == [] cache_data = opCache.Output(*roi).wait() assert (cache_data == data[roiToSlice(*roi)]).all() assert opDataProvider.accessCount == 2 # Repeat this next part just for safety for _ in range(10): # Make sure the cache is empty opDataProvider.Input.setDirty((30, 30, 30), (31, 31, 31)) opDataProvider.accessCount = 0 # Create many requests for the same data. # Upstream data should only be accessed ONCE. pool = RequestPool() for _ in range(10): pool.add(opCache.Output(*roi)) pool.wait() assert opDataProvider.accessCount == 1 # Also, make sure requests for INNER rois of stored blocks are also serviced from memory opDataProvider.accessCount = 0 inner_roi = ((35, 35, 35), (45, 45, 45)) cache_data = opCache.Output(*inner_roi).wait() assert (cache_data == data[roiToSlice(*inner_roi)]).all() assert opDataProvider.accessCount == 0 assert opCache.CleanBlocks.value == [roiToSlice(*roi)]