Skip to content

Commit c0aac92

Browse files
committed
Add a readblock fallback
1 parent 0f0407a commit c0aac92

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/cat.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function ConcatDiskArray(arrays::AbstractArray{<:AbstractArray{<:Any,N},M}) wher
2222
T = mapreduce(eltype, promote_type, init=eltype(first(arrays)), arrays)
2323

2424
if N > M
25-
newshape = extenddims(size(arrays), size(first(arrays)),1)
25+
newshape = extenddims(size(arrays), size(first(arrays)), 1)
2626
arrays1 = reshape(arrays, newshape)
2727
D = N
2828
else
@@ -42,17 +42,17 @@ function ConcatDiskArray(arrays::AbstractArray)
4242
error("Arrays don't have the same dimensions")
4343
return error("Should not be reached")
4444
end
45-
extenddims(a::Tuple{Vararg{<:Any,N}}, b::Tuple{Vararg{<:Any,M}}, fillval) where {N,M} = extenddims((a..., fillval), b, fillval)
46-
extenddims(a::Tuple{Vararg{<:Any,N}}, _::Tuple{Vararg{<:Any,N}}, _) where {N} = a
45+
extenddims(a::Tuple{Vararg{Any,N}}, b::Tuple{Vararg{Any,M}}, fillval) where {N,M} = extenddims((a..., fillval), b, fillval)
46+
extenddims(a::Tuple{Vararg{Any,N}}, _::Tuple{Vararg{Any,N}}, _) where {N} = a
4747

4848
Base.size(a::ConcatDiskArray) = a.size
4949

5050
function arraysize_and_startinds(arrays1)
51-
sizes = map(i->zeros(Int,i),size(arrays1))
51+
sizes = map(i -> zeros(Int, i), size(arrays1))
5252
for i in CartesianIndices(arrays1)
5353
ai = arrays1[i]
5454
sizecur = extenddims(size(ai), size(arrays1), 1)
55-
foreach(sizecur,i.I,sizes) do si, ind, sizeall
55+
foreach(sizecur, i.I, sizes) do si, ind, sizeall
5656
if sizeall[ind] == 0
5757
#init the size
5858
sizeall[ind] = si
@@ -64,9 +64,9 @@ function arraysize_and_startinds(arrays1)
6464
r = map(sizes) do sizeall
6565
pushfirst!(sizeall, 1)
6666
for i in 2:length(sizeall)
67-
sizeall[i] = sizeall[i-1]+sizeall[i]
67+
sizeall[i] = sizeall[i-1] + sizeall[i]
6868
end
69-
pop!(sizeall)-1,sizeall
69+
pop!(sizeall) - 1, sizeall
7070
end
7171
map(last, r), map(first, r)
7272
end
@@ -86,7 +86,7 @@ end
8686
function writeblock!(a::ConcatDiskArray, aout, inds::AbstractUnitRange...)
8787
_concat_diskarray_block_io(a, inds...) do outer_range, array_range, I
8888
data = view(aout, outer_range...)
89-
writeblock!(a.parents[I], data, array_range)
89+
writeblock!(a.parents[I], data, array_range...)
9090
end
9191
end
9292

@@ -123,11 +123,11 @@ fix_outerrangeshape(res, ::Tuple{}, ::Tuple{}) = res
123123

124124

125125
function concat_chunksize(parents)
126-
newchunks = map(s->Vector{Union{RegularChunks, IrregularChunks}}(undef, s) ,size(parents))
126+
newchunks = map(s -> Vector{Union{RegularChunks,IrregularChunks}}(undef, s), size(parents))
127127
for i in CartesianIndices(parents)
128128
array = parents[i]
129129
chunks = eachchunk(array)
130-
foreach(chunks.chunks,i.I,newchunks) do c, ind, newc
130+
foreach(chunks.chunks, i.I, newchunks) do c, ind, newc
131131
if !isassigned(newc, ind)
132132
newc[ind] = c
133133
elseif c != newc[ind]
@@ -146,7 +146,7 @@ function concat_chunksize(parents)
146146
init = RegularChunks(approx_chunksize(first(v)), 0, 0)
147147
reduce(mergechunks, v; init=init)
148148
end
149-
extenddims(newchunks, size(parents), RegularChunks(1,0,1))
149+
extenddims(newchunks, size(parents), RegularChunks(1, 0, 1))
150150
return GridChunks(newchunks...)
151151
end
152152

src/diskarray.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ The only function that should be implemented by a `AbstractDiskArray`. This func
2323
"""
2424
function readblock! end
2525

26+
function readblock!(a::AbstractArray, aout, r...)
27+
# Fallback implementation for arrays that are not DiskArrays
28+
if isdisk(a)
29+
@warn "Using fallback readblock! for array $(typeof(a)). This should not happen but there should be a custom implementation."
30+
end
31+
copyto!(aout, CartesianIndices(aout), a, CartesianIndices(r))
32+
end
33+
2634
"""
2735
writeblock!(A::AbstractDiskArray, A_in, r::AbstractUnitRange...)
2836

0 commit comments

Comments
 (0)