-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Rather than calling rand(...)
, it would be good to call rand(rng, ...)
with an optionally user-specified rng::AbstractRNG
keyword argument in algorithms that require pseudo-random initialization, e.g. lobpcg (
IterativeSolvers.jl/src/lobpcg.jl
Line 872 in ae01dfe
@inbounds X[:,j] .= rand.() |
IterativeSolvers.jl/src/bicgstabl.jl
Line 38 in ae01dfe
r_shadow = rand(T, n) |
IterativeSolvers.jl/src/bicgstabl.jl
Line 38 in ae01dfe
r_shadow = rand(T, n) |
Rationale: if deterministic results are desired (as is often the case), it is better for the user to be able to specify an RNG than setting the global Random.seed!
.
Moreover, arguably the default rng should be a new deterministic RNG object created with a fixed seed every time the iterative solver is initialized, so that the algorithm defaults to being deterministic.
(Note: "deterministic" ≠ "reproducible" … e.g. changing the Julia version could change the results. But it is useful to be able to run the same code with the same software on the same hardware multiple times and get exactly the same results as much as possible.)