Skip to content

Commit

Permalink
return slices besides 1
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Feb 5, 2024
1 parent f529d28 commit 85b7bd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/cached.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)

Expand Down
9 changes: 7 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 85b7bd4

Please sign in to comment.