From 4d4ab9936b63e86144b3a421e6937feec2fa2d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Sun, 25 Aug 2019 21:17:23 +0300 Subject: [PATCH] =?UTF-8?q?Variable=20Lov=C3=A1sz=20condition=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 726d5c1b1dc03a5b11f8d7b32e6bf589efec369d --- qpms/lattices.h | 3 ++- qpms/lll.c | 5 +++-- qpms/qpms_c.pyx | 4 ++-- qpms/qpms_cdefs.pxd | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/qpms/lattices.h b/qpms/lattices.h index b9c28dd..45a7322 100644 --- a/qpms/lattices.h +++ b/qpms/lattices.h @@ -72,7 +72,8 @@ static inline point2d point2d_fromxy(const double x, const double y) { */ int qpms_reduce_lattice_basis(double *b, ///< Array of dimension [bsize][ndim]. const size_t bsize, ///< Number of the basis vectors (dimensionality of the lattice). - const size_t ndim ///< Dimension of the space into which the lattice is embedded. + const size_t ndim, ///< Dimension of the space into which the lattice is embedded. + double delta ); /// Generic lattice point generator type. diff --git a/qpms/lll.c b/qpms/lll.c index 02fc0da..bf381fa 100644 --- a/qpms/lll.c +++ b/qpms/lll.c @@ -38,7 +38,8 @@ static void gram_schmidt( static inline double fsq(double x) { return x * x; }; // A naïve implementation of Lenstra-Lenstra-Lovász algorithm. -int qpms_reduce_lattice_basis(double *b, const size_t bsize, const size_t ndim) +int qpms_reduce_lattice_basis(double *b, const size_t bsize, const size_t ndim, + double delta) { QPMS_ENSURE(bsize <= ndim, "The basis must have less elements (%zd) than the space dimension (%zd).", @@ -59,7 +60,7 @@ int qpms_reduce_lattice_basis(double *b, const size_t bsize, const size_t ndim) } // Step 2 if (k > 0 && // Case 1 - bstar_sqnorm[k] < (0.75 - fsq(mu[mu_index(k, k-1)])) * bstar_sqnorm[k-1]) { + bstar_sqnorm[k] < (delta - fsq(mu[mu_index(k, k-1)])) * bstar_sqnorm[k-1]) { // swap b(k) and b(k-1) cblas_dswap(ndim, &b[k*ndim], 1, &b[(k-1)*ndim], 1); double B_k = bstar_sqnorm[k]; diff --git a/qpms/qpms_c.pyx b/qpms/qpms_c.pyx index cfb6218..6e7ba36 100644 --- a/qpms/qpms_c.pyx +++ b/qpms/qpms_c.pyx @@ -610,7 +610,7 @@ def gamma_inc_CF(double a, cdouble x): cx_gamma_inc_CF_e(a, x, &res) return (res.val, res.err) -def lll_reduce(basis): +def lll_reduce(basis, double delta=0.75): """ Lattice basis reduction with the Lenstra-Lenstra-Lovász algorithm. @@ -630,7 +630,7 @@ def lll_reduce(basis): "the dimensionality of the lattice (%d) embedded into it." % (d, n)) cdef double [:,:] basis_view = basis - if 0 != qpms_reduce_lattice_basis(&basis_view[0,0], n, d): + if 0 != qpms_reduce_lattice_basis(&basis_view[0,0], n, d, delta): raise RuntimeError("Something weird happened") return basis diff --git a/qpms/qpms_cdefs.pxd b/qpms/qpms_cdefs.pxd index 9987119..940c7f0 100644 --- a/qpms/qpms_cdefs.pxd +++ b/qpms/qpms_cdefs.pxd @@ -209,7 +209,7 @@ cdef extern from "lattices.h": PGEN_1D_INC_TOWARDS_ORIGIN PGen PGen_1D_new_minMaxR(double period, double offset, double minR, bint inc_minR, double maxR, bint inc_maxR, PGen_1D_incrementDirection incdir) - int qpms_reduce_lattice_basis(double *b, size_t bsize, size_t ndim) + int qpms_reduce_lattice_basis(double *b, size_t bsize, size_t ndim, double delta) cdef extern from "quaternions.h":