@@ -52,7 +52,13 @@ DiskIndex(a, i::Tuple{<:AbstractVector{<:Integer}}, batchstrategy) =
52
52
function _resolve_indices (chunks, i, indices_pre:: DiskIndex , strategy:: BatchStrategy )
53
53
inow = first (i)
54
54
indices_new, chunksrem = process_index (inow, chunks, strategy)
55
- _resolve_indices (chunksrem, Base. tail (i), merge_index (indices_pre, indices_new), strategy)
55
+ _resolve_indices (chunksrem, tail (i), merge_index (indices_pre, indices_new), strategy)
56
+ end
57
+ # Splat out CartesianIndex as regular indices
58
+ function _resolve_indices (
59
+ chunks, i:: Tuple{<:CartesianIndex} , indices_pre:: DiskIndex , strategy:: BatchStrategy
60
+ )
61
+ _resolve_indices (chunks, (Tuple (i[1 ])... , tail (i)... ), indices_pre, strategy)
56
62
end
57
63
_resolve_indices (:: Tuple{} , :: Tuple{} , indices:: DiskIndex , strategy:: BatchStrategy ) = indices
58
64
# No dimension left in array, only singular indices allowed
@@ -61,17 +67,25 @@ function _resolve_indices(::Tuple{}, i, indices_pre::DiskIndex, strategy::BatchS
61
67
(length (inow) == 1 && only (inow) == 1 ) || throw (ArgumentError (" Trailing indices must be 1" ))
62
68
indices_new = DiskIndex (size (inow), (), size (inow), (), ())
63
69
indices = merge_index (indices_pre, indices_new)
64
- _resolve_indices ((), Base. tail (i), indices, strategy)
70
+ _resolve_indices ((), tail (i), indices, strategy)
71
+ end
72
+ # Splat out CartesianIndex as regular trailing indices
73
+ function _resolve_indices (
74
+ :: Tuple{} , i:: Tuple{<:CartesianIndex} , indices_pre:: DiskIndex , strategy:: BatchStrategy
75
+ )
76
+ _resolve_indices ((), (Tuple (i[1 ])... , tail (i)... ), indices_pre, strategy)
65
77
end
66
78
# Still dimensions left, but no indices available
67
79
function _resolve_indices (chunks, :: Tuple{} , indices_pre:: DiskIndex , strategy:: BatchStrategy )
68
80
chunksnow = first (chunks)
69
- arraysize_from_chunksize (chunksnow) == 1 || throw ( ArgumentError ( " Indices can only be omitted for trailing singleton dimensions " ))
81
+ checktrailing ( arraysize_from_chunksize (chunksnow))
70
82
indices_new = add_dimension_index (strategy)
71
83
indices = merge_index (indices_pre, indices_new)
72
- _resolve_indices (Base . tail (chunks), (), indices, strategy)
84
+ _resolve_indices (tail (chunks), (), indices, strategy)
73
85
end
74
86
87
+ checktrailing (i) = i == 1 || throw (ArgumentError (" Indices can only be omitted for trailing singleton dimensions" ))
88
+
75
89
add_dimension_index (:: NoBatch ) = DiskIndex ((), (1 ,), (), (1 ,), (1 : 1 ,))
76
90
add_dimension_index (:: Union{ChunkRead,SubRanges} ) = DiskIndex ((), (1 ,), ([()],), ([(1 ,)],), ([(1 : 1 ,)],))
77
91
@@ -98,18 +112,24 @@ Calculate indices for `i` the first chunk/s in `chunks`
98
112
Returns a [`DiskIndex`](@ref), and the remaining chunks.
99
113
"""
100
114
process_index (i, chunks, :: NoBatch ) = process_index (i, chunks)
101
- process_index (inow:: Integer , chunks) = DiskIndex ((), (1 ,), (), (1 ,), (inow: inow,)), Base. tail (chunks)
115
+ function process_index (i:: CartesianIndex{N} , chunks, :: NoBatch ) where {N}
116
+ _, chunksrem = splitchunks (i, chunks)
117
+ di = DiskIndex ((), map (one, i. I), (), (1 ,), map (i -> i: i, i. I))
118
+ return di, chunksrem
119
+ end
120
+ process_index (inow:: Integer , chunks) =
121
+ DiskIndex ((), (1 ,), (), (1 ,), (inow: inow,)), tail (chunks)
102
122
function process_index (:: Colon , chunks)
103
123
s = arraysize_from_chunksize (first (chunks))
104
- DiskIndex ((s,), (s,), (Colon (),), (Colon (),), (1 : s,),), Base . tail (chunks)
124
+ DiskIndex ((s,), (s,), (Colon (),), (Colon (),), (1 : s,),), tail (chunks)
105
125
end
106
126
function process_index (i:: AbstractUnitRange{<:Integer} , chunks, :: NoBatch )
107
- DiskIndex ((length (i),), (length (i),), (Colon (),), (Colon (),), (i,)), Base . tail (chunks)
127
+ DiskIndex ((length (i),), (length (i),), (Colon (),), (Colon (),), (i,)), tail (chunks)
108
128
end
109
129
function process_index (i:: AbstractArray{<:Integer} , chunks, :: NoBatch )
110
130
indmin, indmax = isempty (i) ? (1 , 0 ) : extrema (i)
111
131
di = DiskIndex (size (i), ((indmax - indmin + 1 ),), map (_ -> Colon (), size (i)), ((i .- (indmin - 1 )),), (indmin: indmax,))
112
- return di, Base . tail (chunks)
132
+ return di, tail (chunks)
113
133
end
114
134
function process_index (i:: AbstractArray{Bool,N} , chunks, :: NoBatch ) where {N}
115
135
chunksnow, chunksrem = splitchunks (i, chunks)
@@ -162,7 +182,12 @@ splitchunks(i::CartesianIndex, chunks) = splitchunks(i.I, (), chunks)
162
182
splitchunks (_, chunks) = (first (chunks),), Base. tail (chunks)
163
183
splitchunks (si, chunksnow, chunksrem) =
164
184
splitchunks (Base. tail (si), (chunksnow... , first (chunksrem)), Base. tail (chunksrem))
185
+ function splitchunks (si,chunksnow, :: Tuple{} )
186
+ only (first (si)) == 1 || throw (ArgumentError (" Trailing indices must be 1" ))
187
+ splitchunks (Base. tail (si), chunksnow, ())
188
+ end
165
189
splitchunks (:: Tuple{} , chunksnow, chunksrem) = (chunksnow, chunksrem)
190
+ splitchunks (:: Tuple{} , chunksnow, chunksrem:: Tuple{} ) = (chunksnow, chunksrem)
166
191
167
192
"""
168
193
output_aliasing(di::DiskIndex, ndims_dest, ndims_source)
0 commit comments