/usr/include/NTL/matrix.h is in libntl-dev 9.9.1-3.
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 | #ifndef NTL_matrix__H
#define NTL_matrix__H
#include <NTL/tools.h>
#include <NTL/vector.h>
// matrix templates
NTL_OPEN_NNS
template<class T>
class Mat {
private:
struct Fixer {
long m;
explicit Fixer(long _m) : m(_m) { }
void operator()(Vec<T>& v) { v.FixLength(m); }
};
public:
// pseudo-private fields
Vec< Vec<T> > _mat__rep;
long _mat__numcols;
// really public fields
typedef typename Vec<T>::value_type value_type;
typedef typename Vec<T>::reference reference;
typedef typename Vec<T>::const_reference const_reference;
Mat() : _mat__numcols(0) { }
Mat(const Mat& a);
Mat& operator=(const Mat& a);
~Mat() { }
Mat(INIT_SIZE_TYPE, long n, long m);
void kill();
void SetDims(long n, long m);
long NumRows() const { return _mat__rep.length(); }
long NumCols() const { return _mat__numcols; }
Vec<T>& operator[](long i) { return _mat__rep[i]; }
const Vec<T>& operator[](long i) const { return _mat__rep[i]; }
Vec<T>& operator()(long i) { return _mat__rep[i-1]; }
const Vec<T>& operator()(long i) const { return _mat__rep[i-1]; }
reference operator()(long i, long j) { return _mat__rep[i-1][j-1]; }
const_reference operator()(long i, long j) const
{ return _mat__rep[i-1][j-1]; }
const_reference get(long i, long j) const { return _mat__rep[i].get(j); }
void put(long i, long j, const T& a) { _mat__rep[i].put(j, a); }
template <class U>
void put(long i, long j, const U& a) { _mat__rep[i].put(j, a); }
long position(const Vec<T>& a) const { return _mat__rep.position(a); }
long position1(const Vec<T>& a) const { return _mat__rep.position1(a); }
Mat(Mat& x, INIT_TRANS_TYPE) :
_mat__rep(x._mat__rep, INIT_TRANS), _mat__numcols(x._mat__numcols) { }
void swap(Mat& other)
{
_mat__rep.swap(other._mat__rep);
_ntl_swap(_mat__numcols, other._mat__numcols);
}
};
template<class T>
inline const Vec< Vec<T> >& rep(const Mat<T>& a)
{ return a._mat__rep; }
template<class T>
Mat<T>::Mat(const Mat& src) :
_mat__rep(src._mat__rep), _mat__numcols(src._mat__numcols)
{
long i, nrows;
nrows = _mat__rep.length();
for (i = 0; i < nrows; i++)
_mat__rep[i].FixAtCurrentLength();
}
template<class T>
Mat<T>& Mat<T>::operator=(const Mat& src)
{
if (this == &src) return *this;
if (src.NumCols() == 0)
SetDims(src.NumRows(), src.NumCols());
else if (NumCols() != src.NumCols()) {
Mat<T> tmp(src);
this->swap(tmp);
}
else {
long i, init, len;
init = _mat__rep.MaxLength();
len = src._mat__rep.length();
_mat__rep = src._mat__rep;
for (i = init; i < len; i++)
_mat__rep[i].FixAtCurrentLength();
}
return *this;
}
template<class T>
Mat<T>::Mat(INIT_SIZE_TYPE, long n, long m) : _mat__numcols(0)
{
SetDims(n, m);
}
template<class T>
void Mat<T>::kill()
{
Mat<T> tmp;
this->swap(tmp);
}
// This is designed to provide strong ES
template<class T>
void Mat<T>::SetDims(long n, long m)
{
if (n < 0 || m < 0)
LogicError("SetDims: bad args");
long init = _mat__rep.MaxLength();
if (init > 0 && m != _mat__numcols) {
Mat<T> tmp;
tmp._mat__rep.SetLengthAndApply(n, Fixer(m));
tmp._mat__numcols = m;
this->swap(tmp);
}
else {
_mat__rep.SetLengthAndApply(n, Fixer(m));
_mat__numcols = m;
}
}
template<class T>
void MakeMatrix(Mat<T>& x, const Vec< Vec<T> >& a)
{
long n = a.length();
if (n == 0) {
x.SetDims(0, 0);
return;
}
long m = a[0].length();
long i;
for (i = 1; i < n; i++)
if (a[i].length() != m)
LogicError("nonrectangular matrix");
x.SetDims(n, m);
for (i = 0; i < n; i++)
x[i] = a[i];
}
template<class T>
void swap(Mat<T>& X, Mat<T>& Y)
{
X.swap(Y);
}
template<class T>
long operator==(const Mat<T>& a, const Mat<T>& b)
{
if (a.NumCols() != b.NumCols())
return 0;
if (a.NumRows() != b.NumRows())
return 0;
long n = a.NumRows();
long i;
for (i = 0; i < n; i++)
if (a[i] != b[i])
return 0;
return 1;
}
template<class T>
long operator!=(const Mat<T>& a, const Mat<T>& b)
{
return !(a == b);
}
template<class T>
NTL_SNS istream& operator>>(NTL_SNS istream& s, Mat<T>& x)
{
Vec< Vec<T> > buf;
NTL_INPUT_CHECK_RET(s, s >> buf);
MakeMatrix(x, buf);
return s;
}
template<class T>
NTL_SNS ostream& operator<<(NTL_SNS ostream& s, const Mat<T>& a)
{
long n = a.NumRows();
long i;
s << "[";
for (i = 0; i < n; i++) {
s << a[i];
s << "\n";
}
s << "]";
return s;
}
// conversion
template<class T, class S>
void conv(Mat<T>& x, const Mat<S>& a)
{
x.SetDims(a.NumRows(), a.NumCols());
conv(x._mat__rep, a._mat__rep);
}
NTL_CLOSE_NNS
#endif
|