/usr/include/linbox/matrix/sparsematrix/sparse-tpl-matrix.inl is in liblinbox-dev 1.4.2-5build1.
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 | /* linbox/matrix/sparsematrix/sparse-tpl-matrix-omp.inl
* Copyright (c) LinBox
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox 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.
*
* This library 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 this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
* Written by Rich Seagraves <seagrave@cis.udel.edu>
* with mods by bds and Alex Stachnik
*/
/** @file matrix/sparsematrix/sparse-tpl-matrix-omp.inl
* @ingroup blackbox
* @brief A COO (vector of i,j,v triples) sparse matrix rep.
*/
#ifndef __LINBOX_triplesbb_INL
#define __LINBOX_triplesbb_INL
#include <algorithm>
#include <iostream>
//#include <vector>
#include "linbox/util/matrix-stream.h"
namespace LinBox
{
// template<class Field_> SparseMatrix<Field_,SparseMatrixFormat::TPL>::
// SparseMatrix() : MD_(), data_(), rows_(0), cols_(0), sort_(unsorted) {}
template<class Field_>
SparseMatrix<Field_,SparseMatrixFormat::TPL>::
~SparseMatrix() {}
template<class Field_>
SparseMatrix<Field_,SparseMatrixFormat::TPL>::
SparseMatrix(const Field& F, std::istream& in)
: MD_(F), data_(), rows_(0), cols_(0), sort_(unsorted)
{ read(in); }
template<class Field_>
SparseMatrix<Field_,SparseMatrixFormat::TPL>::
SparseMatrix(MatrixStream<Field_> &ms):
MD_(ms.field()), data_(), rows_(0), cols_(0), sort_(unsorted)
{
Index r, c;
typename Field::Element v; field().init(v);
ms.getDimensions(r, c);
init(field(), r, c);
while (ms.nextTriple(r, c, v)) setEntry(r, c, v);
finalize();
}
template<class Field_>
std::istream& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
read(std::istream& in){
Index r, c;
typename Field::Element v; field().init(v);
MatrixStream<Field> ms(field(), in);
ms.getDimensions(r, c);
init(field(), r, c);
while (ms.nextTriple(r, c, v)) setEntry(r, c, v);
finalize();
return in;
}
template<class Field_>
template<class Format>
std::ostream& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
write(std::ostream& out,
Format f ) const{
return write(out);
}
template<class Field_>
std::ostream& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
write(std::ostream& out ) const{
// linbox_check(f == SparseFileFormat::COO());
//! @bug we should not support too many formats
out << "%%MatrixMarket matrix coordinate integer general" << std::endl;
out << "% written from a LinBox SparseMatrix" << std::endl;
out << rowdim() <<" " << coldim() << " " << size() << std::endl;
for (Index k = 0; k < size(); ++k) {
Triple t = data_[k];
field().write(out << t.row+1 << " " << t.col+1 << " ", t.elt) << std::endl;
}
return out;
}
template<class Field_>
SparseMatrix<Field_,SparseMatrixFormat::TPL>& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
init(const Field& F, Index r, Index c)
{ MD_.init(F), data_.clear(); rows_ = r; cols_ = c; sort_ = unsorted; return *this; }
template<class Field_>
SparseMatrix<Field_,SparseMatrixFormat::TPL>::
SparseMatrix(const Field& F, Index r, Index c)
: MD_(F), data_(), rows_(r), cols_(c), sort_(unsorted) {}
template<class Field_>
SparseMatrix<Field_,SparseMatrixFormat::TPL>::
SparseMatrix(const SparseMatrix<Field_,SparseMatrixFormat::TPL> & B)
: MD_(B.field()), data_ ( B.data_ ), rows_ ( B.rows_ ), cols_ ( B.cols_ ),
sort_ ( B.sort_ )
{}
// template<class Field_>
// SparseMatrix<Field_,SparseMatrixFormat::TPL>& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
// operator=(const SparseMatrix<Field_,SparseMatrixFormat::TPL> & rhs)
// { if (rhs == this) return *this;
// MD_.init(rhs.field_);
// data_ = rhs.data_;
// rows_ = rhs.rows_;
// cols_ = rhs.cols_;
// sort_ = rhs.sort_;
// return *this;
// }
template<class Field_>
template<class Mat1, class Mat2> Mat1& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
// I do not like this need to templatize -bds
//typename SparseMatrix<Field_,SparseMatrixFormat::TPL>::Matrix& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
applyLeft // Y = AX
( /*typename SparseMatrix<Field_,SparseMatrixFormat::TPL>::Matrix*/Mat1 &Y,
const /*typename SparseMatrix<Field_,SparseMatrixFormat::TPL>::Matrix*/Mat2 &X
) const
{ Y.zero();
// Matrix Yc(field()) ;
// const Matrix Xc(field());// row submatrices
for (Index k = 0; k < data_.size(); ++k) {
Triple t = data_[k];
Matrix Yc (Y,t.row,0,1,Y.coldim());
// Yc.submatrix(Y,t.row,0,1,Y.coldim());
typename Matrix::constSubMatrixType Xc(X,t.col,0,1,X.coldim());
// Xc.submatrix(X,t.col,0,1,X.coldim());
MD_.saxpyin(Yc, t.elt, Xc);
}
return Y;
}
//template<class Field_> typename SparseMatrix<Field_,SparseMatrixFormat::TPL>::Matrix& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
template<class Field_>
template<class Mat1, class Mat2> Mat1& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
applyRight // Y = XA
( /*SparseMatrix<Field_,SparseMatrixFormat::TPL>::Matrix*/Mat1 &Y,
const /*typename SparseMatrix<Field_,SparseMatrixFormat::TPL>::Matrix*/Mat2 &X
) const
{ Y.zero();
// Matrix Yr(field());
// const Matrix Xr(field()); // row submatrices
for (Index k = 0; k < data_.size(); ++k) {
Triple t = data_[k];
Matrix Yr(Y,0,t.col,Y.rowdim(),1);
// Yr.submatrix(Y,0,t.col,Y.rowdim(),1);
typename Matrix::constSubMatrixType Xr(X,0,t.row,X.rowdim(),1);
// Xr.submatrix(X,0,t.row,X.rowdim(),1);
MD_.saxpyin(Yr, t.elt, Xr);
}
return Y;
}
template<class Field_>
template<class OutVector, class InVector>
OutVector & SparseMatrix<Field_,SparseMatrixFormat::TPL>::apply(OutVector & y, const InVector & x) const
{
linbox_check( rowdim() == y.size() );
linbox_check( coldim() == x.size() );
for (Index i = 0; i < y.size(); ++i) field().assign(y[i], field().zero);
for (Index k = 0; k < data_.size(); ++k) {
Triple t = data_[k];
field().axpyin(y[t.row], t.elt, x[t.col]);
}
return y;
}
template<class Field_>
template<class OutVector, class InVector>
OutVector & SparseMatrix<Field_,SparseMatrixFormat::TPL>::applyTranspose(OutVector & y, const InVector & x) const
{
linbox_check( coldim() == y.size() );
linbox_check( rowdim() == x.size() );
for (Index i = 0; i < y.size(); ++i) field().assign(y[i], field().zero);
for (Index k = 0; k < data_.size(); ++k) {
const Triple& t = data_[k];
field().axpyin(y[t.col], t.elt, x[t.row]);
}
return y;
}
template<class Field_>
size_t SparseMatrix<Field_,SparseMatrixFormat::TPL>::
rowdim() const { return rows_; }
template<class Field_>
size_t SparseMatrix<Field_,SparseMatrixFormat::TPL>::
coldim() const { return cols_; }
template<class Field_>
const Field_& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
field() const { return MD_.field(); }
template<class Field_>
size_t SparseMatrix<Field_,SparseMatrixFormat::TPL>::
size() const { return data_.size(); }
template<class Field_>
void SparseMatrix<Field_,SparseMatrixFormat::TPL>::
setEntry(Index i, Index j, const typename Field::Element & e)
{
sort_ = unsorted;
data_.push_back(Triple(i, j, e));
}
template<class Field_>
void SparseMatrix<Field_,SparseMatrixFormat::TPL>::
finalize(sortPolicy s) { /* sort according to policy */ sort_ = s; }
template<class Field_>
typename Field_::Element& SparseMatrix<Field_,SparseMatrixFormat::TPL>::
getEntry(typename Field_::Element& e, Index i, Index j) const
{
for (Index k = 0; k < data_.size(); ++k)
if (data_[k].row == i and data_[k].col == j)
return e = data_[k].elt;
return e = field().zero;
}
} // namespace LinBox
#endif // __LINBOX_triplesbb_INL
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
|