Mercurial > octave
changeset 32372:2c0dc2ac3d3b
Make random numbers in BISTs reproducible
Comparing fntests.log across different runs was difficult due to
large random arrays being printed for some known failures. This change
sets the random state for such instances that were being printed.
It also sets the random state as a non-shared variable so that it is
not printed, which would again cause difficulty comparing test runs.
* libinterp/corefcn/conv2.cc : set state
* lininterp/corefcn/gsvd.cc : set state
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Thu, 05 Oct 2023 17:14:53 -0400 |
parents | ff0859c6f361 |
children | 07e7a87dbeea |
files | libinterp/corefcn/conv2.cc libinterp/corefcn/gsvd.cc |
diffstat | 2 files changed, 40 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/conv2.cc Wed Sep 20 22:00:45 2023 +0200 +++ b/libinterp/corefcn/conv2.cc Thu Oct 05 17:14:53 2023 -0400 @@ -239,6 +239,9 @@ ## Test shapes %!shared A, B, C +%! old_state = rand ("state"); +%! restore_state = onCleanup (@() rand ("state", old_state)); +%! rand ("state", 12345); # initialize generator to make behavior reproducible %! A = rand (3, 4); %! B = rand (4); %! C = conv2 (A, B); @@ -248,6 +251,11 @@ %!assert (size (conv2 (B,A, "valid")), [2 1]) %!test +%!shared A, B, C +%! old_state = rand ("state"); +%! restore_state = onCleanup (@() rand ("state", old_state)); +%! rand ("state", 12345); # initialize generator to make behavior reproducible +%! A = rand (3, 4); %! B = rand (5); %! C = conv2 (A, B); %!assert (conv2 (A,B, "full"), C) @@ -419,6 +427,9 @@ ## the tests will be marked as known failures. %!shared a, b, c %! ## test 3D by 3D +%! old_state = rand ("state"); +%! restore_state = onCleanup (@() rand ("state", old_state)); +%! rand ("state", 12345); # initialize generator to make behavior reproducible %! a = rand (10, 10, 10); %! b = rand (3, 3, 3); %! c = convn (a, b, "full"); @@ -427,6 +438,9 @@ %! assert (convn (a, b, "valid"), c(3:10,3:10,3:10)); %! %!test +%! old_state = rand ("state"); +%! restore_state = onCleanup (@() rand ("state", old_state)); +%! rand ("state", 12345); # initialize generator to make behavior reproducible %! ## test 3D by 2D %! a = rand (10, 10, 10); %! b = rand (3, 3); @@ -436,6 +450,9 @@ %! assert (convn (a, b, "valid"), c(3:10,3:10,:)); %! %!test +%! old_state = rand ("state"); +%! restore_state = onCleanup (@() rand ("state", old_state)); +%! rand ("state", 12345); # initialize generator to make behavior reproducible %! ## test 2D by 3D %! a = rand (10, 10); %! b = rand (3, 3, 3); @@ -444,6 +461,9 @@ %!assert (convn (a, b, "valid"), c(3:10,3:10,3:2)) # a 7x7x0 matrix %! %!test +%! old_state = rand ("state"); +%! restore_state = onCleanup (@() rand ("state", old_state)); +%! rand ("state", 12345); # initialize generator to make behavior reproducible %! ## test multiple different number of dimensions, with odd and even numbers %! a = rand (10, 15, 7, 8, 10); %! b = rand (4, 3, 2, 3); @@ -557,18 +577,26 @@ %!assert (convn (a, b, "valid"), c(4,3:8,3:4,:)) ## test correct class -%!assert (class (convn (rand (5), rand (3))), "double") -%!assert (class (convn (rand (5, "single"), rand (3))), "single") -%!assert (class (convn (rand (5), rand (3, "single"))), "single") -%!assert (class (convn (true (5), rand (3))), "double") -%!assert (class (convn (true (5), rand (3, "single"))), "single") -%!assert (class (convn (ones (5, "uint8"), rand (3))), "double") -%!assert (class (convn (rand (3, "single"), ones (5, "uint8"))), "single") +%!shared a, b, c, d +%! old_state = rand ("state"); +%! restore_state = onCleanup (@() rand ("state", old_state)); +%! rand ("state", 12345); # initialize generator to make behavior reproducible +%! a = rand (5); +%! b = rand (3); +%! c = rand (5, "single"); +%! d = rand (3, "single"); +%!assert (class (convn (a, b)), "double") +%!assert (class (convn (c, b)), "single") +%!assert (class (convn (a, d)), "single") +%!assert (class (convn (true (5), b)), "double") +%!assert (class (convn (true (5), d)), "single") +%!assert (class (convn (ones (5, "uint8"), b)), "double") +%!assert (class (convn (d, ones (5, "uint8"))), "single") %!error convn () %!error convn (1) %!error <SHAPE type not valid> convn (1,2, "NOT_A_SHAPE") -%!error convn (rand (3), 1, 1) +%!error convn (b, 1, 1) */ OCTAVE_END_NAMESPACE(octave)
--- a/libinterp/corefcn/gsvd.cc Wed Sep 20 22:00:45 2023 +0200 +++ b/libinterp/corefcn/gsvd.cc Thu Oct 05 17:14:53 2023 -0400 @@ -283,7 +283,7 @@ %! assert (S0, S1, 20*eps); ## a few tests for gsvd.m -%!shared A, A0, B, B0, U, V, C, S, X, old_state, restore_state +%!shared A, A0, B, B0, U, V, C, S, X %! old_state = randn ("state"); %! restore_state = onCleanup (@() randn ("state", old_state)); %! randn ("state", 40); # initialize generator to make behavior reproducible @@ -365,6 +365,9 @@ ## A: 5x3 complex full rank, B: 3x3 complex full rank %!test <48807> +%! old_state = randn ("state"); +%! restore_state = onCleanup (@() randn ("state", old_state)); +%! randn ("state", 12345); # initialize generator to make behavior reproducible %! A0 = A0 + j* randn (5, 3); %! B0 = diag ([1 2 4]) + j* diag ([4 -2 -1]); %! A = A0;