@@ -18,7 +18,7 @@ struct CachedDiskArray{T,N,A<:AbstractArray{T,N},C} <: AbstractDiskArray{T,N}
18
18
end
19
19
function CachedDiskArray (A:: AbstractArray{T,N} ; maxsize= 1000 ) where {T,N}
20
20
by (x) = sizeof (x) ÷ 1_000_000 # In Megabytes
21
- CachedDiskArray (A, LRU {Tuple,Any } (; by, maxsize))
21
+ CachedDiskArray (A, LRU {ChunkIndex{N,OffsetChunks},OffsetArray{T,N,Array{T,N}} } (; by, maxsize))
22
22
end
23
23
24
24
Base. parent (A:: CachedDiskArray ) = A. parent
@@ -35,25 +35,20 @@ eachchunk(A::CachedDiskArray) = eachchunk(parent(A))
35
35
function _readblock_cached! (A:: CachedDiskArray{T,N} , data, I... ) where {T,N}
36
36
chunks = eachchunk (A)
37
37
chunk_inds = findchunk .(chunks. chunks, I)
38
- needed_chunks = chunks[chunk_inds... ]
39
-
40
- chunk_arrays = map (needed_chunks) do c
41
- if haskey (A. cache, c)
42
- A. cache[c]
43
- else
44
- chunk_data = Array {T,N} (undef, length .(c)... )
45
- A. cache[c] = readblock! (parent (A), chunk_data, c... )
38
+ data_offset = OffsetArray (data,map (i-> first (i)- 1 ,I)... )
39
+ foreach (CartesianIndices (chunk_inds)) do ci
40
+ chunkindex = ChunkIndex (ci,offset= true )
41
+ chunk = get! (A. cache, chunkindex) do
42
+ res = parent (A)[chunkindex]
43
+ res
44
+ end
45
+ inner_indices = map (axes (chunk),axes (data_offset)) do ax1, ax2
46
+ max (first (ax1),first (ax2)): min (last (ax1),last (ax2))
47
+ end
48
+ for ii in CartesianIndices (inner_indices)
49
+ data_offset[ii] = chunk[ii]
46
50
end
47
51
end
48
- out = ConcatDiskArray (chunk_arrays)
49
-
50
- out_inds = map (I, first (needed_chunks)) do i, nc
51
- i .- first (nc) .+ 1
52
- end
53
-
54
- data .= view (out, out_inds... )
55
-
56
- return data
57
52
end
58
53
59
54
"""
0 commit comments