@@ -42,16 +42,16 @@ function ConcatDiskArray(arrays::AbstractArray)
42
42
error (" Arrays don't have the same dimensions" )
43
43
return error (" Should not be reached" )
44
44
end
45
- extenddims (a:: NTuple{N} , b:: NTuple{M} , fillval) where {N,M} = extenddims ((a... ,fillval), b, fillval)
46
- extenddims (a:: NTuple{N} , _:: NTuple{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
47
47
48
48
Base. size (a:: ConcatDiskArray ) = a. size
49
49
50
50
function arraysize_and_startinds (arrays1)
51
51
sizes = map (i-> zeros (Int,i),size (arrays1))
52
52
for i in CartesianIndices (arrays1)
53
53
ai = arrays1[i]
54
- sizecur = size (ai)
54
+ sizecur = extenddims ( size (ai), size (arrays1), 1 )
55
55
foreach (sizecur,i. I,sizes) do si, ind, sizeall
56
56
if sizeall[ind] == 0
57
57
# init the size
@@ -79,12 +79,14 @@ haschunks(c::ConcatDiskArray) = c.haschunks
79
79
function readblock! (a:: ConcatDiskArray , aout, inds:: AbstractUnitRange... )
80
80
# Find affected blocks and indices in blocks
81
81
_concat_diskarray_block_io (a, inds... ) do outer_range, array_range, I
82
- aout[outer_range... ] = a. parents[I][array_range... ]
82
+ vout = view (aout, outer_range... )
83
+ readblock! (a. parents[I], vout, array_range... )
83
84
end
84
85
end
85
86
function writeblock! (a:: ConcatDiskArray , aout, inds:: AbstractUnitRange... )
86
87
_concat_diskarray_block_io (a, inds... ) do outer_range, array_range, I
87
- a. parents[I][array_range... ] = aout[outer_range... ]
88
+ data = view (aout, outer_range... )
89
+ writeblock! (a. parents[I], data, array_range)
88
90
end
89
91
end
90
92
@@ -99,17 +101,26 @@ function _concat_diskarray_block_io(f, a::ConcatDiskArray, inds...)
99
101
end
100
102
map (CartesianIndices (blockinds)) do cI
101
103
myar = a. parents[cI]
102
- mysize = size (myar)
104
+ mysize = extenddims ( size (myar), cI . I, 1 )
103
105
array_range = map (cI. I, a. startinds, mysize, inds) do ii, si, ms, indstoread
104
106
max (first (indstoread) - si[ii] + 1 , 1 ): min (last (indstoread) - si[ii] + 1 , ms)
105
107
end
106
108
outer_range = map (cI. I, a. startinds, array_range, inds) do ii, si, ar, indstoread
107
109
(first (ar)+ si[ii]- first (indstoread)): (last (ar)+ si[ii]- first (indstoread))
108
110
end
109
- # aout[outer_range...] = a.parents[cI][array_range...]
111
+ # Shorten array range to shape of actual array
112
+ array_range = map ((i, j) -> j, size (myar), array_range)
113
+ outer_range = fix_outerrangeshape (outer_range, array_range)
110
114
f (outer_range, array_range, cI)
111
115
end
112
116
end
117
+ fix_outerrangeshape (outer_range, array_range) = fix_outerrangeshape ((), outer_range, array_range)
118
+ fix_outerrangeshape (res, outer_range, array_range) =
119
+ fix_outerrangeshape ((res... , first (outer_range)), Base. tail (outer_range), Base. tail (array_range))
120
+ fix_outerrangeshape (res, outer_range, :: Tuple{} ) =
121
+ fix_outerrangeshape ((res... , only (first (outer_range))), Base. tail (outer_range), ())
122
+ fix_outerrangeshape (res, :: Tuple{} , :: Tuple{} ) = res
123
+
113
124
114
125
function concat_chunksize (parents)
115
126
newchunks = map (s-> Vector {Union{RegularChunks, IrregularChunks}} (undef, s) ,size (parents))
@@ -125,6 +136,13 @@ function concat_chunksize(parents)
125
136
end
126
137
end
127
138
newchunks = map (newchunks) do v
139
+ # Chunks that have not been set are from additional dimensions in the parent array shape
140
+ for i in eachindex (v)
141
+ if ! isassigned (v, i)
142
+ v[i] = RegularChunks (1 , 0 , 1 )
143
+ end
144
+ end
145
+ # Merge the chunks
128
146
init = RegularChunks (approx_chunksize (first (v)), 0 , 0 )
129
147
reduce (mergechunks, v; init= init)
130
148
end
0 commit comments