21
21
function ConcatDiskArray (arrays:: AbstractArray{<:AbstractArray{<:Any,N},M} ) where {N,M}
22
22
T = mapreduce (eltype, promote_type, init= eltype (first (arrays)), arrays)
23
23
24
- function othersize (x, id)
25
- return (x[1 : (id- 1 )]. .. , x[(id+ 1 ): end ]. .. )
26
- end
27
24
if N > M
28
- newshape = (size (arrays)... , ntuple (_ -> 1 , N - M)... )
25
+ newshape = extenddims (size (arrays), size (first (arrays)))
26
+ @show newshape
29
27
arrays1 = reshape (arrays, newshape)
30
28
D = N
31
- elseif N < M
32
- arrays1 = map (arrays) do a
33
- newshape = (size (a)... , ntuple (_ -> 1 , M - N)... )
34
- reshape (a, newshape)
35
- end
36
- D = M
37
29
else
38
30
arrays1 = arrays
39
31
D = M
40
32
end
41
- arraysizes = map (size, arrays1)
42
- si = ntuple (D) do id
43
- a = reduce (arraysizes; dims= id, init= ntuple (zero, D)) do i, j
44
- if all (iszero, i)
45
- j
46
- elseif othersize (i, id) == othersize (j, id)
47
- j
48
- else
49
- error (" Dimension sizes don't match" )
50
- end
51
- end
52
- I = ntuple (D) do i
53
- i == id ? Colon () : 1
54
- end
55
- ari = map (i -> i[id], arraysizes[I... ])
56
- sl = sum (ari)
57
- r = cumsum (ari)
58
- pop! (pushfirst! (r, 0 ))
59
- r .+ 1 , sl
60
- end
61
-
62
- startinds = map (first, si)
63
- sizes = map (last, si)
33
+ startinds, sizes = arraysize_and_startinds (arrays1)
34
+ @show startinds, sizes
64
35
65
36
chunks = concat_chunksize (D, arrays1)
66
37
hc = Chunked (batchstrategy (chunks))
@@ -73,9 +44,35 @@ function ConcatDiskArray(arrays::AbstractArray)
73
44
error (" Arrays don't have the same dimensions" )
74
45
return error (" Should not be reached" )
75
46
end
47
+ extenddims (a:: NTuple{N,Int} ,b:: NTuple{M,Int} ) where {N,M} = extenddims ((a... ,1 ), b)
48
+ extenddims (a:: NTuple{N,Int} ,b:: NTuple{N,Int} ) where {N} = a
76
49
77
50
Base. size (a:: ConcatDiskArray ) = a. size
78
51
52
+ function arraysize_and_startinds (arrays1)
53
+ sizes = map (i-> zeros (Int,i),size (arrays1))
54
+ for i in CartesianIndices (arrays1)
55
+ ai = arrays1[i]
56
+ sizecur = size (ai)
57
+ foreach (sizecur,i. I,sizes) do si, ind, sizeall
58
+ if sizeall[ind] == 0
59
+ # init the size
60
+ sizeall[ind] = si
61
+ elseif sizeall[ind] != si
62
+ throw (ArgumentError (" Array sizes don't form a grid" ))
63
+ end
64
+ end
65
+ end
66
+ r = map (sizes) do sizeall
67
+ pushfirst! (sizeall, 1 )
68
+ for i in 2 : length (sizeall)
69
+ sizeall[i] = sizeall[i- 1 ]+ sizeall[i]
70
+ end
71
+ pop! (sizeall)- 1 ,sizeall
72
+ end
73
+ map (last, r), map (first, r)
74
+ end
75
+
79
76
# DiskArrays interface
80
77
81
78
eachchunk (a:: ConcatDiskArray ) = a. chunks
0 commit comments