util.h
Go to the documentation of this file.
1/* Copyright (C) 2005-2008 Damien Stehle.
2 Copyright (C) 2007 David Cade.
3 Copyright (C) 2011 Xavier Pujol.
4
5 This file is part of fplll. fplll is free software: you
6 can redistribute it and/or modify it under the terms of the GNU Lesser
7 General Public License as published by the Free Software Foundation,
8 either version 2.1 of the License, or (at your option) any later version.
9
10 fplll is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with fplll. If not, see <http://www.gnu.org/licenses/>. */
20#ifndef FPLLL_UTIL_H
21#define FPLLL_UTIL_H
22
23#include "nr/matrix.h"
24
26
27static inline int cputime()
28{
29#ifdef FPLLL_WITH_GETRUSAGE
30 struct rusage rus;
31 getrusage(RUSAGE_SELF, &rus);
32 return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
33#else
34 return time(NULL) * 1000;
35#endif
36}
37
38/* Computes result = x * m (it is not required that result is initialized,
39 x.size() must be equal to m.GetNumRows()) */
40template <class ZT>
41void vector_matrix_product(vector<ZT> &result, const vector<ZT> &x, const Matrix<ZT> &m)
42{
43 int nrows = m.get_rows(), ncols = m.get_cols();
44 FPLLL_CHECK(x.size() == (unsigned int)nrows, "vector_matrix_product(): dimensions do not match!");
45 gen_zero_vect(result, ncols);
46 for (int i = 0; i < nrows; i++)
47 for (int j = 0; j < ncols; j++)
48 result[j].addmul(x[i], m(i, j));
49}
50
51/* Computes result = x * m (it is not required that result is initialized,
52 x.size() must be equal to m.GetNumRows()) */
53template <class ZT>
55{
56 int nrows = m.get_rows(), ncols = m.get_cols();
57 FPLLL_CHECK(x.size() == nrows, "vector_matrix_product(): dimensions do not match!");
58 result.gen_zero(ncols);
59 for (int i = 0; i < nrows; i++)
60 for (int j = 0; j < ncols; j++)
61 result[j].addmul(x[i], m(i, j));
62}
63
64const double DEF_GSO_PREC_EPSILON = 0.03;
65
74int gso_min_prec(double &rho, int d, double delta, double eta,
75 double epsilon = DEF_GSO_PREC_EPSILON);
76
80int l2_min_prec(int d, double delta, double eta, double epsilon);
81
85int hlll_min_prec(int d_i, int n_i, double delta, double eta, double theta, double c);
86
90void sphere_volume(FP_NR<mpfr_t> &volume, int d);
91
95void cost_estimate(FP_NR<mpfr_t> &cost, const FP_NR<mpfr_t> &bound, const Matrix<FP_NR<mpfr_t>> &r,
96 int dimMax);
97
98template <class ZT> void zeros_first(ZZ_mat<ZT> &b, ZZ_mat<ZT> &u, ZZ_mat<ZT> &u_inv_t);
99
100template <class ZT> void zeros_last(ZZ_mat<ZT> &b, ZZ_mat<ZT> &u, ZZ_mat<ZT> &u_inv_t);
101
105const char *get_red_status_str(int status);
106
108
109#endif
int get_cols() const
Definition: matrix.h:156
int get_rows() const
Definition: matrix.h:154
Definition: numvect.h:130
int size() const
Definition: numvect.h:156
void gen_zero(int size)
Definition: numvect.h:164
Definition: matrix.h:244
#define FPLLL_CHECK(x, y)
Definition: defs.h:81
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
void gen_zero_vect(vector< T > &v, int n)
Definition: numvect.h:117
void sphere_volume(FP_NR< mpfr_t > &volume, int d)
Definition: util.cpp:207
void zeros_first(ZZ_mat< ZT > &b, ZZ_mat< ZT > &u, ZZ_mat< ZT > &u_inv_t)
Definition: util.cpp:257
int gso_min_prec(double &rho, int d, double delta, double eta, double epsilon=DEF_GSO_PREC_EPSILON)
Definition: util.cpp:99
int hlll_min_prec(int d_i, int n_i, double delta, double eta, double theta, double c)
Definition: util.cpp:110
void vector_matrix_product(vector< ZT > &result, const vector< ZT > &x, const Matrix< ZT > &m)
Definition: util.h:41
void cost_estimate(FP_NR< mpfr_t > &cost, const FP_NR< mpfr_t > &bound, const Matrix< FP_NR< mpfr_t > > &r, int dimMax)
Definition: util.cpp:229
const char * get_red_status_str(int status)
Definition: util.cpp:249
static FPLLL_BEGIN_NAMESPACE int cputime()
Definition: util.h:27
int l2_min_prec(int d, double delta, double eta, double epsilon)
Definition: util.cpp:104
const double DEF_GSO_PREC_EPSILON
Definition: util.h:64
void zeros_last(ZZ_mat< ZT > &b, ZZ_mat< ZT > &u, ZZ_mat< ZT > &u_inv_t)
Definition: util.cpp:273