4
4
5
5
Joins multiple AbstractArrays or AbstractDiskArrays in lazy concatination.
6
6
"""
7
- struct ConcatDiskArray{T,N,P} <: AbstractDiskArray{T,N}
7
+ struct ConcatDiskArray{T,N,P,C,HC } <: AbstractDiskArray{T,N}
8
8
parents:: P
9
9
startinds:: NTuple{N,Vector{Int}}
10
10
size:: NTuple{N,Int}
11
+ chunks:: C
12
+ haschunks:: HC
11
13
end
12
- function ConcatDiskArray (arrays:: AbstractArray{<:AbstractArray{T,N},M} ) where {T,N,M}
14
+ function ConcatDiskArray (arrays:: AbstractArray{<:AbstractArray{<:Any,N},M} ) where {N,M}
15
+ T = mapreduce (eltype,promote_type, init = eltype (first (arrays)),arrays)
16
+
13
17
function othersize (x, id)
14
18
return (x[1 : (id - 1 )]. .. , x[(id + 1 ): end ]. .. )
15
19
end
@@ -51,12 +55,13 @@ function ConcatDiskArray(arrays::AbstractArray{<:AbstractArray{T,N},M}) where {T
51
55
startinds = map (first, si)
52
56
sizes = map (last, si)
53
57
54
- return ConcatDiskArray {T,D,typeof(arrays1)} (arrays1, startinds, sizes)
58
+ chunks = concat_chunksize (D, arrays1)
59
+ hc = Chunked (batchstrategy (chunks))
60
+
61
+ return ConcatDiskArray {T,D,typeof(arrays1),typeof(chunks),typeof(hc)} (arrays1, startinds, sizes, chunks, hc)
55
62
end
56
63
function ConcatDiskArray (arrays:: AbstractArray )
57
64
# Validate array eltype and dimensionality
58
- all (a -> eltype (a) == eltype (first (arrays)), arrays) ||
59
- error (" Arrays don't have the same element type" )
60
65
all (a -> ndims (a) == ndims (first (arrays)), arrays) ||
61
66
error (" Arrays don't have the same dimensions" )
62
67
return error (" Should not be reached" )
@@ -98,11 +103,10 @@ function _concat_diskarray_block_io(f, a::ConcatDiskArray, inds...)
98
103
end
99
104
end
100
105
101
- haschunks (:: ConcatDiskArray ) = Chunked ()
106
+ haschunks (c :: ConcatDiskArray ) = c . haschunks
102
107
103
- function eachchunk (aconc:: ConcatDiskArray{T,N} ) where {T,N}
104
- s = size (aconc)
105
- oldchunks = map (eachchunk, aconc. parents)
108
+ function concat_chunksize (N, parents)
109
+ oldchunks = map (eachchunk, parents)
106
110
newchunks = ntuple (N) do i
107
111
sliceinds = Base. setindex (ntuple (_ -> 1 , N), :, i)
108
112
v = map (c -> c. chunks[i], oldchunks[sliceinds... ])
@@ -113,6 +117,10 @@ function eachchunk(aconc::ConcatDiskArray{T,N}) where {T,N}
113
117
return GridChunks (newchunks... )
114
118
end
115
119
120
+ function eachchunk (aconc:: ConcatDiskArray{T,N} ) where {T,N}
121
+ aconc. chunks
122
+ end
123
+
116
124
function mergechunks (a:: RegularChunks , b:: RegularChunks )
117
125
if a. s == 0 || (a. cs == b. cs && length (last (a)) == a. cs)
118
126
RegularChunks (a. cs, a. offset, a. s + b. s)
0 commit comments