Skip to content
This repository was archived by the owner on Dec 16, 2024. It is now read-only.

Commit 00452cd

Browse files
authored
reset GLOBAL_RNG state in/out at-testset for reproducibility (#24445)
This is a follow-up on the recently introduced `guardsrand` functionality, first suggested at JuliaLang/julia#16940 (comment). Each `testset` block is now implicitly wrapped in a `guardsrand` block, which is more user-friendly and more systematic (only few users know about `guardsrand`). These are essentially two new features: 1) "in": in base, tests are run with the global RNG randomly seeded, but the seed is printed in case of failure to allow reproducing the failure; but even if the failure occurs after many tests, when they alter the global RNG state, one has to re-run the whole file, which can be time-consuming; with this change, at the beginning of each `testset`, the global RNG is re-seeded with its own seed: this allows to re-run only the failing `testset`, which can be done easily in the REPL (the seeding occurs for each loop in a `testset for`; this also allows to re-arrange `testset`s in arbitrary order w.r.t. the global RNG; 2) "out": a `testset` leaves no tracks of its use of `srand` or `rand` (this "feature" should be less and less needed/useful with the generalization of the use of `testset` blocks). Example: ``` @testset begin srand(123) rand() @testset for T in (Int, Float64) # here is an implicit srand(123), by 1) rand() end rand() # this value will not be affected if the sub-`testset` block # above is removed, or if another rand() call is added therein, by 2) end ``` Note that guardsrand can't be used directly, as then the testset's body is wrapped in a function, which causes problem with overwriting loop variable ("outer"), using `using`, defining new methods, etc. So we need to duplicate guardsrand's logic.
1 parent 8442312 commit 00452cd

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

SuiteSparse/test/cholmod.jl

+1
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ end
723723
end
724724

725725
@testset "Check that Symmetric{SparseMatrixCSC} can be constructed from CHOLMOD.Sparse" begin
726+
Int === Int32 && srand(124)
726727
A = sprandn(10, 10, 0.1)
727728
B = CHOLMOD.Sparse(A)
728729
C = B'B

0 commit comments

Comments
 (0)