50
50
xor (x, x >> 1 i32)
51
51
end
52
52
53
- @inline function bisect_range (index:: I , lo:: I , n:: I ) where I
53
+ @inline function bisect_range (index:: I , lo:: I , n:: I ) where {I}
54
54
if n <= one (I)
55
55
return - one (I), - one (I)
56
56
end
64
64
return lo, n
65
65
end
66
66
67
- @inline function rev_lt (a :: T , b :: T , lt, rev :: Val{R} ) where {T,R}
67
+ @inline function rev_lt (a:: T , b:: T , lt, rev:: Val{R} ) where {T,R}
68
68
if R
69
69
return lt (b, a)
70
70
else
71
71
return lt (a, b)
72
72
end
73
73
end
74
74
75
- @inline function rev_lt (a :: Tuple{T, J} , b :: Tuple{T, J} , lt, rev :: Val{R} ) where {T, J, R}
75
+ @inline function rev_lt (a:: Tuple{T,J} , b:: Tuple{T,J} , lt, rev:: Val{R} ) where {T,J, R}
76
76
if R
77
77
if a[1 ] == b[1 ]
78
78
return a[2 ] < b[2 ]
94
94
end
95
95
end
96
96
97
- @inline function compare! (vals_inds:: Tuple , i1:: I , i2:: I , dir:: Bool , by, lt, rev) where I
97
+ @inline function compare! (vals_inds:: Tuple , i1:: I , i2:: I , dir:: Bool , by, lt, rev) where {I}
98
98
i1′, i2′ = i1 + one (I), i2 + one (I)
99
99
vals, inds = vals_inds
100
100
# comparing tuples of (value, index) guarantees stability of sort
104
104
end
105
105
106
106
107
- @inline function get_range_part1 (n:: I , index:: I , k:: I ):: Tuple{I,I,Bool} where I
107
+ @inline function get_range_part1 (n:: I , index:: I , k:: I ):: Tuple{I,I,Bool} where {I}
108
108
lo = zero (I)
109
109
dir = true
110
110
for iter = one (I): k- one (I)
123
123
return lo, n, dir
124
124
end
125
125
126
- @inline function get_range_part2 (lo:: I , n:: I , index:: I , j:: I ):: Tuple{I,I} where I
126
+ @inline function get_range_part2 (lo:: I , n:: I , index:: I , j:: I ):: Tuple{I,I} where {I}
127
127
for iter = one (I): j- one (I)
128
128
lo, n = bisect_range (index, lo, n)
129
129
end
175
175
end
176
176
end
177
177
178
- @inline function compare_small! (vals_inds:: Tuple , i1:: I , i2:: I , dir:: Bool , by, lt, rev) where I
178
+ @inline function compare_small! (vals_inds:: Tuple , i1:: I , i2:: I , dir:: Bool , by, lt, rev) where {I}
179
179
i1′, i2′ = i1 + one (I), i2 + one (I)
180
180
vals, inds = vals_inds
181
181
# comparing tuples of (value, index) guarantees stability of sort
@@ -192,7 +192,7 @@ all threads perform swaps accessible using shmem.
192
192
193
193
Various negative exit values just for debugging.
194
194
"""
195
- @inline function block_range (n:: I , block_index:: I , k:: I , j:: I ):: Tuple{I,I,Bool} where I
195
+ @inline function block_range (n:: I , block_index:: I , k:: I , j:: I ):: Tuple{I,I,Bool} where {I}
196
196
lo = zero (I)
197
197
dir = true
198
198
tmp = block_index * two (I)
252
252
For sortperm/sortperm!, allocate and return shared memory views of `c` and index
253
253
array. Each view is indexed along block x dim: one view per pseudo-block
254
254
"""
255
- @inline function initialize_shmem! (
256
- vals_inds:: Tuple{AbstractArray{T},AbstractArray{J}} ,
257
- index,
258
- in_range,
259
- ) where {T,J}
255
+ @inline function initialize_shmem! (vals_inds:: Tuple{AbstractArray{T},AbstractArray{J}} , index, in_range) where {T,J}
260
256
# NB: I tried creating both shmem arrays with `initialize_shmem!`
261
257
# but the behavior changed - maybe it's necessary to alloc both before
262
258
# writing to either?
275
271
"""
276
272
For sort/sort!, copy shmem view `swap` back into global array `c`
277
273
"""
278
- @inline function finalize_shmem! (vals:: AbstractArray , swap:: AbstractArray , index:: I , in_range:: Bool ) where I
274
+ @inline function finalize_shmem! (vals:: AbstractArray , swap:: AbstractArray , index:: I , in_range:: Bool ) where {I}
279
275
if in_range
280
276
@inbounds vals[index+ one (I)] = swap[threadIdx (). x]
281
277
end
@@ -348,7 +344,7 @@ of values and an index array for doing `sortperm!`. Cannot provide a stable
348
344
`sort!` although `sortperm!` is properly stable. To reverse, set `rev=true`
349
345
rather than `lt=!isless` (otherwise stability of sortperm breaks down).
350
346
"""
351
- function bitonic_sort! (c; by = identity, lt = isless, rev= false ) where {T}
347
+ function bitonic_sort! (c; by = identity, lt = isless, rev = false ) where {T}
352
348
c_len = if typeof (c) <: Tuple
353
349
length (c[1 ])
354
350
else
0 commit comments