/usr/include/fplll/numvect.h is in libfplll-dev 4.0.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | /* Copyright (C) 2011 Xavier Pujol.
This file is part of fplll. fplll is free software: you
can redistribute it and/or modify it under the terms of the GNU Lesser
General Public License as published by the Free Software Foundation,
either version 2.1 of the License, or (at your option) any later version.
fplll is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with fplll. If not, see <http://www.gnu.org/licenses/>. */
#ifndef FPLLL_NUMVECT_H
#define FPLLL_NUMVECT_H
#include "nr.h"
#include <vector>
FPLLL_BEGIN_NAMESPACE
template<class T>
void extendVect(vector<T>& v, int size) {
if (static_cast<int>(v.size()) < size) {
v.resize(size);
}
}
template<class T>
void reverseBySwap(vector<T>& v, int first, int last) {
for (; first < last; first++, last--)
v[first].swap(v[last]);
}
template<class T>
void rotateBySwap(vector<T>& v, int first, int middle, int last) {
// Algorithm from STL code
reverseBySwap(v, first, middle - 1);
reverseBySwap(v, middle, last);
for (; first < middle && middle <= last; first++, last--) {
v[first].swap(v[last]);
}
if (first == middle)
reverseBySwap(v, middle, last);
else
reverseBySwap(v, first, middle - 1);
}
template<class T>
void rotateLeftBySwap(vector<T>& v, int first, int last) {
FPLLL_DEBUG_CHECK(0 <= first && first <= last
&& last < static_cast<int>(v.size()));
for (int i = first; i < last; i++) {
v[i].swap(v[i + 1]);
}
}
template<class T>
void rotateRightBySwap(vector<T>& v, int first, int last) {
FPLLL_DEBUG_CHECK(0 <= first && first <= last
&& last < static_cast<int>(v.size()));
for (int i = last - 1; i >= first; i--) {
v[i].swap(v[i + 1]);
}
}
/** Prints a vector on stream os. */
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
int n = v.size();
for (int i = 0; i < n; i++) {
if (i > 0) os << " ";
os << v[i];
}
os << "]";
return os;
}
/** Reads a vector from stream is. */
template<class T>
istream& operator>>(istream& is, vector<T>& v) {
char c;
v.clear();
if (!(is >> c)) return is;
if (c != '[') {
is.setstate(ios::failbit);
return is;
}
while (is >> c && c != ']') {
is.putback(c);
v.resize(v.size() + 1);
if (!(is >> v.back())) {
v.pop_back();
return is;
}
}
return is;
}
template<class T>
void genZeroVect(vector<T>& v, int n) {
v.resize(n);
fill(v.begin(), v.end(), 0);
}
template<class T>
class NumVect;
template<class T>
ostream& operator<<(ostream& os, const NumVect<T>& v);
template<class T>
istream& operator>>(istream& is, NumVect<T>& v);
template<class T>
class NumVect {
public:
typedef typename vector<T>::iterator iterator;
NumVect() {}
NumVect(const NumVect& v) : data(v.data) {}
NumVect(int size) : data(size) {} // Initial content is undefined
NumVect(int size, const T& t) : data(size, t) {}
void operator=(const NumVect& v) {
if (this != &v)
data = v.data;
}
void swap(NumVect& v) {
data.swap(v.data);
}
const iterator begin() {
return data.begin();
}
iterator end() {
return data.end();
}
int size() const {
return data.size();
}
bool empty() const {
return data.empty();
}
void resize(int size) {
data.resize(size);
}
void resize(int size, const T& t) {
data.resize(size, t);
}
void gen_zero(int size) {
data.resize(size);
fill(0);
}
void push_back(const T& t) {
data.push_back(t);
}
void pop_back() {
data.pop_back();
}
T& front() {
return data.front();
}
const T& front() const {
return data.front();
}
T& back() {
return data.back();
}
const T& back() const {
return data.back();
}
void extend(int maxSize) {
if (size() < maxSize)
data.resize(maxSize);
}
void clear() {
data.clear();
}
T& operator[](int i) {
return data[i];
}
const T& operator[](int i) const {
return data[i];
}
void add(const NumVect<T>& v) {
add(v, size());
}
void add(const NumVect<T>& v, int n);
void sub(const NumVect<T>& v) {
sub(v, size());
}
void sub(const NumVect<T>& v, int n);
void addmul_2exp(const NumVect<T>& v, const T& x, long expo, T& tmp) {
addmul_2exp(v, x, expo, size(), tmp);
}
void addmul_2exp(const NumVect<T>& v, const T& x, long expo, int n, T& tmp);
void addmul_si(const NumVect<T>& v, long x) {
addmul_si(v, x, size());
}
void addmul_si(const NumVect<T>& v, long x, int n);
void addmul_si_2exp(const NumVect<T>& v, long x,
long expo, T& tmp) {
addmul_si_2exp(v, x, expo, size(), tmp);
}
void addmul_si_2exp(const NumVect<T>& v, long x,
long expo, int n, T& tmp);
/** (v[first],...,v[last]) becomes (v[first+1],...,v[last],v[first]) */
void rotateLeft(int first, int last) {
rotateLeftBySwap(data, first, last);
}
/** (v[first],...,v[last]) becomes (v[last],v[first],...,v[last-1]) */
void rotateRight(int first, int last) {
rotateRightBySwap(data, first, last);
}
/** Returns expo >= 0 such that all elements are < 2^expo. */
long getMaxExponent();
void fill(long value);
bool is_zero(int fromCol = 0) const;
int sizeNZ() const;
friend ostream& operator<< <T>(ostream& os, const NumVect<T>& v);
friend istream& operator>> <T>(istream& is, NumVect<T>& v);
private:
vector<T> data;
};
template<class T>
void NumVect<T>::add(const NumVect<T>& v, int n) {
FPLLL_DEBUG_CHECK(n <= size() && size() == v.size() && v.is_zero(n));
for (int i = n - 1; i >= 0; i--)
data[i].add(data[i], v[i]);
}
template<class T>
void NumVect<T>::sub(const NumVect<T>& v, int n) {
FPLLL_DEBUG_CHECK(n <= size() && size() == v.size() && v.is_zero(n));
for (int i = n - 1; i >= 0; i--)
data[i].sub(data[i], v[i]);
}
template<class T>
void NumVect<T>::addmul_2exp(const NumVect<T>& v, const T& x,
long expo, int n, T& tmp) {
FPLLL_DEBUG_CHECK(n <= size() && size() == v.size() && v.is_zero(n));
for (int i = n - 1; i >= 0; i--) {
tmp.mul(v[i], x);
tmp.mul_2si(tmp, expo);
data[i].add(data[i], tmp);
}
}
template<class T>
void NumVect<T>::addmul_si(const NumVect<T>& v, long x, int n) {
FPLLL_DEBUG_CHECK(n <= size() && size() == v.size() && v.is_zero(n));
for (int i = n - 1; i >= 0; i--)
data[i].addmul_si(v[i], x);
}
template<class T>
void NumVect<T>::addmul_si_2exp(const NumVect<T>& v, long x,
long expo, int n, T& tmp) {
FPLLL_DEBUG_CHECK(n <= size() && size() == v.size() && v.is_zero(n));
for (int i = n - 1; i >= 0; i--) {
tmp.mul_si(v[i], x);
tmp.mul_2si(tmp, expo);
data[i].add(data[i], tmp);
}
}
template<class T>
long NumVect<T>::getMaxExponent() {
long maxExpo = 0;
for (int i = 0; i < size(); i++) {
maxExpo = max(maxExpo, data[i].exponent());
}
return maxExpo;
}
template<class T>
void NumVect<T>::fill(long value) {
for (int i = 0; i < size(); i++) {
data[i] = value;
}
}
template<class T>
bool NumVect<T>::is_zero(int fromCol) const {
for (int i = fromCol; i < size(); i++) {
if (!data[i].is_zero()) return false;
}
return true;
}
template<class T>
int NumVect<T>::sizeNZ() const {
int i;
for (i = data.size(); i > 0; i--) {
if (data[i - 1] != 0) break;
}
return i;
}
template<class T>
void dotProduct(T& result, const NumVect<T>& v1,
const NumVect<T>& v2, int n) {
FPLLL_DEBUG_CHECK(n > 0 && n <= v1.size() && v1.size() == v2.size()
&& (v1.is_zero(n) || v2.is_zero(n)));
result.mul(v1[0], v2[0]);
for (int i = 1; i < n; i++) {
result.addmul(v1[i], v2[i]);
}
}
template<class T>
inline void dotProduct(T& result, const NumVect<T>& v1, const NumVect<T>& v2) {
dotProduct(result, v1, v2, v1.size());
}
template<class T>
inline void squaredNorm(T& result, const NumVect<T>& v) {
dotProduct(result, v, v);
}
/** Prints a NumVect on stream os. */
template<class T>
ostream& operator<<(ostream& os, const NumVect<T>& v) {
return os << v.data;
}
/** Reads a NumVect from stream is. */
template<class T>
istream& operator>>(istream& is, NumVect<T>& v) {
return is >> v.data;
}
typedef vector<Integer> IntVect;
typedef vector<Float> FloatVect;
FPLLL_END_NAMESPACE
#endif
|