16#ifndef FPLLL_NUMVECT_H
17#define FPLLL_NUMVECT_H
27 if (
static_cast<int>(v.size()) < size)
36 for (; first < last; first++, last--)
37 v[first].swap(v[last]);
41template <
class T>
void rotate_by_swap(vector<T> &v,
int first,
int middle,
int last)
46 for (; first < middle && middle <= last; first++, last--)
48 v[first].swap(v[last]);
59 FPLLL_DEBUG_CHECK(0 <= first && first <= last && last <
static_cast<int>(v.size()));
60 for (
int i = first; i < last; i++)
69 FPLLL_DEBUG_CHECK(0 <= first && first <= last && last <
static_cast<int>(v.size()));
70 for (
int i = last - 1; i >= first; i--)
77template <
class T> ostream &
operator<<(ostream &os,
const vector<T> &v)
81 for (
int i = 0; i < n; i++)
92template <
class T> istream &
operator>>(istream &is, vector<T> &v)
100 is.setstate(ios::failbit);
103 while (is >> c && c !=
']')
106 v.resize(v.size() + 1);
107 if (!(is >> v.back()))
120 fill(v.begin(), v.end(), 0);
123template <
class T>
class NumVect;
156 int size()
const {
return data.size(); }
158 bool empty()
const {
return data.empty(); }
183 const T &
front()
const {
return data.front(); }
185 T &
back() {
return data.back(); }
188 const T &
back()
const {
return data.back(); }
192 if (
size() < maxSize)
193 data.resize(maxSize);
253 void fill(
long value);
256 bool is_zero(
int fromCol = 0)
const;
261 friend ostream &operator<< <T>(ostream &os,
const NumVect<T> &v);
262 friend istream &
operator>><T>(istream &is,
NumVect<T> &v);
271 for (
int i = n - 1; i >= 0; i--)
272 data[i].add(data[i], v[i]);
278 for (
int i = n - 1; i >= 0; i--)
279 data[i].sub(data[i], v[i]);
285 for (
int i = n - 1; i >= b; i--)
286 data[i].mul(v[i], c);
294 for (
int i = n - 1; i >= b; i--)
295 data[i].div(v[i], c);
303 for (
int i = n - 1; i >= beg; i--)
304 data[i].addmul(v[i], x);
309 this->addmul(v, x, 0, n);
316 for (
int i = n - 1; i >= 0; i--)
319 tmp.mul_2si(tmp, expo);
320 data[i].add(data[i], tmp);
327 for (
int i = n - 1; i >= 0; i--)
328 data[i].addmul_si(v[i], x);
335 for (
int i = n - 1; i >= 0; i--)
338 tmp.mul_2si(tmp, expo);
339 data[i].add(data[i], tmp);
346 for (
int i = 0; i < size(); i++)
348 max_expo = max(max_expo, data[i].exponent());
355 for (
int i = 0; i < size(); i++)
363 for (
int i = fromCol; i < size(); i++)
365 if (!data[i].is_zero())
374 for (i = data.size(); i > 0; i--)
376 if (data[i - 1] != 0)
390 result.mul(v1[beg], v2[beg]);
391 for (
int i = beg + 1; i < n; i++)
393 result.addmul(v1[i], v2[i]);
Definition: numvect.h:130
const T & operator[](int i) const
Definition: numvect.h:200
int size_nz() const
Definition: numvect.h:371
T & front()
Definition: numvect.h:180
void swap(NumVect &v)
Definition: numvect.h:150
void div(const NumVect< T > &v, int b, int n, T c)
Definition: numvect.h:291
void fill(long value)
Definition: numvect.h:353
NumVect(int size)
Definition: numvect.h:141
void pop_back()
Definition: numvect.h:178
void mul(const NumVect< T > &v, int b, int n, T c)
Definition: numvect.h:282
void addmul(const NumVect< T > &v, T x)
Definition: numvect.h:229
int size() const
Definition: numvect.h:156
void resize(int size)
Definition: numvect.h:160
void clear()
Definition: numvect.h:195
NumVect()
Definition: numvect.h:134
bool empty() const
Definition: numvect.h:158
void add(const NumVect< T > &v, int n)
Definition: numvect.h:268
void div(const NumVect< T > &v, T c)
Definition: numvect.h:220
bool is_zero(int fromCol=0) const
Definition: numvect.h:361
void sub(const NumVect< T > &v, int n)
Definition: numvect.h:275
iterator end()
Definition: numvect.h:154
void operator=(const NumVect &v)
Definition: numvect.h:144
void addmul_2exp(const NumVect< T > &v, const T &x, long expo, T &tmp)
Definition: numvect.h:230
void add(const NumVect< T > &v)
Definition: numvect.h:204
void rotate_right(int first, int last)
Definition: numvect.h:247
void rotate_left(int first, int last)
Definition: numvect.h:244
const iterator begin()
Definition: numvect.h:152
void extend(int maxSize)
Definition: numvect.h:190
NumVect(const vector< T > &v)
Definition: numvect.h:138
void sub(const NumVect< T > &v)
Definition: numvect.h:208
void resize(int size, const T &t)
Definition: numvect.h:162
void push_back(const T &t)
Definition: numvect.h:176
T & back()
Definition: numvect.h:185
NumVect(const NumVect &v)
Definition: numvect.h:136
void addmul_si_2exp(const NumVect< T > &v, long x, long expo, T &tmp)
Definition: numvect.h:237
const T & front() const
Definition: numvect.h:183
void gen_zero(int size)
Definition: numvect.h:164
NumVect(int size, const T &t)
Definition: numvect.h:142
void addmul(const NumVect< T > &v, T x, int beg, int n)
Definition: numvect.h:300
T & operator[](int i)
Definition: numvect.h:197
bool operator==(NumVect< T > &other)
Definition: numvect.h:173
vector< T >::iterator iterator
Definition: numvect.h:132
const T & back() const
Definition: numvect.h:188
void addmul_si(const NumVect< T > &v, long x)
Definition: numvect.h:235
void mul(const NumVect< T > &v, T c)
Definition: numvect.h:214
long get_max_exponent()
Definition: numvect.h:343
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
#define FPLLL_DEBUG_CHECK(x)
Definition: defs.h:109
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
void dot_product(T &result, const NumVect< T > &v1, const NumVect< T > &v2, int beg, int n)
Definition: numvect.h:386
void rotate_right_by_swap(vector< T > &v, int first, int last)
Definition: numvect.h:67
void squared_norm(T &result, const NumVect< T > &v)
Definition: numvect.h:409
void gen_zero_vect(vector< T > &v, int n)
Definition: numvect.h:117
istream & operator>>(istream &is, vector< T > &v)
Definition: numvect.h:92
FPLLL_BEGIN_NAMESPACE void extend_vect(vector< T > &v, int size)
Definition: numvect.h:25
void rotate_by_swap(vector< T > &v, int first, int middle, int last)
Definition: numvect.h:41
ostream & operator<<(ostream &os, const vector< T > &v)
Definition: numvect.h:77
void rotate_left_by_swap(vector< T > &v, int first, int last)
Definition: numvect.h:57
void reverse_by_swap(vector< T > &v, int first, int last)
Definition: numvect.h:34