diff --git a/src/cached.jl b/src/cached.jl index 4c20bb5..c4f5b08 100644 --- a/src/cached.jl +++ b/src/cached.jl @@ -41,8 +41,8 @@ function _readblock_cached!(A::CachedDiskArray{T,N}, data, I...) where {T,N} if haskey(A.cache, c) A.cache[c] else - chunk_data = Array{T,N}(undef, length.(I)...) - A.cache[c] = readblock!(parent(A), chunk_data, I...) + chunk_data = Array{T,N}(undef, length.(c)...) + A.cache[c] = readblock!(parent(A), chunk_data, c...) end end out = ConcatDiskArray(chunk_arrays) diff --git a/test/runtests.jl b/test/runtests.jl index 644e577..b974dad 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -709,22 +709,24 @@ end end @testset "Cached arrays" begin - A = (1:300) * (1:1200)' - ch = ChunkedDiskArray((1:3000) * (1:1200)', (128, 128)) + M = (1:300) * (1:1200)' + A = cat(M, M, M, M; dims=3) + ch = ChunkedDiskArray(A, (128, 128, 2)) ca = DiskArrays.CachedDiskArray(ch; maxsize=5) # Read the original @test sum(ca) == sum(ca) - # Read from the cache - @test ca[:, :] == ch length(ca.cache) ca = DiskArrays.cache(ch; maxsize=5) @test sum(ca) == sum(ca) - @test ca[:, :] == ch[:, :] - @test ca[:, 1] == ch[:, 1] - @test ca[:, 2] == ch[:, 2] - @test ca[:, 3] == ch[:, 3] - @test ca[:, 200] == ch[:, 200] - @test ca[200, :] == ch[200, :] + @test ca[:, :, 1] == A[:, :, 1] + @test ca[:, :, 2] == A[:, :, 2] + @test ca[:, :, 2] == A[:, :, 3] + @test ca[:, :, 2] == A[:, :, 4] + @test ca[:, 1, 1] == ch[:, 1, 1] + @test ca[:, 2, 1] == ch[:, 2, 1] + @test ca[:, 3, 1] == ch[:, 3, 1] + @test ca[:, 200, 1] == ch[:, 200, 1] + @test ca[200, :, 1] == ch[200, :, 1] end