Permalink
Browse files

test_hlll looks like test_lll and test wrapper.

  • Loading branch information...
lgremy committed Dec 4, 2018
1 parent 7be2181 commit 8400e7de68b9656609be435441f2da1356e937b0
Showing with 100 additions and 68 deletions.
  1. +1 −0 fplll/fplll.h
  2. +99 −68 tests/test_hlll.cpp
@@ -24,6 +24,7 @@

#include "bkz.h"
#include "bkz_param.h"
#include "hlll.h"
#include "pruner/pruner.h"
#include "svpcvp.h"
#include "util.h"
@@ -15,8 +15,7 @@
along with fplll. If not, see <http://www.gnu.org/licenses/>. */

#include <cstring>
#include <hlll.h>
#include <householder.h>
#include <fplll.h>
#include <test_utils.h>

using namespace std;
@@ -26,61 +25,107 @@ using namespace fplll;
#define TESTDATADIR ".."
#endif

// Return 0 if all goes well, 1 instead
template <class ZT, class FT> int test_hlll(ZZ_mat<ZT> &A, int flags)
/**
@brief Test the tester.
@param A
@return zero on success.
Should return 0, since the at this point of the program, A is not reduced.
*/

template <class ZT> int test_test(ZZ_mat<ZT> &A)
{
ZZ_mat<ZT> U;
ZZ_mat<ZT> UT;

MatHouseholder<Z_NR<ZT>, FP_NR<mpfr_t>> M(A, U, UT, 0);

int is_reduced =
is_hlll_reduced<Z_NR<ZT>, FP_NR<mpfr_t>>(M, LLL_DEF_DELTA, LLL_DEF_ETA, HLLL_DEF_THETA);

if (is_reduced == RED_SUCCESS)
cerr << "is_hlll_reduced reports success when it should not" << endl;

return (is_reduced == RED_SUCCESS);
}

/**
@brief Test HLLL reduction.
@param A test matrix
@param method LLL method to test
@param float_type floating point type to test
@param flags flags to use
@return zero on success.
*/

template <class ZT>
int test_hlll(ZZ_mat<ZT> &A, LLLMethod method, FloatType float_type, int flags = LLL_DEFAULT)
{
// Define empty u and ut.
ZZ_mat<ZT> u(0, 0);
ZZ_mat<ZT> ut(0, 0);
// Create the MatHouseholder object
MatHouseholder<Z_NR<ZT>, FP_NR<FT>> Mhouseholder(A, u, ut, flags);
// Create the HLLLReduction object, on which will be performed the hlll reduction
HLLLReduction<Z_NR<ZT>, FP_NR<FT>> hlll_obj(Mhouseholder, 0.99, 0.52, 0.99, 0.01, LLL_DEFAULT);

// The matrix A used to build Mhouseholder is not reduced. If the test return true, then
// is_hlll_reduced is badly
// implemented
int status = is_hlll_reduced<Z_NR<ZT>, FP_NR<FT>>(Mhouseholder, 0.99, 0.52, 0.01);
if (status == RED_SUCCESS)

ZZ_mat<ZT> U;
ZZ_mat<ZT> UT;

int status = 0;

// zero on success
if (test_test(A))
{
cerr << "is_hlll_reduced reports success when it should not." << endl;
return 1;
}

// Perform the hlll reduction
hlll_obj.hlll();

// Verify if A is hlll reduced thanks to mpfr
MatHouseholder<Z_NR<ZT>, FP_NR<mpfr_t>> M(A, u, ut, HOUSEHOLDER_DEFAULT);
// zero on success
status = hlll_reduction(A, LLL_DEF_DELTA, LLL_DEF_ETA, HLLL_DEF_THETA, HLLL_DEF_C, method,
float_type, 0, flags, false);

// This times, M must be hlll reduced
status = is_hlll_reduced<Z_NR<ZT>, FP_NR<mpfr_t>>(M, 0.99, 0.52, 0.01);
if (status != RED_SUCCESS)
{
cerr << "Output of HLLL reduction is not HLLL reduced." << endl;
return 1;
cerr << "HLLL reduction failed with error '" << get_red_status_str(status);
cerr << "' for method " << LLL_METHOD_STR[method];
cerr << " and float type " << FLOAT_TYPE_STR[float_type] << endl;
return status;
}

return 0;
int prec = hlll_min_prec(A.get_rows(), A.get_cols(), LLL_DEF_DELTA, LLL_DEF_ETA, HLLL_DEF_THETA,
HLLL_DEF_C);

const int old_prec = FP_NR<mpfr_t>::set_prec(prec);

MatHouseholder<Z_NR<ZT>, FP_NR<mpfr_t>> M(A, U, UT, 0);

// one on success
status = is_hlll_reduced<Z_NR<ZT>, FP_NR<mpfr_t>>(M, LLL_DEF_DELTA, LLL_DEF_ETA, HLLL_DEF_THETA);

FP_NR<mpfr_t>::set_prec(old_prec);

if (status != RED_SUCCESS)
cerr << "Output of HLLL reduction is not HLLL reduced with method " << LLL_METHOD_STR[method]
<< endl;

return (status != RED_SUCCESS);
}

/**
@brief Test HLLL for matrix stored in file pointed to by `input_filename`.
@param input_filename a path
@param method LLL method to test
@param float_type floating point type to test
@param flags flags to use
@return zero on success
*/

template <class ZT, class FT> int test_filename(const char *input_filename, int flags)
template <class ZT>
int test_filename(const char *input_filename, LLLMethod method, FloatType float_type = FT_DEFAULT,
int flags = LLL_DEFAULT)
{
ZZ_mat<ZT> A;
int status = 0;
// Read A from input_filename
status |= read_file(A, input_filename);
// Test hlll reduction on A
status |= test_hlll<ZT, FT>(A, flags);
status |= test_hlll<ZT>(A, method, float_type, flags);
return status;
}

@@ -92,49 +137,35 @@ template <class ZT, class FT> int test_filename(const char *input_filename, int
@param method LLL method to test
@param float_type floating point type to test
@param flags flags to use
@param prec precision used for is_lll_reduced
@return zero on success
*/

template <class ZT>
int test_int_rel(int d, int b, LLLMethod method, FloatType float_type = FT_DEFAULT,
int flags = LLL_DEFAULT)
{
ZZ_mat<ZT> A;
A.resize(d, d + 1);
A.gen_intrel(b);
return test_hlll<ZT>(A, method, float_type, flags);
}

int main(int /*argc*/, char ** /*argv*/)
{

int status = 0;
int flags_fast = HOUSEHOLDER_ROW_EXPO /* | HOUSEHOLDER_OP_FORCE_LONG */;
int flags_proved = HOUSEHOLDER_DEFAULT;

status |= test_filename<mpz_t, double>(TESTDATADIR "/tests/lattices/dim55_in", flags_fast);
#ifdef FPLLL_WITH_LONG_DOUBLE
status |= test_filename<mpz_t, long double>(TESTDATADIR "/tests/lattices/dim55_in", flags_fast);
#endif // FPLLL_WITH_LONG_DOUBLE
#ifdef FPLLL_WITH_DPE
status |= test_filename<mpz_t, dpe_t>(TESTDATADIR "/tests/lattices/dim55_in", flags_proved);
#endif // FPLLL_WITH_DPE
#ifdef FPLLL_WITH_QD
status |= test_filename<mpz_t, qd_real>(TESTDATADIR "/tests/lattices/dim55_in", flags_fast);
status |= test_filename<mpz_t, dd_real>(TESTDATADIR "/tests/lattices/dim55_in", flags_fast);
#endif // FPLLL_WITH_QD
status |= test_filename<mpz_t, mpfr_t>(TESTDATADIR "/tests/lattices/dim55_in", flags_proved);

status |= test_filename<mpz_t, double>(TESTDATADIR "/tests/lattices/example_cvp_in_lattice4",
flags_fast);
#ifdef FPLLL_WITH_LONG_DOUBLE
status |= test_filename<mpz_t, long double>(TESTDATADIR "/tests/lattices/example_cvp_in_lattice4",
flags_fast);
#endif // FPLLL_WITH_LONG_DOUBLE
#ifdef FPLLL_WITH_DPE
status |= test_filename<mpz_t, dpe_t>(TESTDATADIR "/tests/lattices/example_cvp_in_lattice4",
flags_proved);
#endif // FPLLL_WITH_DPE
#ifdef FPLLL_WITH_QD
status |= test_filename<mpz_t, qd_real>(TESTDATADIR "/tests/lattices/example_cvp_in_lattice4",
flags_fast);
status |= test_filename<mpz_t, dd_real>(TESTDATADIR "/tests/lattices/example_cvp_in_lattice4",
flags_fast);
#endif // FPLLL_WITH_QD
status |= test_filename<mpz_t, mpfr_t>(TESTDATADIR "/tests/lattices/example_cvp_in_lattice4",
flags_proved);
int status = 0;
status |= test_filename<mpz_t>(TESTDATADIR "/tests/lattices/dim55_in", LM_WRAPPER, FT_DEFAULT);
status |= test_filename<mpz_t>(TESTDATADIR "/tests/lattices/dim55_in", LM_PROVED, FT_MPFR);

status |= test_int_rel<mpz_t>(50, 1000, LM_FAST, FT_DOUBLE);
status |= test_int_rel<mpz_t>(30, 1000, LM_PROVED, FT_MPFR);

status |= test_int_rel<mpz_t>(30, 2000, LM_PROVED, FT_DPE);
status |= test_int_rel<mpz_t>(20, 2000, LM_PROVED, FT_MPFR);

status |= test_filename<mpz_t>(TESTDATADIR "/tests/lattices/example_in", LM_FAST, FT_DOUBLE);
status |= test_filename<mpz_t>(TESTDATADIR "/tests/lattices/example_in", LM_PROVED, FT_MPFR);

if (status == 0)
{

0 comments on commit 8400e7d

Please sign in to comment.