Skip to content

Commit

Permalink
make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Feb 5, 2024
1 parent b9a4974 commit a4df672
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/cached.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,4 @@ end
@test sum(ca) == sum(ca)
# Read from the cache
@test ca[:, :] == ch
length(ca.cache)
end

0 comments on commit a4df672

Please sign in to comment.