Skip to content

Commit

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

0 comments on commit d1a9899

Please sign in to comment.