[Gmp-commit] /var/hg/gmp: Rewrite random generation.
mercurial at gmplib.org
mercurial at gmplib.org
Fri Jun 1 11:19:40 CEST 2012
details: /var/hg/gmp/rev/401e1ce4ca2e
changeset: 15033:401e1ce4ca2e
user: Torbjorn Granlund <tege at gmplib.org>
date: Fri Jun 01 11:19:37 2012 +0200
description:
Rewrite random generation.
diffstat:
ChangeLog | 5 ++
tests/mpz/t-cong.c | 97 ++++++++++++++++++++++++++++++++---------------------
2 files changed, 63 insertions(+), 39 deletions(-)
diffs (155 lines):
diff -r 357486cfe1e7 -r 401e1ce4ca2e ChangeLog
--- a/ChangeLog Fri Jun 01 08:23:33 2012 +0200
+++ b/ChangeLog Fri Jun 01 11:19:37 2012 +0200
@@ -1,3 +1,8 @@
+2012-06-01 Torbjorn Granlund <tege at gmplib.org>
+
+ * tests/mpz/t-cong.c (check_random): Rewrite random generation for
+ exponentially distributed operand sizes.
+
2012-06-01 Marco Bodrato <bodrato at mail.dm.unipi.it>
* mpq: Use more macros and MPZ_REALLOC return value when possible.
diff -r 357486cfe1e7 -r 401e1ce4ca2e tests/mpz/t-cong.c
--- a/tests/mpz/t-cong.c Fri Jun 01 08:23:33 2012 +0200
+++ b/tests/mpz/t-cong.c Fri Jun 01 11:19:37 2012 +0200
@@ -1,6 +1,6 @@
/* test mpz_congruent_p and mpz_congruent_ui_p
-Copyright 2001, 2002 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -34,38 +34,38 @@
{
got = (mpz_congruent_p (a, c, d) != 0);
if (want != got)
- {
- printf ("mpz_congruent_p wrong\n");
- printf (" expected %d got %d\n", want, got);
- mpz_trace (" a", a);
- mpz_trace (" c", c);
- mpz_trace (" d", d);
- mp_trace_base = -16;
- mpz_trace (" a", a);
- mpz_trace (" c", c);
- mpz_trace (" d", d);
- abort ();
- }
+ {
+ printf ("mpz_congruent_p wrong\n");
+ printf (" expected %d got %d\n", want, got);
+ mpz_trace (" a", a);
+ mpz_trace (" c", c);
+ mpz_trace (" d", d);
+ mp_trace_base = -16;
+ mpz_trace (" a", a);
+ mpz_trace (" c", c);
+ mpz_trace (" d", d);
+ abort ();
+ }
if (mpz_fits_ulong_p (c) && mpz_fits_ulong_p (d))
- {
- unsigned long uc = mpz_get_ui (c);
- unsigned long ud = mpz_get_ui (d);
- got = (mpz_congruent_ui_p (a, uc, ud) != 0);
- if (want != got)
- {
- printf ("mpz_congruent_ui_p wrong\n");
- printf (" expected %d got %d\n", want, got);
- mpz_trace (" a", a);
- printf (" c=%lu\n", uc);
- printf (" d=%lu\n", ud);
- mp_trace_base = -16;
- mpz_trace (" a", a);
- printf (" c=0x%lX\n", uc);
- printf (" d=0x%lX\n", ud);
- abort ();
- }
- }
+ {
+ unsigned long uc = mpz_get_ui (c);
+ unsigned long ud = mpz_get_ui (d);
+ got = (mpz_congruent_ui_p (a, uc, ud) != 0);
+ if (want != got)
+ {
+ printf ("mpz_congruent_ui_p wrong\n");
+ printf (" expected %d got %d\n", want, got);
+ mpz_trace (" a", a);
+ printf (" c=%lu\n", uc);
+ printf (" d=%lu\n", ud);
+ mp_trace_base = -16;
+ mpz_trace (" a", a);
+ printf (" c=0x%lX\n", uc);
+ printf (" d=0x%lX\n", ud);
+ abort ();
+ }
+ }
MPZ_SRCPTR_SWAP (a, c);
}
@@ -138,11 +138,15 @@
mpz_t a, c, d, ra, rc;
int i;
int want;
- int reps = 50000;
+ int reps = 20000;
+ mpz_t bs;
+ unsigned long size_range, size;
if (argc >= 2)
reps = atoi (argv[1]);
+ mpz_init (bs);
+
mpz_init (a);
mpz_init (c);
mpz_init (d);
@@ -151,11 +155,24 @@
for (i = 0; i < reps; i++)
{
- mpz_errandomb (a, rands, 100*GMP_LIMB_BITS);
- MPZ_CHECK_FORMAT (a);
- mpz_errandomb (c, rands, 100*GMP_LIMB_BITS);
- MPZ_CHECK_FORMAT (c);
- mpz_errandomb_nonzero (d, rands, 100*GMP_LIMB_BITS);
+ mpz_urandomb (bs, rands, 32);
+ size_range = mpz_get_ui (bs) % 14 + 1; /* 0..16384 bit operands */
+
+ mpz_urandomb (bs, rands, size_range);
+ size = mpz_get_ui (bs);
+ mpz_rrandomb (a, rands, size);
+
+ mpz_urandomb (bs, rands, size_range);
+ size = mpz_get_ui (bs);
+ mpz_rrandomb (c, rands, size);
+
+ do
+ {
+ mpz_urandomb (bs, rands, size_range);
+ size = mpz_get_ui (bs);
+ mpz_rrandomb (d, rands, size);
+ }
+ while (SIZ(d) == 0);
mpz_negrandom (a, rands);
MPZ_CHECK_FORMAT (a);
@@ -176,11 +193,13 @@
if (! mpz_pow2abs_p (d))
{
- refmpz_combit (a, urandom() % (8*GMP_LIMB_BITS));
- check_one (a, c, d, 0);
+ refmpz_combit (a, urandom() % (8*GMP_LIMB_BITS));
+ check_one (a, c, d, 0);
}
}
+ mpz_clear (bs);
+
mpz_clear (a);
mpz_clear (c);
mpz_clear (d);
More information about the gmp-commit
mailing list