From 85b7bd4ba94aa8cd99b10be4eca16d227b49f7dd Mon Sep 17 00:00:00 2001 From: rafaqz Date: Fri, 2 Feb 2024 17:59:41 +0100 Subject: [PATCH] return slices besides 1 --- src/cached.jl | 7 +++++-- test/runtests.jl | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cached.jl b/src/cached.jl index 334161a..4c20bb5 100644 --- a/src/cached.jl +++ b/src/cached.jl @@ -35,8 +35,9 @@ eachchunk(A::CachedDiskArray) = eachchunk(parent(A)) function _readblock_cached!(A::CachedDiskArray{T,N}, data, I...) where {T,N} chunks = eachchunk(A) chunk_inds = findchunk.(chunks.chunks, I) + needed_chunks = chunks[chunk_inds...] - chunk_arrays = map(chunks[chunk_inds...]) do c + chunk_arrays = map(needed_chunks) do c if haskey(A.cache, c) A.cache[c] else @@ -46,7 +47,9 @@ function _readblock_cached!(A::CachedDiskArray{T,N}, data, I...) where {T,N} end out = ConcatDiskArray(chunk_arrays) - out_inds = map(i -> i .- first(i) .+ 1, I) + out_inds = map(I, first(needed_chunks)) do i, nc + i .- first(nc) .+ 1 + end data .= view(out, out_inds...) diff --git a/test/runtests.jl b/test/runtests.jl index 58f67b6..644e577 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -720,6 +720,11 @@ end ca = DiskArrays.cache(ch; maxsize=5) @test sum(ca) == sum(ca) - # Read from the cache - @test ca[:, :] == ch + + @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, :] end