From a4df672925359a59761feacf077ab5f3a093a5b5 Mon Sep 17 00:00:00 2001 From: rafaqz Date: Fri, 2 Feb 2024 17:07:12 +0100 Subject: [PATCH] make it work --- src/cached.jl | 21 +++++++++++++++++++++ test/runtests.jl | 1 - 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cached.jl b/src/cached.jl index 796b89d..389a9cb 100644 --- a/src/cached.jl +++ b/src/cached.jl @@ -32,6 +32,27 @@ readblock!(A::CachedDiskArray, data, I::AbstractVector...) = _readblock_cached(A haschunks(A::CachedDiskArray) = haschunks(parent(A)) eachchunk(A::CachedDiskArray) = eachchunk(parent(A)) +function readblock!(A::CachedDiskArray{T,N}, data, I...) where {T,N} + chunks = eachchunk(A) + chunk_inds = findchunk.(chunks.chunks, I) + + chunk_arrays = map(chunks[chunk_inds...]) do c + if haskey(A.cache, c) + A.cache[c] + else + chunk_data = Array{T,N}(undef, length.(I)) + A.cache[c] = readblock!(A, chunk_data, I...) + end + end + + out_chunks = ConcatDiskArray(chunk_arrays) + out_inds = map(i -> i .- first(i) + 1, I) + + data .= view(out_chunks, out_inds...) + + return data +end + function _readblock_cached(A, data, I...) if haskey(A.cache, I) data .= A.cache[I] diff --git a/test/runtests.jl b/test/runtests.jl index db141cb..bbec127 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -722,5 +722,4 @@ end @test sum(ca) == sum(ca) # Read from the cache @test ca[:, :] == ch - length(ca.cache) end