Skip to content

Commit 8a1785f

Browse files
authored
fix rand(::AbstractRange{Int64}) (#402)
1 parent b18f78a commit 8a1785f

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "OpenCL"
22
uuid = "08131aa3-fb12-5dee-8b74-c09406e224a2"
3-
version = "0.10.6"
3+
version = "0.10.7"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/device/random.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,6 @@ end
232232
@device_override @inline function Random.randexp(rng::AbstractRNG, ::Type{T}) where {T <: Union{Float16, Float32}}
233233
@invoke Random.randexp(rng::AbstractRNG, T::Type{<:AbstractFloat})
234234
end
235+
236+
@device_override Random.Sampler(::Type{<:AbstractRNG}, r::AbstractUnitRange{T},
237+
::Random.Repetition) where {T<:Union{Int64, UInt64}} = Random.SamplerRangeFast(r)

test/device/random.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,24 @@ end
135135
@test Array(a) == Array(b)
136136
end
137137
end
138+
139+
@testset "rand(::AbstractRange{$T}), seed $seed" for T in (Int32, Int64, UInt32, UInt64), seed in (nothing, #=missing,=# 1234)
140+
function kernel(A::AbstractArray{T}, seed) where {T}
141+
apply_seed(seed)
142+
tid = get_global_id(1)
143+
A[tid] = rand(T(10):T(20))
144+
return
145+
end
146+
147+
a = OpenCL.zeros(T, n)
148+
b = OpenCL.zeros(T, n)
149+
150+
@opencl global_size=n local_size=n kernel(a, seed)
151+
@opencl global_size=n local_size=n kernel(b, seed)
152+
153+
if seed === nothing || seed === missing
154+
@test Array(a) != Array(b)
155+
else
156+
@test Array(a) == Array(b)
157+
end
158+
end

0 commit comments

Comments
 (0)