Open
Description
why should this performance optimization not include all AbstractArrays{Float64}
s ? i haven't tested any changes to the Random stdlib, but simply looking at the code i think it should work for AbstractArray
s too, like this: randfun!(rng::MersenneTwister, A::AbstractArray{Float64})
.
the reason i ask, is that for testing purposes i need to generate the same random numbers with and without physical units using Unitful.jl. to do so, one currently must strip off the units using ustrip
, which uses reinterpret
, and hence returns a ReinterpretArray
, which then dispatches to the non-optimized code, leading to different random numbers.
julia> using Unitful, Random
julia> len=15;
julia> rng = MersenneTwister();
julia> a = zeros(len);
julia> Random.seed!(rng, 1);
julia> randn!(rng, ustrip(a))
15-element Vector{Float64}:
0.2972879845354616
0.3823959677906078
-0.5976344767282311
-0.01044524463737564
-0.839026854388764
0.31111133849833383
2.2950878238373105
0.40839583832475224
0.2290095549097807
-2.2670863488005306
0.5299655761667461
0.43142152642291204
0.5837082875687786
0.9632716050381906
0.45879095505371686
julia> ua = zeros(len) * 1u"s";
julia> Random.seed!(rng, 1);
julia> randn!(rng, ustrip(ua))
15-element reinterpret(Float64, ::Vector{Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}}):
0.2972879845354616
0.3823959677906078
-0.5976344767282311
-0.01044524463737564
-0.839026854388764
0.31111133849833383
2.2950878238373105
-2.2670863488005306
0.5299655761667461
0.43142152642291204
0.5837082875687786
0.9632716050381906
0.45879095505371686
-0.5223367574215084
0.40839583832475224
cc: @rfourquet