@@ -4,19 +4,19 @@ import Base.MultiplicativeInverses: SignedMultiplicativeInverse
4
4
5
5
# CartesianIndex uses Int instead of Int32
6
6
7
- @eval EmptySMI () = $ (Expr (:new , SignedMultiplicativeInverse{Int32}, Int32 (0 ), typemax (Int32), 0 % Int8, 0 % UInt8))
7
+ @eval EmptySMI () = $ (Expr (:new , SignedMultiplicativeInverse{Int32}, Int32 (0 ), typemax (Int32), 0 % Int8, 0 % UInt8))
8
8
SMI (i) = i == 0 ? EmptySMI () : SignedMultiplicativeInverse {Int32} (i)
9
9
10
10
struct FastCartesianIndices{N} <: AbstractArray{CartesianIndex{N}, N}
11
11
inverses:: NTuple{N, SignedMultiplicativeInverse{Int32}}
12
12
end
13
13
14
- function FastCartesianIndices (indices:: NTuple{N} ) where N
15
- inverses = map (i-> SMI (Int32 (i)), indices)
14
+ function FastCartesianIndices (indices:: NTuple{N} ) where {N}
15
+ inverses = map (i -> SMI (Int32 (i)), indices)
16
16
FastCartesianIndices (inverses)
17
17
end
18
18
19
- function Base. size (FCI:: FastCartesianIndices{N} ) where N
19
+ function Base. size (FCI:: FastCartesianIndices{N} ) where {N}
20
20
ntuple (Val (N)) do I
21
21
FCI. inverses[I]. divisor
22
22
end
26
26
return CartesianIndex ()
27
27
end
28
28
29
- @inline function Base. getindex (iter:: FastCartesianIndices{N} , I:: Vararg{Int, N} ) where N
29
+ @inline function Base. getindex (iter:: FastCartesianIndices{N} , I:: Vararg{Int, N} ) where {N}
30
30
@boundscheck checkbounds (iter, I... )
31
31
index = map (iter. inverses, I) do inv, i
32
32
@inbounds getindex (Base. OneTo (inv. divisor), i)
33
33
end
34
34
CartesianIndex (index)
35
35
end
36
36
37
- _ind2sub_recuse (:: Tuple{} , ind) = (ind+ 1 ,)
37
+ _ind2sub_recuse (:: Tuple{} , ind) = (ind + 1 ,)
38
38
function _ind2sub_recurse (indslast:: NTuple{1} , ind)
39
- @inline
39
+ Base . @_inline_meta
40
40
(_lookup (ind, indslast[1 ]),)
41
41
end
42
42
43
43
function _ind2sub_recurse (inds, ind)
44
- @inline
44
+ Base . @_inline_meta
45
45
inv = inds[1 ]
46
46
indnext, f, l = _div (ind, inv)
47
- (ind- l * indnext+ f, _ind2sub_recurse (Base. tail (inds), indnext)... )
47
+ (ind - l * indnext + f, _ind2sub_recurse (Base. tail (inds), indnext)... )
48
48
end
49
49
50
- _lookup (ind, inv:: SignedMultiplicativeInverse ) = ind+ 1
50
+ _lookup (ind, inv:: SignedMultiplicativeInverse ) = ind + 1
51
51
function _div (ind, inv:: SignedMultiplicativeInverse )
52
52
inv. divisor == 0 && throw (DivideError ())
53
- div (ind% Int32, inv), 1 , inv. divisor
53
+ div (ind % Int32, inv), 1 , inv. divisor
54
54
end
55
55
56
56
function Base. _ind2sub (inv:: FastCartesianIndices , ind)
57
- @inline
58
- _ind2sub_recurse (inv. inverses, ind- 1 )
57
+ Base . @_inline_meta
58
+ _ind2sub_recurse (inv. inverses, ind - 1 )
59
59
end
60
60
61
61
export _Size, StaticSize, DynamicSize, get
@@ -151,24 +151,7 @@ Base.length(range::NDRange) = length(blocks(range))
151
151
end
152
152
153
153
Base. @propagate_inbounds function expand (ndrange:: NDRange{N} , groupidx:: Integer , idx:: Integer ) where {N}
154
- # This causes two sdiv operations, one for each Linear to CartesianIndex
155
154
return expand (ndrange, blocks (ndrange)[groupidx], workitems (ndrange)[idx])
156
-
157
- # The formulation below saves one sdiv
158
- # but leads to a different index order...
159
- # previous: julia> expand(ndrange, 1, 32*32)
160
- # CartesianIndex(32, 32)
161
- # now: julia> expand(ndrange, 1, 32*32)
162
- # CartesianIndex(1024, 1)
163
- # B = blocks(ndrange)::CartesianIndices
164
- # W = workitems(ndrange)::CartesianIndices
165
- # Ind = ntuple(Val(N)) do I
166
- # Base.@_inline_meta
167
- # b = B.indices[I]
168
- # w = W.indices[I]
169
- # length(b) * length(w)
170
- # end
171
- # CartesianIndices(Ind)[(groupidx-1)* prod(size(W)) + idx]
172
155
end
173
156
174
157
Base. @propagate_inbounds function expand (ndrange:: NDRange{N} , groupidx:: CartesianIndex{N} , idx:: Integer ) where {N}
0 commit comments