@@ -52,7 +52,13 @@ DiskIndex(a, i::Tuple{<:AbstractVector{<:Integer}}, batchstrategy) =
5252function _resolve_indices (chunks, i, indices_pre:: DiskIndex , strategy:: BatchStrategy )
5353 inow = first (i)
5454 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)
5662end
5763_resolve_indices (:: Tuple{} , :: Tuple{} , indices:: DiskIndex , strategy:: BatchStrategy ) = indices
5864# No dimension left in array, only singular indices allowed
@@ -61,17 +67,25 @@ function _resolve_indices(::Tuple{}, i, indices_pre::DiskIndex, strategy::BatchS
6167 (length (inow) == 1 && only (inow) == 1 ) || throw (ArgumentError (" Trailing indices must be 1" ))
6268 indices_new = DiskIndex (size (inow), (), size (inow), (), ())
6369 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)
6577end
6678# Still dimensions left, but no indices available
6779function _resolve_indices (chunks, :: Tuple{} , indices_pre:: DiskIndex , strategy:: BatchStrategy )
6880 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))
7082 indices_new = add_dimension_index (strategy)
7183 indices = merge_index (indices_pre, indices_new)
72- _resolve_indices (Base . tail (chunks), (), indices, strategy)
84+ _resolve_indices (tail (chunks), (), indices, strategy)
7385end
7486
87+ checktrailing (i) = i == 1 || throw (ArgumentError (" Indices can only be omitted for trailing singleton dimensions" ))
88+
7589add_dimension_index (:: NoBatch ) = DiskIndex ((), (1 ,), (), (1 ,), (1 : 1 ,))
7690add_dimension_index (:: Union{ChunkRead,SubRanges} ) = DiskIndex ((), (1 ,), ([()],), ([(1 ,)],), ([(1 : 1 ,)],))
7791
@@ -98,18 +112,24 @@ Calculate indices for `i` the first chunk/s in `chunks`
98112Returns a [`DiskIndex`](@ref), and the remaining chunks.
99113"""
100114process_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)
102122function process_index (:: Colon , chunks)
103123 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)
105125end
106126function 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)
108128end
109129function process_index (i:: AbstractArray{<:Integer} , chunks, :: NoBatch )
110130 indmin, indmax = isempty (i) ? (1 , 0 ) : extrema (i)
111131 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)
113133end
114134function process_index (i:: AbstractArray{Bool,N} , chunks, :: NoBatch ) where {N}
115135 chunksnow, chunksrem = splitchunks (i, chunks)
@@ -162,7 +182,12 @@ splitchunks(i::CartesianIndex, chunks) = splitchunks(i.I, (), chunks)
162182splitchunks (_, chunks) = (first (chunks),), Base. tail (chunks)
163183splitchunks (si, chunksnow, chunksrem) =
164184 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
165189splitchunks (:: Tuple{} , chunksnow, chunksrem) = (chunksnow, chunksrem)
190+ splitchunks (:: Tuple{} , chunksnow, chunksrem:: Tuple{} ) = (chunksnow, chunksrem)
166191
167192"""
168193 output_aliasing(di::DiskIndex, ndims_dest, ndims_source)
0 commit comments