Permalink
Browse files

Fixing issue #362

  • Loading branch information...
gilvillard committed Dec 20, 2018
1 parent a8cb572 commit 9e508b52e3d64fa0afd3b048ff7040f20fbf46a7
@@ -29,7 +29,7 @@ FPLLL_BEGIN_NAMESPACE
* @brief Performs a heuristic check if BKZ can be terminated.
*
* Checks if the slope of the basis hasn't decreased in a while.
*/
*/
template <class ZT, class FT> class BKZAutoAbort
{
public:
@@ -42,7 +42,7 @@ template <class ZT, class FT> class BKZAutoAbort
* the number of vectors to check
* @param start_row
* the starting point of the vectors to check
*/
*/
BKZAutoAbort(MatGSO<ZT, FT> &m, int num_rows, int start_row = 0)
: m(m), old_slope(numeric_limits<double>::max()), no_dec(-1), num_rows(num_rows),
start_row(start_row)
@@ -78,12 +78,12 @@ template <class ZT, class FT> class BKZAutoAbort
};

/**
* @brief The class performing block reduction.
*
* This class implements BKZ, SD-BKZ and Slide Reduction. For this
* it relies on the GSO, LLL, and Enumeration modules. It assumes
* that the basis is LLL reduced.
**/
* @brief The class performing block reduction.
*
* This class implements BKZ, SD-BKZ and Slide Reduction. For this
* it relies on the GSO, LLL, and Enumeration modules. It assumes
* that the basis is LLL reduced.
**/
template <class ZT, class FT> class BKZReduction
{
/**
@@ -160,7 +160,7 @@ template <class ZT, class FT> class BKZReduction
* flag specifying if the block is to be SVP or dual SVP reduced.
* @returns
* false if it made progress, true otherwise
*/
*/
bool svp_reduction(int kappa, int block_size, const BKZParam &param, bool dual = false);

/**
@@ -27,7 +27,7 @@ void EnumerationDyn<ZT, FT>::reset(enumf cur_dist, int cur_depth)
int new_dim = cur_depth + 1;

vector<enumxt> partial_sol(d - cur_depth - 1);
for (int i = cur_depth + 1; i < d; ++i)
for (int i = cur_depth + 1; i < d; ++i)
partial_sol[i - cur_depth - 1] = x[i];

FT new_dist = 0.0;
@@ -49,7 +49,7 @@ void EnumerationDyn<ZT, FT>::reset(enumf cur_dist, int cur_depth)
{
// FPLLL_TRACE("Saving it.");
for (int i = 0; i < new_dim; ++i)
x[i] = new_evaluator.begin()->second[i].get_d();
x[i] = new_evaluator.begin()->second[i].get_d();
process_solution(sol_dist + cur_dist);
}
}
@@ -67,7 +67,7 @@ void EnumerationDyn<ZT, FT>::enumerate(int first, int last, FT &fmaxdist, long f
target = target_coord;
if (last == -1)
last = _gso.d;
d = last - first;
d = last - first;
fx.resize(d);
FPLLL_CHECK(d < maxdim, "enumerate: dimension is too high");
FPLLL_CHECK((solvingsvp || !dual), "CVP for dual not implemented! What does that even mean? ");
@@ -79,12 +79,12 @@ void EnumerationDyn<ZT, FT>::enumerate(int first, int last, FT &fmaxdist, long f

if (solvingsvp)
{
for (int i = 0; i < d; ++i)
for (int i = 0; i < d; ++i)
center_partsum[i] = 0.0;
}
else
{
for (int i = 0; i < d; ++i)
for (int i = 0; i < d; ++i)
center_partsum[i] = target_coord[i + first].get_d();
}

@@ -223,7 +223,7 @@ template <typename ZT, typename FT> void EnumerationDyn<ZT, FT>::set_bounds()
}
else
{
for (int i = 0; i < d; ++i)
for (int i = 0; i < d; ++i)
partdistbounds[i] = pruning_bounds[i] * maxdist;
}
}
@@ -232,7 +232,7 @@ template <typename ZT, typename FT> void EnumerationDyn<ZT, FT>::process_solutio
{
FPLLL_TRACE("Sol dist: " << newmaxdist << " (nodes:" << nodes << ")");
for (int j = 0; j < d; ++j)
fx[j] = x[j];
fx[j] = x[j];
_evaluator.eval_sol(fx, newmaxdist, maxdist);

set_bounds();
@@ -242,9 +242,9 @@ template <typename ZT, typename FT>
void EnumerationDyn<ZT, FT>::process_subsolution(int offset, enumf newdist)
{
for (int j = 0; j < offset; ++j)
fx[j] = 0.0;
fx[j] = 0.0;
for (int j = offset; j < d; ++j)
fx[j] = x[j];
fx[j] = x[j];
_evaluator.eval_sub_sol(offset, fx, newdist);
}

@@ -55,18 +55,18 @@ inline void EnumerationBase::enumerate_recursive(
partdist[kk - 1] = newdist;
if (dualenum)
{
for (int j = center_partsum_begin[kk]; j > kk - 1; --j)
for (int j = center_partsum_begin[kk]; j > kk - 1; --j)
center_partsums[kk - 1][j] = center_partsums[kk - 1][j + 1] - alpha[j] * mut[kk - 1][j];
}
else
{
for (int j = center_partsum_begin[kk]; j > kk - 1; --j)
for (int j = center_partsum_begin[kk]; j > kk - 1; --j)
center_partsums[kk - 1][j] = center_partsums[kk - 1][j + 1] - x[j] * mut[kk - 1][j];
}
if (center_partsum_begin[kk] > center_partsum_begin[kk - 1])
center_partsum_begin[kk - 1] = center_partsum_begin[kk];
center_partsum_begin[kk] = kk;
center[kk - 1] = center_partsums[kk - 1][kk];
center_partsum_begin[kk] = kk;
center[kk - 1] = center_partsums[kk - 1][kk];
roundto(x[kk - 1], center[kk - 1]);
dx[kk - 1] = ddx[kk - 1] = (((int)(center[kk - 1] >= x[kk - 1]) & 1) << 1) - 1;
}
@@ -105,7 +105,7 @@ inline void EnumerationBase::enumerate_recursive(
center_partsums[kk - 1][kk - 1 + 1 + 1] - x[kk - 1 + 1] * mut[kk - 1][kk - 1 + 1];
if (kk > center_partsum_begin[kk - 1])
center_partsum_begin[kk - 1] = kk;
center[kk - 1] = center_partsums[kk - 1][kk - 1 + 1];
center[kk - 1] = center_partsums[kk - 1][kk - 1 + 1];
roundto(x[kk - 1], center[kk - 1]);
dx[kk - 1] = ddx[kk - 1] = (((int)(center[kk - 1] >= x[kk - 1]) & 1) << 1) - 1;
}
@@ -136,7 +136,7 @@ inline void EnumerationBase::enumerate_recursive(
center_partsums[kk - 1][kk - 1 + 1 + 1] - x[kk - 1 + 1] * mut[kk - 1][kk - 1 + 1];
if (kk > center_partsum_begin[kk - 1])
center_partsum_begin[kk - 1] = kk;
center[kk - 1] = center_partsums[kk - 1][kk - 1 + 1];
center[kk - 1] = center_partsums[kk - 1][kk - 1 + 1];
roundto(x[kk - 1], center[kk - 1]);
dx[kk - 1] = ddx[kk - 1] = (((int)(center[kk - 1] >= x[kk - 1]) & 1) << 1) - 1;
}
@@ -231,12 +231,12 @@ template <bool dualenum, bool findsubsols, bool enable_reset> void EnumerationBa
}
if (dualenum)
{
for (int j = center_partsum_begin[k + 1]; j > k; --j)
for (int j = center_partsum_begin[k + 1]; j > k; --j)
center_partsums[k][j] = center_partsums[k][j + 1] - alpha[j] * mut[k][j];
}
else
{
for (int j = center_partsum_begin[k + 1]; j > k; --j)
for (int j = center_partsum_begin[k + 1]; j > k; --j)
center_partsums[k][j] = center_partsums[k][j + 1] - x[j] * mut[k][j];
}
center_partsum_begin[k] = max(center_partsum_begin[k], center_partsum_begin[k + 1]);
@@ -33,8 +33,8 @@ inline void roundto(double &dest, const double &src) { dest = round(src); }

/* config */
#define MAXTEMPLATEDDIMENSION 80 // unused
//#define FORCE_ENUM_INLINE // not recommended
/* end config */
//#define FORCE_ENUM_INLINE // not recommended
/* end config */

#ifndef __has_attribute
#define __has_attribute(x) 0 // Compatibility with non - GCC/clang compilers.
@@ -120,8 +120,8 @@ class EnumerationBase

template <bool dualenum, bool findsubsols, bool enable_reset> void enumerate_loop();

virtual void reset(enumf, int) = 0;
virtual void process_solution(enumf newmaxdist) = 0;
virtual void reset(enumf, int) = 0;
virtual void process_solution(enumf newmaxdist) = 0;
virtual void process_subsolution(int offset, enumf newdist) = 0;

int rounding_backup;
@@ -112,12 +112,12 @@ void ExternalEnumeration<ZT, FT>::callback_set_config(enumf *mu, size_t mudim, b

if (_pruning.empty())
{
for (int i = 0; i < _d; ++i)
for (int i = 0; i < _d; ++i)
pruning[i] = 1.0;
}
else
{
for (int i = 0; i < _d; ++i)
for (int i = 0; i < _d; ++i)
pruning[i] = _pruning[i];
}
}
@@ -126,7 +126,7 @@ template <typename ZT, typename FT>
enumf ExternalEnumeration<ZT, FT>::callback_process_sol(enumf dist, enumf *sol)
{
for (int i = 0; i < _d; ++i)
_fx[i] = sol[i];
_fx[i] = sol[i];
_evaluator.eval_sol(_fx, dist, _maxdist);
return _maxdist;
}
@@ -135,9 +135,9 @@ template <typename ZT, typename FT>
void ExternalEnumeration<ZT, FT>::callback_process_subsol(enumf dist, enumf *subsol, int offset)
{
for (int i = 0; i < offset; ++i)
_fx[i] = 0.0;
_fx[i] = 0.0;
for (int i = offset; i < _d; ++i)
_fx[i] = subsol[i];
_fx[i] = subsol[i];
_evaluator.eval_sub_sol(offset, _fx, dist);
}

@@ -74,7 +74,7 @@ typedef uint64_t(extenum_fc_enumerate)(int dim, enumf maxdist,
std::function<extenum_cb_process_sol> cbsol,
std::function<extenum_cb_process_subsol> cbsubsol,
bool dual /*=false*/, bool findsubsols /*=false*/
);
);

// set & get external enumerator (nullptr => disabled)
void set_external_enumerator(std::function<extenum_fc_enumerate> extenum = nullptr);
@@ -239,7 +239,7 @@ void FastErrorBoundedEvaluator::eval_sub_sol(int offset,
{
sub_solutions[offset].first = dist;
sub_solutions[offset].second = new_sub_sol_coord;
for (int i = 0; i < offset; ++i)
for (int i = 0; i < offset; ++i)
sub_solutions[offset].second[i] = 0.0;
}
}
@@ -345,7 +345,7 @@ void ExactErrorBoundedEvaluator::eval_sub_sol(int offset,
{
sub_solutions[offset].first = subdist;
sub_solutions[offset].second = new_sub_sol_coord;
for (int i = 0; i < offset; ++i)
for (int i = 0; i < offset; ++i)
sub_solutions[offset].second[i] = 0.0;
}
}
@@ -46,7 +46,7 @@ enum EvaluatorStrategy
* EVALSTRATEGY_FIRST_N_SOLUTIONS
* The enumeration bound is not updated. As soon as max_sols are found, enumeration
* stops.
*/
*/
EVALSTRATEGY_BEST_N_SOLUTIONS = 0,
EVALSTRATEGY_OPPORTUNISTIC_N_SOLUTIONS = 1,
EVALSTRATEGY_FIRST_N_SOLUTIONS = 2
@@ -154,10 +154,10 @@ template <class FT> class Evaluator
};

/**
* Simple solution evaluator which provides a result without error bound.
* The same instance can be used for several calls to enumerate on different
* problems.
*/
* Simple solution evaluator which provides a result without error bound.
* The same instance can be used for several calls to enumerate on different
* problems.
*/
template <class FT> class FastEvaluator : public Evaluator<FT>
{
public:
@@ -196,7 +196,7 @@ template <class FT> class FastEvaluator : public Evaluator<FT>
{
sub_solutions[offset].first = dist;
sub_solutions[offset].second = new_sub_sol_coord;
for (int i = 0; i < offset; ++i)
for (int i = 0; i < offset; ++i)
sub_solutions[offset].second[i] = 0.0;
}
}
@@ -274,7 +274,7 @@ template <class ZT, class FT> inline void MatGSO<ZT, FT>::create_rows(int n_new_
u.set_rows(d);
for (int i = old_d; i < d; i++)
for (int j = 0; j < u.get_cols(); j++)
u[i][j] = 0;
u[i][j] = 0;
}
size_increased();
if (n_known_rows == old_d)
@@ -245,7 +245,7 @@ template <class ZT, class FT> inline void MatGSOGram<ZT, FT>::create_rows(int n_
u.set_rows(d);
for (int i = old_d; i < d; i++)
for (int j = 0; j < u.get_cols(); j++)
u[i][j] = 0;
u[i][j] = 0;
}
size_increased();
if (n_known_rows == old_d)
@@ -124,7 +124,7 @@ template <class ZT, class FT> class MatGSOInterface
* Returns maximum exponent of b. In the gram
* version it returns a half times the
* maximum exponent of g.
*/
*/
virtual long get_max_exp_of_b() = 0;

/** Returns true if the ith row
@@ -147,8 +147,8 @@ template <class ZT, class FT> class MatGSOInterface
virtual int get_rows_of_b() = 0;

/** Negates the ith row of b. Needed
* by dbkz_postprocessing.
*/
* by dbkz_postprocessing.
*/
virtual void negate_row_of_b(int i) = 0;

/**
@@ -460,8 +460,8 @@ template <class ZT, class FT> class MatGSOInterface

protected:
/** Allocates matrices and arrays whose size depends on d (all but tmp_col_expo).
* When enable_int_gram=false, initializes bf.
*/
* When enable_int_gram=false, initializes bf.
*/
virtual void size_increased() = 0;

/* Increases known rows and invalidates the last
@@ -475,8 +475,8 @@ template <class ZT, class FT> class MatGSOInterface
// Marks mu(i, j) and r(i, j) as invalid for j >= new_valid_cols
void invalidate_gso_row(int i, int new_valid_cols = 0);
/* Upates the i-th row of bf. It does not invalidate anything, so the caller
* must take into account that it might change row_expo.
*/
* must take into account that it might change row_expo.
*/
virtual void update_bf(int i) = 0;
/* Marks g(i, j) for all j <= i (but NOT for j > i) */
virtual void invalidate_gram_row(int i) = 0;
@@ -546,10 +546,10 @@ template <class ZT, class FT> class MatGSOInterface

public:
/** Replaced the gram matrix by a pointer. In the gso-class
* there is also a matrix g, and in the constructor gptr is
* defined to be equal to &g. In the ggso-class a gram matrix
* is given (arg_g), and gptr is defined as &arg_g.
*/
* there is also a matrix g, and in the constructor gptr is
* defined to be equal to &g. In the ggso-class a gram matrix
* is given (arg_g), and gptr is defined as &arg_g.
*/

/* Gram matrix (dot products of basis vectors, lower triangular matrix)
g(i, j) is valid if 0 <= i < n_known_rows and j <= i */
@@ -398,9 +398,9 @@ template <class ZT, class FT> bool HLLLReduction<ZT, FT>::verify_size_reduction(
// avoid to return it.
#ifdef DEBUG
m.get_R(ftmp1, kappa, i, expo1); // R(kappa, i) = ftmp1 * 2^expo1
#else // DEBUG
#else // DEBUG
m.get_R(ftmp1, kappa, i); // R(kappa, i) = ftmp1 * 2^expo0
#endif // DEBUG
#endif // DEBUG

FPLLL_DEBUG_CHECK(expo0 == expo1); // Since R[kappa] and b[kappa] share the same row_expo.
ftmp1.abs(ftmp1);
@@ -55,6 +55,7 @@ template <class ZT, class FT> class HLLLReduction

// Get the status of the computation
inline int get_status() { return status; }

private:
// Paramters to (delta, eta, theta) hlll-reduce the basis b in m.
FT delta, eta, theta;
@@ -173,7 +173,7 @@ template <class ZT, class FT> void MatHouseholder<ZT, FT>::update_R(int i, bool
// Copy R into R_history
// TODO: this is a row operation. Can try to copy R(i, j..n-1) directly in
// R_history[i][j](j..n-1).
for (k = j; k < n; k++)
for (k = j; k < n; k++)
R_history[i][j][k] = R(i, k);
}

Oops, something went wrong.

0 comments on commit 9e508b5

Please sign in to comment.