speed up some unnecessarily slow tests

This commit is contained in:
Fredrik Johansson 2016-03-31 02:02:22 +02:00
parent 03add27ec1
commit 7759e89a79
9 changed files with 66 additions and 60 deletions

View file

@ -25,8 +25,8 @@
#include "acb_poly.h" #include "acb_poly.h"
#define NEWTON_EXP_CUTOFF 120 /* allow changing this from the test code */
slong acb_poly_newton_exp_cutoff = 120;
/* with inverse=1 simultaneously computes g = exp(-x) to length n /* with inverse=1 simultaneously computes g = exp(-x) to length n
with inverse=0 uses g as scratch space, computing with inverse=0 uses g as scratch space, computing
@ -126,7 +126,7 @@ _acb_poly_exp_series(acb_ptr f, acb_srcptr h, slong hlen, slong n, slong prec)
_acb_vec_zero(f + j - d + 1, n - (j - d + 1)); _acb_vec_zero(f + j - d + 1, n - (j - d + 1));
acb_clear(t); acb_clear(t);
} }
else if (hlen <= NEWTON_EXP_CUTOFF) else if (hlen <= acb_poly_newton_exp_cutoff)
{ {
_acb_poly_exp_series_basecase(f, h, hlen, n, prec); _acb_poly_exp_series_basecase(f, h, hlen, n, prec);
} }
@ -150,7 +150,7 @@ _acb_poly_exp_series(acb_ptr f, acb_srcptr h, slong hlen, slong n, slong prec)
acb_init(u); acb_init(u);
acb_exp(u, h, prec); acb_exp(u, h, prec);
_acb_poly_exp_series_newton(f, g, t, n, prec, 0, NEWTON_EXP_CUTOFF); _acb_poly_exp_series_newton(f, g, t, n, prec, 0, acb_poly_newton_exp_cutoff);
if (!acb_is_one(u)) if (!acb_is_one(u))
_acb_vec_scalar_mul(f, f, n, u, prec); _acb_vec_scalar_mul(f, f, n, u, prec);

View file

@ -25,6 +25,8 @@
#include "acb_poly.h" #include "acb_poly.h"
extern slong acb_poly_newton_exp_cutoff;
int main() int main()
{ {
slong iter; slong iter;
@ -40,14 +42,19 @@ int main()
slong m, n, bits1, bits2, bits3; slong m, n, bits1, bits2, bits3;
acb_poly_t a, b, c, d; acb_poly_t a, b, c, d;
bits1 = 2 + n_randint(state, 200); bits1 = 2 + n_randint(state, 100);
bits2 = 2 + n_randint(state, 200); bits2 = 2 + n_randint(state, 100);
bits3 = 2 + n_randint(state, 200); bits3 = 2 + n_randint(state, 100);
if (iter > 1000)
{
acb_poly_newton_exp_cutoff = 5 + n_randint(state, 50);
}
if (n_randint(state, 100) == 0) if (n_randint(state, 100) == 0)
{ {
m = 1 + n_randint(state, 400); m = 1 + n_randint(state, 100);
n = 1 + n_randint(state, 400); n = 1 + n_randint(state, 100);
} }
else else
{ {
@ -60,8 +67,8 @@ int main()
acb_poly_init(c); acb_poly_init(c);
acb_poly_init(d); acb_poly_init(d);
acb_poly_randtest(a, state, m, bits1, 10); acb_poly_randtest(a, state, m, bits1, 5);
acb_poly_randtest(b, state, m, bits1, 10); acb_poly_randtest(b, state, m, bits1, 5);
acb_poly_randtest(c, state, 1 + n_randint(state, 300), bits1, 10); acb_poly_randtest(c, state, 1 + n_randint(state, 300), bits1, 10);
acb_poly_randtest(d, state, 1 + n_randint(state, 300), bits1, 10); acb_poly_randtest(d, state, 1 + n_randint(state, 300), bits1, 10);

View file

@ -40,20 +40,20 @@ int main()
slong m, n, bits1, bits2, bits3; slong m, n, bits1, bits2, bits3;
acb_poly_t a, b, c, d; acb_poly_t a, b, c, d;
bits1 = 2 + n_randint(state, 200); bits1 = 2 + n_randint(state, 100);
bits2 = 2 + n_randint(state, 200); bits2 = 2 + n_randint(state, 100);
bits3 = 2 + n_randint(state, 200); bits3 = 2 + n_randint(state, 100);
m = 1 + n_randint(state, 40); m = 1 + n_randint(state, 30);
n = 1 + n_randint(state, 40); n = 1 + n_randint(state, 30);
acb_poly_init(a); acb_poly_init(a);
acb_poly_init(b); acb_poly_init(b);
acb_poly_init(c); acb_poly_init(c);
acb_poly_init(d); acb_poly_init(d);
acb_poly_randtest(a, state, m, bits1, 10); acb_poly_randtest(a, state, m, bits1, 5);
acb_poly_randtest(b, state, m, bits1, 10); acb_poly_randtest(b, state, m, bits1, 5);
/* check exp(a+b) = exp(a) exp(b) */ /* check exp(a+b) = exp(a) exp(b) */
acb_poly_exp_series_basecase(c, a, n, bits2); acb_poly_exp_series_basecase(c, a, n, bits2);

View file

@ -40,11 +40,19 @@ int main()
slong m, n, rbits1, rbits2; slong m, n, rbits1, rbits2;
acb_poly_t a, b, c, d, e; acb_poly_t a, b, c, d, e;
rbits1 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 100);
rbits2 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 100);
m = 1 + n_randint(state, 50); if (n_randint(state, 10) == 0)
n = 1 + n_randint(state, 50); {
m = 1 + n_randint(state, 50);
n = 1 + n_randint(state, 50);
}
else
{
m = 1 + n_randint(state, 20);
n = 1 + n_randint(state, 20);
}
acb_poly_init(a); acb_poly_init(a);
acb_poly_init(b); acb_poly_init(b);
@ -53,8 +61,6 @@ int main()
acb_poly_init(e); acb_poly_init(e);
acb_poly_randtest(a, state, m, rbits1, 10); acb_poly_randtest(a, state, m, rbits1, 10);
acb_poly_set_coeff_si(a, 0, 0); /* TODO: implement complex atan */
acb_poly_tan_series(b, a, n, rbits2); acb_poly_tan_series(b, a, n, rbits2);
/* check tan(x) = 2*tan(x/2)/(1-tan(x/2)^2) */ /* check tan(x) = 2*tan(x/2)/(1-tan(x/2)^2) */

View file

@ -85,7 +85,7 @@ int main()
} }
/* check large arguments */ /* check large arguments */
for (iter = 0; iter < 1000000; iter++) for (iter = 0; iter < 100000; iter++)
{ {
arb_t a, b, c, d; arb_t a, b, c, d;
slong prec0, prec1, prec2; slong prec0, prec1, prec2;

View file

@ -85,7 +85,7 @@ int main()
} }
/* check large arguments */ /* check large arguments */
for (iter = 0; iter < 1000000; iter++) for (iter = 0; iter < 100000; iter++)
{ {
arb_t a, b, c, d; arb_t a, b, c, d;
slong prec0, prec1, prec2; slong prec0, prec1, prec2;

View file

@ -90,7 +90,7 @@ int main()
} }
/* check large arguments */ /* check large arguments */
for (iter = 0; iter < 1000000; iter++) for (iter = 0; iter < 100000; iter++)
{ {
arb_t a, b, c, d, e; arb_t a, b, c, d, e;
slong prec0, prec1, prec2, prec3; slong prec0, prec1, prec2, prec3;

View file

@ -25,7 +25,8 @@
#include "arb_poly.h" #include "arb_poly.h"
#define NEWTON_EXP_CUTOFF 200 /* allow changing this from the test code */
slong arb_poly_newton_exp_cutoff = 200;
/* with inverse=1 simultaneously computes g = exp(-x) to length n /* with inverse=1 simultaneously computes g = exp(-x) to length n
with inverse=0 uses g as scratch space, computing with inverse=0 uses g as scratch space, computing
@ -125,7 +126,7 @@ _arb_poly_exp_series(arb_ptr f, arb_srcptr h, slong hlen, slong n, slong prec)
_arb_vec_zero(f + j - d + 1, n - (j - d + 1)); _arb_vec_zero(f + j - d + 1, n - (j - d + 1));
arb_clear(t); arb_clear(t);
} }
else if (hlen <= NEWTON_EXP_CUTOFF) else if (hlen <= arb_poly_newton_exp_cutoff)
{ {
_arb_poly_exp_series_basecase(f, h, hlen, n, prec); _arb_poly_exp_series_basecase(f, h, hlen, n, prec);
} }
@ -149,7 +150,7 @@ _arb_poly_exp_series(arb_ptr f, arb_srcptr h, slong hlen, slong n, slong prec)
arb_init(u); arb_init(u);
arb_exp(u, h, prec); arb_exp(u, h, prec);
_arb_poly_exp_series_newton(f, g, t, n, prec, 0, NEWTON_EXP_CUTOFF); _arb_poly_exp_series_newton(f, g, t, n, prec, 0, arb_poly_newton_exp_cutoff);
if (!arb_is_one(u)) if (!arb_is_one(u))
_arb_vec_scalar_mul(f, f, n, u, prec); _arb_vec_scalar_mul(f, f, n, u, prec);

View file

@ -25,20 +25,7 @@
#include "arb_poly.h" #include "arb_poly.h"
extern slong arb_poly_newton_exp_cutoff;
/* hack: avoid overflow since exp currently uses mpfr */
void
fmpq_poly_randtest_small(fmpq_poly_t A, flint_rand_t state, slong len, slong bits)
{
fmpq_poly_randtest(A, state, len, bits);
if (A->length > 0)
{
bits = _fmpz_vec_max_bits(A->coeffs, A->length);
bits = FLINT_ABS(bits);
fmpz_mul_2exp(A->den, A->den, bits);
_fmpq_poly_normalise(A);
}
}
int main() int main()
{ {
@ -57,9 +44,9 @@ int main()
fmpq_poly_t A, B; fmpq_poly_t A, B;
arb_poly_t a, b; arb_poly_t a, b;
qbits = 2 + n_randint(state, 200); qbits = 2 + n_randint(state, 100);
rbits1 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 100);
rbits2 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 100);
m = 1 + n_randint(state, 20); m = 1 + n_randint(state, 20);
n = 1 + n_randint(state, 20); n = 1 + n_randint(state, 20);
@ -106,14 +93,14 @@ int main()
fmpq_poly_t A; fmpq_poly_t A;
arb_poly_t a, b; arb_poly_t a, b;
qbits = 2 + n_randint(state, 200); qbits = 2 + n_randint(state, 100);
rbits1 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 100);
rbits2 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 100);
if (n_randint(state, 100) == 0) if (n_randint(state, 100) == 0)
{ {
m = 1 + n_randint(state, 600); m = 1 + n_randint(state, 300);
n = 1 + n_randint(state, 600); n = 1 + n_randint(state, 300);
} }
else else
{ {
@ -125,7 +112,7 @@ int main()
arb_poly_init(a); arb_poly_init(a);
arb_poly_init(b); arb_poly_init(b);
fmpq_poly_randtest_small(A, state, m, qbits); fmpq_poly_randtest(A, state, m, qbits);
arb_poly_randtest(a, state, 1 + n_randint(state, 300), rbits1, 5); arb_poly_randtest(a, state, 1 + n_randint(state, 300), rbits1, 5);
arb_poly_set_fmpq_poly(a, A, rbits1); arb_poly_set_fmpq_poly(a, A, rbits1);
@ -158,15 +145,20 @@ int main()
fmpq_poly_t A; fmpq_poly_t A;
arb_poly_t a, b, c; arb_poly_t a, b, c;
qbits = 2 + n_randint(state, 200); qbits = 2 + n_randint(state, 100);
rbits1 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 100);
rbits2 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 100);
rbits3 = 2 + n_randint(state, 200); rbits3 = 2 + n_randint(state, 100);
if (iter > 100)
{
arb_poly_newton_exp_cutoff = 5 + n_randint(state, 50);
}
if (n_randint(state, 100) == 0) if (n_randint(state, 100) == 0)
{ {
m = 1 + n_randint(state, 600); m = 1 + n_randint(state, 100);
n = 1 + n_randint(state, 600); n = 1 + n_randint(state, 100);
} }
else else
{ {
@ -182,7 +174,7 @@ int main()
arb_poly_randtest(b, state, 1 + n_randint(state, 300), rbits1, 5); arb_poly_randtest(b, state, 1 + n_randint(state, 300), rbits1, 5);
do { do {
fmpq_poly_randtest_small(A, state, m, qbits); fmpq_poly_randtest(A, state, m, qbits);
arb_poly_set_fmpq_poly(a, A, rbits1); arb_poly_set_fmpq_poly(a, A, rbits1);
arb_poly_exp_series(b, a, n, rbits3); arb_poly_exp_series(b, a, n, rbits3);
} while (b->length == 0 || arb_contains_zero(b->coeffs)); } while (b->length == 0 || arb_contains_zero(b->coeffs));