ALL: Add flint
This commit is contained in:
112
external/flint-2.4.3/nmod_vec/test/t-add_sub_neg.c
vendored
Normal file
112
external/flint-2.4.3/nmod_vec/test/t-add_sub_neg.c
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("add/sub/neg....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check (a + b) - b == a */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
slong len = n_randint(state, 100) + 1;
|
||||
nmod_t mod;
|
||||
mp_limb_t n = n_randtest_not_zero(state);
|
||||
|
||||
mp_ptr vec = _nmod_vec_init(len);
|
||||
mp_ptr vec2 = _nmod_vec_init(len);
|
||||
mp_ptr vec3 = _nmod_vec_init(len);
|
||||
|
||||
nmod_init(&mod, n);
|
||||
|
||||
_nmod_vec_randtest(vec, state, len, mod);
|
||||
_nmod_vec_randtest(vec2, state, len, mod);
|
||||
|
||||
_nmod_vec_add(vec3, vec, vec2, len, mod);
|
||||
_nmod_vec_sub(vec3, vec3, vec2, len, mod);
|
||||
|
||||
result = _nmod_vec_equal(vec, vec3, len);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("len = %wd, n = %wd\n", len, n);
|
||||
abort();
|
||||
}
|
||||
|
||||
_nmod_vec_clear(vec);
|
||||
_nmod_vec_clear(vec2);
|
||||
_nmod_vec_clear(vec3);
|
||||
}
|
||||
|
||||
/* Check (a + -b) == a - b */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
slong len = n_randint(state, 100) + 1;
|
||||
mp_limb_t n = n_randtest_not_zero(state);
|
||||
nmod_t mod;
|
||||
|
||||
mp_ptr vec = _nmod_vec_init(len);
|
||||
mp_ptr vec2 = _nmod_vec_init(len);
|
||||
mp_ptr vec3 = _nmod_vec_init(len);
|
||||
|
||||
nmod_init(&mod, n);
|
||||
|
||||
_nmod_vec_randtest(vec, state, len, mod);
|
||||
_nmod_vec_randtest(vec2, state, len, mod);
|
||||
|
||||
_nmod_vec_sub(vec3, vec, vec2, len, mod);
|
||||
_nmod_vec_neg(vec2, vec2, len, mod);
|
||||
_nmod_vec_add(vec, vec, vec2, len, mod);
|
||||
|
||||
result = _nmod_vec_equal(vec, vec3, len);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("len = %wd, n = %wd\n", len, n);
|
||||
abort();
|
||||
}
|
||||
|
||||
_nmod_vec_clear(vec);
|
||||
_nmod_vec_clear(vec2);
|
||||
_nmod_vec_clear(vec3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
99
external/flint-2.4.3/nmod_vec/test/t-dot.c
vendored
Normal file
99
external/flint-2.4.3/nmod_vec/test/t-dot.c
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("dot....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
slong len;
|
||||
nmod_t mod;
|
||||
mp_limb_t m, res;
|
||||
mp_ptr x, y;
|
||||
int limbs1;
|
||||
mpz_t s, t;
|
||||
slong j;
|
||||
|
||||
len = n_randint(state, 1000) + 1;
|
||||
m = n_randtest_not_zero(state);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
|
||||
x = _nmod_vec_init(len);
|
||||
y = _nmod_vec_init(len);
|
||||
|
||||
_nmod_vec_randtest(x, state, len, mod);
|
||||
_nmod_vec_randtest(y, state, len, mod);
|
||||
|
||||
limbs1 = _nmod_vec_dot_bound_limbs(len, mod);
|
||||
|
||||
res = _nmod_vec_dot(x, y, len, mod, limbs1);
|
||||
|
||||
mpz_init(s);
|
||||
mpz_init(t);
|
||||
|
||||
for (j = 0; j < len; j++)
|
||||
{
|
||||
flint_mpz_set_ui(t, x[j]);
|
||||
flint_mpz_addmul_ui(s, t, y[j]);
|
||||
}
|
||||
|
||||
flint_mpz_mod_ui(s, s, m);
|
||||
|
||||
if (flint_mpz_get_ui(s) != res)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
flint_printf("len = %wd\n", len);
|
||||
flint_printf("limbs1 = %d\n", limbs1);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpz_clear(s);
|
||||
mpz_clear(t);
|
||||
|
||||
_nmod_vec_clear(x);
|
||||
_nmod_vec_clear(y);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
82
external/flint-2.4.3/nmod_vec/test/t-dot_bound_limbs.c
vendored
Normal file
82
external/flint-2.4.3/nmod_vec/test/t-dot_bound_limbs.c
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("dot_bound_limbs....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 1000000; i++)
|
||||
{
|
||||
slong len;
|
||||
nmod_t mod;
|
||||
mp_limb_t m;
|
||||
int limbs1, limbs2;
|
||||
mpz_t t;
|
||||
|
||||
len = n_randint(state, 10000) + 1;
|
||||
m = n_randtest_not_zero(state);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
|
||||
limbs1 = _nmod_vec_dot_bound_limbs(len, mod);
|
||||
|
||||
mpz_init2(t, 4*FLINT_BITS);
|
||||
flint_mpz_set_ui(t, m-1);
|
||||
mpz_mul(t, t, t);
|
||||
flint_mpz_mul_ui(t, t, len);
|
||||
limbs2 = mpz_size(t);
|
||||
|
||||
if (limbs1 != limbs2)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
flint_printf("len = %wd\n", len);
|
||||
flint_printf("limbs1 = %d\n", limbs1);
|
||||
flint_printf("limbs2 = %d\n", limbs2);
|
||||
gmp_printf("bound: %Zd\n", t);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpz_clear(t);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
92
external/flint-2.4.3/nmod_vec/test/t-dot_ptr.c
vendored
Normal file
92
external/flint-2.4.3/nmod_vec/test/t-dot_ptr.c
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("dot_ptr....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
slong len;
|
||||
nmod_t mod;
|
||||
mp_limb_t m, res, res2;
|
||||
mp_ptr x, y;
|
||||
mp_ptr * z;
|
||||
int limbs1;
|
||||
slong j, offset;
|
||||
|
||||
len = n_randint(state, 1000) + 1;
|
||||
m = n_randtest_not_zero(state);
|
||||
offset = n_randint(state, 10);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
|
||||
x = _nmod_vec_init(len);
|
||||
y = _nmod_vec_init(len);
|
||||
z = flint_malloc(sizeof(mp_ptr) * len);
|
||||
|
||||
_nmod_vec_randtest(x, state, len, mod);
|
||||
_nmod_vec_randtest(y, state, len, mod);
|
||||
|
||||
for (j = 0; j < len; j++)
|
||||
z[j] = &y[j] + offset;
|
||||
|
||||
limbs1 = _nmod_vec_dot_bound_limbs(len, mod);
|
||||
|
||||
res = _nmod_vec_dot_ptr(x, z, -offset, len, mod, limbs1);
|
||||
res2 = _nmod_vec_dot(x, y, len, mod, limbs1);
|
||||
|
||||
if (res != res2)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
flint_printf("len = %wd\n", len);
|
||||
flint_printf("limbs1 = %d\n", limbs1);
|
||||
abort();
|
||||
}
|
||||
|
||||
_nmod_vec_clear(x);
|
||||
_nmod_vec_clear(y);
|
||||
flint_free(z);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
263
external/flint-2.4.3/nmod_vec/test/t-nmod.c
vendored
Normal file
263
external/flint-2.4.3/nmod_vec/test/t-nmod.c
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2013 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("nmod....");
|
||||
fflush(stdout);
|
||||
|
||||
/* nmod_add */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
nmod_t mod;
|
||||
mp_limb_t m, a, b, c;
|
||||
mpz_t x, y, z;
|
||||
|
||||
m = n_randtest_not_zero(state);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
a = n_randlimb(state) % m;
|
||||
b = n_randlimb(state) % m;
|
||||
|
||||
c = nmod_add(a, b, mod);
|
||||
|
||||
mpz_init(x);
|
||||
mpz_init(y);
|
||||
mpz_init(z);
|
||||
|
||||
flint_mpz_set_ui(x, a);
|
||||
flint_mpz_set_ui(y, b);
|
||||
mpz_add(z, x, y);
|
||||
flint_mpz_mod_ui(z, z, m);
|
||||
|
||||
if (flint_mpz_cmp_ui(z, c) != 0)
|
||||
{
|
||||
flint_printf("FAIL (add):\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpz_clear(x);
|
||||
mpz_clear(y);
|
||||
mpz_clear(z);
|
||||
}
|
||||
|
||||
/* nmod_sub */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
nmod_t mod;
|
||||
mp_limb_t m, a, b, c;
|
||||
mpz_t x, y, z;
|
||||
|
||||
m = n_randtest_not_zero(state);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
a = n_randlimb(state) % m;
|
||||
b = n_randlimb(state) % m;
|
||||
|
||||
c = nmod_sub(a, b, mod);
|
||||
|
||||
mpz_init(x);
|
||||
mpz_init(y);
|
||||
mpz_init(z);
|
||||
|
||||
flint_mpz_set_ui(x, a);
|
||||
flint_mpz_set_ui(y, b);
|
||||
mpz_sub(z, x, y);
|
||||
flint_mpz_mod_ui(z, z, m);
|
||||
|
||||
if (flint_mpz_cmp_ui(z, c) != 0)
|
||||
{
|
||||
flint_printf("FAIL (sub):\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpz_clear(x);
|
||||
mpz_clear(y);
|
||||
mpz_clear(z);
|
||||
}
|
||||
|
||||
/* nmod_mul */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
nmod_t mod;
|
||||
mp_limb_t m, a, b, c;
|
||||
mpz_t x, y, z;
|
||||
|
||||
m = n_randtest_not_zero(state);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
a = n_randlimb(state) % m;
|
||||
b = n_randlimb(state) % m;
|
||||
|
||||
c = nmod_mul(a, b, mod);
|
||||
|
||||
mpz_init(x);
|
||||
mpz_init(y);
|
||||
mpz_init(z);
|
||||
|
||||
flint_mpz_set_ui(x, a);
|
||||
flint_mpz_set_ui(y, b);
|
||||
mpz_mul(z, x, y);
|
||||
flint_mpz_mod_ui(z, z, m);
|
||||
|
||||
if (flint_mpz_cmp_ui(z, c) != 0)
|
||||
{
|
||||
flint_printf("FAIL (mul):\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpz_clear(x);
|
||||
mpz_clear(y);
|
||||
mpz_clear(z);
|
||||
}
|
||||
|
||||
/* nmod_div */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
nmod_t mod;
|
||||
mp_limb_t m, a, b, c;
|
||||
mpz_t x, y, z;
|
||||
|
||||
m = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
|
||||
a = n_randlimb(state) % m;
|
||||
do { b = n_randlimb(state) % m; } while (b == 0);
|
||||
|
||||
c = nmod_div(a, b, mod);
|
||||
|
||||
mpz_init(x);
|
||||
mpz_init(y);
|
||||
mpz_init(z);
|
||||
|
||||
flint_mpz_set_ui(x, a);
|
||||
flint_mpz_set_ui(y, b);
|
||||
flint_mpz_set_ui(z, m);
|
||||
mpz_invert(z, y, z);
|
||||
mpz_mul(z, x, z);
|
||||
flint_mpz_mod_ui(z, z, m);
|
||||
|
||||
if (flint_mpz_cmp_ui(z, c) != 0)
|
||||
{
|
||||
flint_printf("FAIL (div):\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpz_clear(x);
|
||||
mpz_clear(y);
|
||||
mpz_clear(z);
|
||||
}
|
||||
|
||||
/* nmod_inv */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
nmod_t mod;
|
||||
mp_limb_t m, b, c;
|
||||
mpz_t y, z;
|
||||
|
||||
m = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
|
||||
do { b = n_randlimb(state) % m; } while (b == 0);
|
||||
|
||||
c = nmod_inv(b, mod);
|
||||
|
||||
mpz_init(y);
|
||||
mpz_init(z);
|
||||
|
||||
flint_mpz_set_ui(y, b);
|
||||
flint_mpz_set_ui(z, m);
|
||||
mpz_invert(z, y, z);
|
||||
|
||||
if (flint_mpz_cmp_ui(z, c) != 0)
|
||||
{
|
||||
flint_printf("FAIL (div):\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpz_clear(y);
|
||||
mpz_clear(z);
|
||||
}
|
||||
|
||||
/* nmod_pow_ui */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
nmod_t mod;
|
||||
mp_limb_t m, b, c;
|
||||
mpz_t y, z;
|
||||
ulong exp;
|
||||
|
||||
m = n_randtest_prime(state, 0);
|
||||
exp = n_randtest(state);
|
||||
|
||||
nmod_init(&mod, m);
|
||||
|
||||
b = n_randlimb(state) % m;
|
||||
|
||||
c = nmod_pow_ui(b, exp, mod);
|
||||
|
||||
mpz_init(y);
|
||||
mpz_init(z);
|
||||
|
||||
flint_mpz_set_ui(y, b);
|
||||
flint_mpz_set_ui(z, m);
|
||||
flint_mpz_powm_ui(z, y, exp, z);
|
||||
|
||||
if (flint_mpz_cmp_ui(z, c) != 0)
|
||||
{
|
||||
flint_printf("FAIL (pow):\n");
|
||||
flint_printf("m = %wu\n", m);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpz_clear(y);
|
||||
mpz_clear(z);
|
||||
}
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
79
external/flint-2.4.3/nmod_vec/test/t-reduce.c
vendored
Normal file
79
external/flint-2.4.3/nmod_vec/test/t-reduce.c
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("reduce....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
slong j, len = n_randint(state, 100) + 1;
|
||||
mp_ptr vec = _nmod_vec_init(len);
|
||||
mp_ptr vec2 = _nmod_vec_init(len);
|
||||
|
||||
mp_limb_t n = n_randtest_not_zero(state);
|
||||
nmod_t mod;
|
||||
nmod_init(&mod, n);
|
||||
|
||||
for (j = 0; j < len; j++)
|
||||
{
|
||||
vec[j] = n_randtest(state);
|
||||
vec2[j] = vec[j];
|
||||
}
|
||||
|
||||
_nmod_vec_reduce(vec, vec, len, mod);
|
||||
for (j = 0; j < len; j++)
|
||||
vec2[j] = n_mod2_preinv(vec2[j], mod.n, mod.ninv);
|
||||
|
||||
result = _nmod_vec_equal(vec, vec2, len);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("len = %wd, n = %wd\n", len, n);
|
||||
abort();
|
||||
}
|
||||
|
||||
_nmod_vec_clear(vec);
|
||||
_nmod_vec_clear(vec2);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
83
external/flint-2.4.3/nmod_vec/test/t-scalar_addmul_nmod.c
vendored
Normal file
83
external/flint-2.4.3/nmod_vec/test/t-scalar_addmul_nmod.c
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("scalar_addmul_nmod....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check (a + b*c) == a + (b*c) */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
slong len = n_randint(state, 100) + 1;
|
||||
mp_limb_t n = n_randtest_not_zero(state);
|
||||
mp_limb_t c = n_randint(state, n);
|
||||
nmod_t mod;
|
||||
|
||||
mp_ptr vec = _nmod_vec_init(len);
|
||||
mp_ptr vec2 = _nmod_vec_init(len);
|
||||
mp_ptr vec3 = _nmod_vec_init(len);
|
||||
|
||||
nmod_init(&mod, n);
|
||||
|
||||
_nmod_vec_randtest(vec, state, len, mod);
|
||||
_nmod_vec_randtest(vec2, state, len, mod);
|
||||
flint_mpn_copyi(vec3, vec2, len);
|
||||
|
||||
_nmod_vec_scalar_mul_nmod(vec3, vec, len, c, mod);
|
||||
_nmod_vec_add(vec3, vec3, vec2, len, mod);
|
||||
|
||||
_nmod_vec_scalar_addmul_nmod(vec2, vec, len, c, mod);
|
||||
|
||||
result = _nmod_vec_equal(vec2, vec3, len);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("len = %wd, n = %wd\n", len, n);
|
||||
abort();
|
||||
}
|
||||
|
||||
_nmod_vec_clear(vec);
|
||||
_nmod_vec_clear(vec2);
|
||||
_nmod_vec_clear(vec3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
84
external/flint-2.4.3/nmod_vec/test/t-scalar_mul_nmod.c
vendored
Normal file
84
external/flint-2.4.3/nmod_vec/test/t-scalar_mul_nmod.c
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("scalar_mul_nmod....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check (a + b)*c == a*c + b*c */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
slong len = n_randint(state, 100) + 1;
|
||||
mp_limb_t n = n_randtest_not_zero(state);
|
||||
mp_limb_t c = n_randint(state, n);
|
||||
nmod_t mod;
|
||||
|
||||
mp_ptr vec = _nmod_vec_init(len);
|
||||
mp_ptr vec2 = _nmod_vec_init(len);
|
||||
mp_ptr vec3 = _nmod_vec_init(len);
|
||||
|
||||
nmod_init(&mod, n);
|
||||
|
||||
_nmod_vec_randtest(vec, state, len, mod);
|
||||
_nmod_vec_randtest(vec2, state, len, mod);
|
||||
|
||||
_nmod_vec_add(vec3, vec, vec2, len, mod);
|
||||
_nmod_vec_scalar_mul_nmod(vec3, vec3, len, c, mod);
|
||||
|
||||
_nmod_vec_scalar_mul_nmod(vec, vec, len, c, mod);
|
||||
_nmod_vec_scalar_mul_nmod(vec2, vec2, len, c, mod);
|
||||
_nmod_vec_add(vec, vec, vec2, len, mod);
|
||||
|
||||
result = _nmod_vec_equal(vec, vec3, len);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("len = %wd, n = %wd\n", len, n);
|
||||
abort();
|
||||
}
|
||||
|
||||
_nmod_vec_clear(vec);
|
||||
_nmod_vec_clear(vec2);
|
||||
_nmod_vec_clear(vec3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user