Skip to content

Commit eef661b

Browse files
authored
fix rand(::AbstractRange{Int64}) (#700)
Previously, the default method would widen to `Int128` causing compilation failures ref JuliaGPU/OpenCL.jl#402
1 parent ceb8267 commit eef661b

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 = "Metal"
22
uuid = "dde4c033-4e86-420c-a63e-0dd931031962"
3-
version = "1.9.0"
3+
version = "1.9.1"
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
@@ -181,3 +181,6 @@ end
181181
@device_override @inline function Random.randexp(rng::Philox2x32, ::Type{T}) where {T <: AbstractFloat}
182182
@invoke Random.randexp(rng::AbstractRNG, T::Type{<:AbstractFloat})
183183
end
184+
185+
@device_override Random.Sampler(::Type{<:AbstractRNG}, r::AbstractUnitRange{T},
186+
::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
@@ -125,3 +125,24 @@ end
125125
@test Array(a) == Array(b)
126126
end
127127
end
128+
129+
@testset "rand(::AbstractRange{$T}), seed $seed" for T in (Int32, Int64, UInt32, UInt64), seed in (nothing, #=missing,=# 1234)
130+
function kernel(A::AbstractArray{T}, seed) where {T}
131+
apply_seed(seed)
132+
tid = thread_position_in_grid().x
133+
A[tid] = rand(T(10):T(20))
134+
return
135+
end
136+
137+
a = Metal.zeros(T, n)
138+
b = Metal.zeros(T, n)
139+
140+
@metal threads=n kernel(a, seed)
141+
@metal threads=n kernel(b, seed)
142+
143+
if seed === nothing || seed === missing
144+
@test Array(a) != Array(b)
145+
else
146+
@test Array(a) == Array(b)
147+
end
148+
end

0 commit comments

Comments
 (0)