This file is indexed.

/usr/include/fplll/nr/matrix.h is in libfplll-dev 5.0.3-1.

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
/* Copyright (C) 2005-2008 Damien Stehle.
   Copyright (C) 2007 David Cade.
   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_MATRIX_H
#define FPLLL_MATRIX_H

#include "fplll/nr/numvect.h"

FPLLL_BEGIN_NAMESPACE

enum MatPrintMode
{
  MAT_PRINT_COMPACT = 0,
  MAT_PRINT_REGULAR = 1
};

template <class T> class Matrix;

/** MatrixRow stores a reference to a row of a Matrix. It supports a subset
    of operations available on vectors. */
template <class T> class MatrixRow
{
public:
  /** Returns a reference to the i-th element of this row. */
  T &operator[](int i) { return row[i]; }
  /** Returns a const reference to the i-th element of this row on constant
      objects. */
  const T &operator[](int i) const { return row[i]; }
  /** Returns the number of columns. */
  int size() const { return row.size(); }
  /** Prints this object on stream os. */
  void print(ostream &os) const { os << row; }

  bool is_zero(int from = 0) const { return row.is_zero(from); }
  int size_nz() const { return row.size_nz(); }
  void fill(long value) { row.fill(value); }
  void add(const MatrixRow<T> &v) { row.add(v.row); }
  void add(const MatrixRow<T> &v, int n) { row.add(v.row, n); }
  void sub(const MatrixRow<T> &v) { row.sub(v.row); }
  void sub(const MatrixRow<T> &v, int n) { row.sub(v.row, n); }
  void addmul(const MatrixRow<T> &v, T x) { row.addmul(v.row, x); }
  void addmul(const MatrixRow<T> &v, T x, int n) { row.addmul(v.row, x, n); }
  void addmul_2exp(const MatrixRow<T> &v, const T &x, long expo, T &tmp)
  {
    row.addmul_2exp(v.row, x, expo, tmp);
  }
  void addmul_2exp(const MatrixRow<T> &v, const T &x, long expo, int /*n*/, T &tmp)
  {
    row.addmul_2exp(v.row, x, expo, tmp);
  }
  void addmul_si(const MatrixRow<T> &v, long x) { row.addmul_si(v.row, x); }
  void addmul_si(const MatrixRow<T> &v, long x, int n) { row.addmul_si(v.row, x, n); }
  void addmul_si_2exp(const MatrixRow<T> &v, long x, long expo, T &tmp)
  {
    row.addmul_si_2exp(v.row, x, expo, tmp);
  }
  void addmul_si_2exp(const MatrixRow<T> &v, long x, long expo, int n, T &tmp)
  {
    row.addmul_si_2exp(v.row, x, expo, n, tmp);
  }

  friend class Matrix<T>;

private:
  MatrixRow(const NumVect<T> &row) : row(const_cast<NumVect<T> &>(row)) {}
  NumVect<T> &row;
};

template <class T>
void dot_product(T &result, const MatrixRow<T> &v1, const MatrixRow<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 dot_product(T &result, const MatrixRow<T> &v1, const MatrixRow<T> &v2)
{
  dot_product(result, v1, v2, v1.size());
}

/** Prints a MatrixRow on stream os. */
template <class T> ostream &operator<<(ostream &os, const MatrixRow<T> &row)
{
  row.print(os);
  return os;
}

/** Matrix is a two-dimensional container. Read and write operations on single
    elements are in constant time. The amortized complexity of resizing the
    matrix is proportional to the number of added/removed elements. All indices
    are 0-based. */
template <class T> class Matrix
{
public:
  /** Creates an empty matrix (0 x 0). */
  Matrix() : r(0), c(0) {}
  /** Creates a matrix of dimensions rows x cols. All elements are
      initialized with the default constructor of T. */
  Matrix(int rows, int cols) : r(0), c(0) { resize(rows, cols); }

  /** Sets number of rows and the number of columns to 0. */
  void clear()
  {
    r = c = 0;
    matrix.clear();
  }
  /** Returns true if the matrix has 0 rows, false otherwise. */
  bool empty() const { return r == 0; }
  /** Sets the dimensions of this matrix, preserving as much as possible of the
      content. The value of new elements is undefined. */
  void resize(int rows, int cols);
  /** Sets the number of rows. Content is not erased except for deleted rows.
      The value of new elements is undefined. */
  void set_rows(int rows) { resize(rows, c); }
  /** Sets the number of columns. Content is not erased except for deleted
      columns. The value of new elements is undefined. */
  void set_cols(int cols) { resize(r, cols); }
  /** Fills this matrix with a given value. */
  template <class U> void fill(U value);
  /** Efficiently swaps two matrices. */
  void swap(Matrix<T> &m)
  {
    matrix.swap(m.matrix);
    std::swap(r, m.r);
    std::swap(c, m.c);
  }

  /** Returns the number of rows */
  int get_rows() const { return r; }
  /** Returns the number of columns */
  int get_cols() const { return c; }
  /** Returns a reference to the element (i, j). */
  T &operator()(int i, int j)
  {
    FPLLL_DEBUG_CHECK(i >= 0 && i < r && j >= 0 && j < c);
    return matrix[i][j];
  }
  /** Returns a constant reference to the element (i, j) on constant objects. */
  const T &operator()(int i, int j) const
  {
    FPLLL_DEBUG_CHECK(i >= 0 && i < r && j >= 0 && j < c);
    return matrix[i][j];
  }
  /** Returns a MatrixRow object pointing to the i-th row of this matrix. */
  MatrixRow<T> operator[](int i)
  {
    FPLLL_DEBUG_CHECK(i >= 0 && i < r);
    return MatrixRow<T>(matrix[i]);
  }
  /** Returns a MatrixRow object pointing to the i-th row of this matrix
      on constant objects. */
  const MatrixRow<T> operator[](int i) const
  {
    FPLLL_DEBUG_CHECK(i >= 0 && i < r);
    return MatrixRow<T>(matrix[i]);
  }
  /** Rows swap. */
  void swap_rows(int r1, int r2) { matrix[r1].swap(matrix[r2]); }
  /** Rows permutation.
      (m[first],...,m[last]) becomes (m[first+1],...,m[last],m[first]) */
  void rotate_left(int first, int last) { rotate_left_by_swap(matrix, first, last); }
  /** Rows permutation.
      (m[first],...,m[last]) becomes (m[last],m[first],...,m[last-1]) */
  void rotate_right(int first, int last) { rotate_right_by_swap(matrix, first, last); }
  /** Rows permutation.
      (m[first],...,m[middle-1],m[middle],m[last]) becomes
      (m[middle],...,m[last],m[first],...,m[middle-1]) */
  void rotate(int first, int middle, int last) { rotate_by_swap(matrix, first, middle, last); }
  /** Transformation needed to update the lower triangular Gram matrix when
     rotate_left(first, last) is done on the basis of the lattice. */
  void rotate_gram_left(int first, int last, int n_valid_rows);
  /** Transformation needed to update the lower triangular Gram matrix when
      rotate_right(first, last) is done on the basis of the lattice. */
  void rotate_gram_right(int first, int last, int n_valid_rows);
  /** Transpose. */
  void transpose();
  T get_max();
  long get_max_exp();
  /** Prints this matrix. No end-of-line is printed after the last line.
      @param os      output stream
      @param nrows   maximum number of rows to display (optional)
      @param ncols   maximum number of columns to display (optional) */
  void print(ostream &os, int nrows = -1, int ncols = -1) const;
  /** Reads this matrix from a stream. */
  void read(istream &is);

  static int set_print_mode(int new_print_mode)
  {
    int old_mode = print_mode;
    print_mode   = new_print_mode;
    return old_mode;
  }

protected:
  int r, c;
  vector<NumVect<T>> matrix;

  static int print_mode;
};

template <class T> int Matrix<T>::print_mode = MAT_PRINT_COMPACT;

template <class T> ostream &operator<<(ostream &os, const Matrix<T> &m)
{
  m.print(os);
  return os;
}

template <class T> istream &operator>>(istream &is, Matrix<T> &m)
{
  m.read(is);
  return is;
}

/** ZZ_mat is a matrix of integers. */
template <class ZT> class ZZ_mat : public Matrix<Z_NR<ZT>>
{
public:
  typedef Z_NR<ZT> T;
  using Matrix<T>::r;
  using Matrix<T>::c;
  using Matrix<T>::matrix;
  using Matrix<T>::resize;
  using Matrix<T>::get_cols;
  using Matrix<T>::get_rows;

  /** Creates an empty matrix (0 x 0). */
  ZZ_mat() : Matrix<T>() {}
  /** Creates a matrix of dimensions rows x cols. All elements are
      initialized with the default constructor of Z_NR&lt;T&gt;. */
  ZZ_mat(int rows, int cols) : Matrix<T>(rows, cols) {}

  // generators
  void gen_zero(int d, int n)
  {
    resize(d, n);
    for (int i = 0; i < d; i++)
      matrix[i].fill(0);
  }

  void gen_identity(int d)
  {
    gen_zero(d, d);
    for (int i     = 0; i < d; i++)
      matrix[i][i] = 1;
  }

  void gen_intrel(int bits);
  void gen_simdioph(int bits, int bits2);
  void gen_uniform(int bits);

  /** Construct a matrix `[[I,H],[0,qI]]` where `H` is constructed from rotations of a vector ``h``.

     @note The constructed matrix will not come with a guarantee of unusually short vectors.
  **/

  void gen_ntrulike(int bits);
  void gen_ntrulike_withq(int q);

  /** Construct a matrix ``[[qI,0],[H,I]]`` where ``H`` is constructed from rotations of a vector
    ``h``.

    @note The constructed matrix will not come with a guarantee of unusually short vectors.
  */

  void gen_ntrulike2(int bits);
  void gen_ntrulike2_withq(int q);

  /** Construct a matrix ``[[I,H],[0,Iq]]`` where ``H`` is uniform mod q, of dimensions (n-k) x k.
  */

  void gen_qary(int k, Z_NR<ZT> &q);

  void gen_qary(int k, int bits)
  {
    Z_NR<ZT> q;
    q.randb(bits);
    gen_qary(k, q);
  }

  void gen_qary_withq(int k, int q)
  {
    Z_NR<ZT> q2;
    q2 = q;
    gen_qary(k, q2);
  }

  void gen_qary_prime(int k, int bits)
  {
    Z_NR<ZT> q;
    q.randb(bits);
    q.nextprime(q);
    gen_qary(k, q);
  }

  /** Construct a lower triangular matrices with specified diagonal coefficients
and random sub-diagonal coefficients.
  */

  void gen_trg(double alpha);
  void gen_trg2(FP_NR<mpfr_t> *w);
};

/** FP_mat is a matrix of floating-point numbers. */
template <class FT> class FP_mat : public Matrix<FP_NR<FT>>
{
public:
  typedef FP_NR<FT> T;
  /** Creates an empty matrix (0 x 0). */
  FP_mat() : Matrix<T>() {}
  /** Creates a matrix of dimensions rows x cols. All elements are
      initialized with the default constructor of FP_NR&lt;T&gt;. */
  FP_mat(int rows, int cols) : Matrix<T>(rows, cols) {}
};

typedef ZZ_mat<IntegerT> IntMatrix;
typedef FP_mat<FloatT> FloatMatrix;

FPLLL_END_NAMESPACE

#include "fplll/nr/matrix.cpp"

#endif