/usr/include/linbox/matrix/permutation-matrix.h is in liblinbox-dev 1.3.2-1.1+b1.
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 | /* Copyright (C) 2010 LinBox
* Written by <brice.boyer@imag.fr>
*
*
*
* ========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========
*/
/** @file matrix/permutation-matrix.h
* @ingroup matrix
* A permutation class for operations on permutations, their representations
* and matrix row/column permuting.
*
* We provide a \ref LinBox::BlasPermutation class that stores the
* permutation packed in a Lapack style and a \ref LinBox::MatrixPermutation
* class that represents a permutation naturally. Converstions are provided.
*/
#ifndef __LINBOX_matrix_permutation_H
#define __LINBOX_matrix_permutation_H
#include <vector>
#include <ostream>
// BlasPermutation
namespace LinBox
{
// forward declaration
template<class _UnsignedInt>
class MatrixPermutation ;
template<class _UnsignedInt>
class BlasPermutation ;
/** Lapack-style permutation.
* @ingroup permutation
*
* A Lapack permutation is represented with a vector \f$[p_1,p_2,\cdots, p_r]\f$
* such that \f$p_i > i\f$. Converting it to a classic representation
* of a permutation corresponds to taking an identity permutation and
* then successively permuting \f$(i,p_i)\f$.
* Example : if <code>P=[1,4,4]</code> and <code>V=[1,2,3,4,5]</code>, then <code>P.V=[1,4,2,3,5]</code>.
* @internal
* @pre if \c Q_ is built, then \c P_=Q_
*/
template<class _UnsignedInt> // unsigned * ou Integer
class BlasPermutation /* : PermutationInterface<_UnsignedInt> */ {
typedef BlasPermutation<_UnsignedInt> BlasPerm ;
public :
BlasPermutation() ;
~BlasPermutation() ;
BlasPermutation(size_t n) ;
BlasPermutation(const _UnsignedInt * V, const _UnsignedInt & n) ;
BlasPermutation(const std::vector<_UnsignedInt> & V);
BlasPermutation(const MatrixPermutation<_UnsignedInt> &M);
//! copy operator (with copy)
BlasPermutation<_UnsignedInt>& operator= (const BlasPermutation<_UnsignedInt> & P)
{
r_ = P.r_;
n_ = P.n_;
P_ = P.P_;
Q_ = P.Q_;
inv_ = P.inv_ ;
return (*this) ;
}
/*! Returns the size of the permuation.
* If given, we return \p n as we see \p P in \f$S_n\f$.
* We default to the order of the permutation (minimal such \p n)
*/
_UnsignedInt getSize() const ;
// _UnsignedInt getOrder() ;
/*! Returns the order of the permuation */
_UnsignedInt getOrder() const ;
void setOrder( size_t r) ;
//! returns a copy of the raw storage.
std::vector<_UnsignedInt> getStorage() const
{
return P_;
};
// resize a blas permutation.
void resize(_UnsignedInt s, bool with_zeros=true)
{
if (s < r_) {
r_ = s ;
#ifndef NDEBUG
std::cout << "*** Warning *** you are resizing a Blas Permutation (possibly corrupting it)" << std::endl;
#endif
}
n_ = s ;
P_.resize(s);
if (Q_.size())
Q_.resize(s);
}
// template<class OutVector, class InVector>
// OutVector &apply (OutVector &y, const InVector &x) ;
// template<class OutVector, class InVector>
// OutVector &applyTranspose (OutVector &y, const InVector &x) ;
/* properties */
bool isIdentity() const
{
return (!r_);
}
/* convert */
/*! Converts a \c BlasPermutation to a \c MatrixPermutation.
* @param[out] P MatrixPermutation to be created. Need not be initialized.
*/
MatrixPermutation<_UnsignedInt> & Convert(MatrixPermutation<_UnsignedInt> &P);
/* apply */
// /*! \f$ M \gets P M\f$ */
// template<class Matrix>
// Matrix & applyRows(Matrix &M);
// /*! \f$ M \gets M P\f$ */
// template<class Matrix>
// Matrix & applyCols(Matrix &M);
// /*! \f$ M \gets M P^t\f$ */
// template<class Matrix>
// Matrix & applyTransposeRows(Matrix &M);
// /*! \f$ M \gets P^t M\f$ */
// template<class Matrix>
// Matrix & applyTransposeCols(Matrix &M);
//_UnsignedInt & operator[] (const _UnsignedInt &i) ;
_UnsignedInt operator[] (const _UnsignedInt i) const ;
// /*! col \p i and col \p j are swapped
// */
// void TransposeCols(_UnsignedInt i, _UnsignedInt j);
// /*! row \p i and row \p j are swapped
// */
// void TransposeRows(_UnsignedInt i, _UnsignedInt j);
const _UnsignedInt* getPointer() const
{
linbox_check(P_.size());
return &P_[0];
}
_UnsignedInt* getWritePointer()
{
linbox_check(P_.size());
return &P_[0];
}
/* invert */
void Transpose();
void Invert();
BlasPerm & Transpose(BlasPerm &Mt);
BlasPerm & Invert(BlasPerm &Mt);
/* clean */
void Compress() ;
/* print */
/*! writes on output stream \p o */
std::ostream & write(std::ostream & o, bool Lapack=true) const ;
/*! writes \p P on output stream \p o */
template<class _Uint>
friend std::ostream & operator<<(std::ostream &o, BlasPerm & P) ;
protected :
_UnsignedInt r_ ; // size of compressed permutation
mutable _UnsignedInt n_ ; // dim of permutation
std::vector<_UnsignedInt> P_ ; // internal blas permutation
mutable std::vector<_UnsignedInt> Q_ ; // corresponding matrix permutation
bool inv_ ; // matrix is inverted ?
void BuildQ_() const ;
void InvertQ_();
std::vector<_UnsignedInt> &InvertQ_(std::vector<_UnsignedInt> & Qinv);
void BuildP_(std::vector<_UnsignedInt>&Q, std::vector<_UnsignedInt>&Qinv);
bool CheckP_();
void InitQ_() const ;
};
} // LinBox
// MatrixPermutation
namespace LinBox
{
/*! Permutation classique.
* @ingroup permutation
*/
template<class _UnsignedInt>
class MatrixPermutation /* : PermutationInterface<_UnsignedInt> */ {
typedef MatrixPermutation<_UnsignedInt> Self_t ;
private :
_UnsignedInt n_ ; // order of permutation
std::vector<_UnsignedInt> P_ ; // _M_[i] = j ssi P(i) = j
public :
MatrixPermutation();
~MatrixPermutation() {};
MatrixPermutation(const _UnsignedInt * V, const _UnsignedInt & n) ;
MatrixPermutation(const std::vector<_UnsignedInt> & V) ;
_UnsignedInt operator[] (const _UnsignedInt i) const ;
_UnsignedInt getSize() const ;
// _UnsignedInt getSize() ;
void resize( _UnsignedInt n ) ;
void Transpose();
void Invert();
Self_t & Transpose(Self_t &Mt);
Self_t & Invert(Self_t &Mt);
/* print */
/*! writes on output stream \p o */
std::ostream & write(std::ostream & o) const ;
/*! writes \p P on output stream \p o */
template<class _Uint>
friend std::ostream & operator<<(std::ostream &o, Self_t & P) ;
template<class OutVector, class InVector>
OutVector &apply (OutVector &y, const InVector &x) const ;
template<class OutVector, class InVector>
OutVector &applyTranspose (OutVector &y, const InVector &x) const ;
void TransposeRows(_UnsignedInt i, _UnsignedInt j);
void TransposeCols(_UnsignedInt i, _UnsignedInt j);
};
} // LinBox
#include "permutation-matrix.inl"
#endif //__LINBOX_matrix_permutation_H
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,:0,t0,+0,=s
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
|