@@ -14,6 +14,29 @@ RepeatedRangeMatrix{T}(r::Range{T}, at::AbstractVector{T}) = RepeatedRangeMatrix
14
14
Base. size (R:: RepeatedRangeMatrix ) = (length (R. r), length (R. at))
15
15
@compat Base. IndexStyle (:: Type{<:RepeatedRangeMatrix} ) = IndexCartesian ()
16
16
17
+ # This coupled iteration over the two fields is 10-20x faster than Cartesian iteration
18
+ @inline function Base. start (R:: RepeatedRangeMatrix )
19
+ is = start (R. r)
20
+ idone = done (R. r, is)
21
+ js = start (R. at)
22
+ jdone = done (R. at, js)
23
+ return (idone | jdone) ? ((one (eltype (R. r)), is), (one (eltype (R. at)), js), true ) :
24
+ (next (R. r, is), next (R. at, js), false )
25
+ end
26
+ @inline function Base. next (R:: RepeatedRangeMatrix , state)
27
+ (i, is), (j, js), _ = state
28
+ val = i + j
29
+ if done (R. r, is)
30
+ if done (R. at, js)
31
+ return (val, ((i, is), (j, js), true ))
32
+ end
33
+ is = start (R. r)
34
+ j, js = next (R. at, js)
35
+ end
36
+ return (val, (next (R. r, is), (j, js), false ))
37
+ end
38
+ @inline Base. done (R:: RepeatedRangeMatrix , state) = state[end ]
39
+
17
40
# Scalar indexing
18
41
@inline function Base. getindex (R:: RepeatedRangeMatrix , i:: Int , j:: Int )
19
42
@boundscheck checkbounds (R, i, j)
0 commit comments