/usr/include/linbox/blackbox/permutation.h is in liblinbox-dev 1.1.6~rc0-4.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 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* linbox/blackbox/permutation.h
* Copyright (C) 2001 Bradford Hovinen
*
* Written by Bradford Hovinen <hovinen@cis.udel.edu>
*
* This library 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 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __PERMUTATION_H
#define __PERMUTATION_H
#include <vector>
#include "linbox/util/debug.h"
#include "linbox/linbox-config.h"
#include <linbox/blackbox/blackbox-interface.h>
#ifdef __LINBOX_XMLENABLED
#include "linbox/util/xml/linbox-reader.h"
#include "linbox/util/xml/linbox-writer.h"
#include <iostream>
#include <string>
#endif
// Namespace in which all LinBox library code resides
namespace LinBox
{
/** \brief size is n.
\ingroup blackbox
* @param Storage \ref{LinBox} dense or sparse vector of field elements
*/
template<class _Field, class Storage = std::vector< long > >
class Permutation : public BlackboxInterface
{
const _Field& _F;
public:
typedef _Field Field;
typedef typename Field::Element Element;
/** Constructor from a vector of indices
* This constructor creates a permutation matrix based on a vector of indices
* @param indices Vector of indices representing the permutation
*/
Permutation (Storage & indices, const Field& F = Field()) : _F(F), _indices (indices)
{}
/** Constructor from a dimension
* This constructor creates an n x n permutation matrix, initialized to be the identity
* @param n The dimension of hte matrix to create
*/
Permutation (int n, const Field& F = Field()) : _F(F)
{
typename Storage::value_type i;
_indices.resize (n);
for (i = 0; i < n; i++)
_indices[i] = i;
}
/* Copy constructor.
* Creates new black box objects in dynamic memory.
* @param M constant reference to compose black box matrix
*/
Permutation (const Permutation &M)
: _F(M._F),_indices (M._indices)
{}
#ifdef __LINBOX_XMLENABLED
Permutation(LinBox::Reader &R)
{
if(!R.expectTagName("MatrixOver")) return;
if(!R.expectChildTag()) return;
R.traverseChild();
if(!R.expectTagName("permutation") || !R.expectTagNumVector(_indices)) return;
R.upToParent();
return;
}
#endif
// Destructor
~Permutation (void) {}
/* Application of BlackBox permutation matrix.
* y= P*x.
* Requires one vector conforming to the \ref{LinBox}
* vector {@link Archetypes archetype}.
* Required by abstract base class.
* @return reference to vector y containing output.
* @param x constant reference to vector to contain input
*/
/// #y \leftarrow Px#.
template<class OutVector, class InVector>
inline OutVector &apply (OutVector &y, const InVector &x) const
{
size_t i;
linbox_check (x.size () == _indices.size ());
// resizing y is now forbidden - bds //y.resize (x.size ());
linbox_check (y.size () == _indices.size ());
for (i = 0; i < x.size(); ++i)
_F.assign(y[_indices[i]], x[i]);
return y;
}
/* Application of BlackBox permutation matrix transpose.
* y= transpose(P)*x, equivalently y= P^-1*x
* Requires one vector conforming to the \ref{LinBox}
* vector {@link Archetypes archetype}.
* Required by abstract base class.
* @return reference to vector y containing output.
* @param x constant reference to vector to contain input
*/
/// #y^T \leftarrow x^T P#.
template<class OutVector, class InVector>
inline OutVector &applyTranspose (OutVector &y, const InVector &x) const
{
size_t i;
linbox_check (x.size () == _indices.size ());
// resizing y is now forbidden - bds //y.resize (x.size ());
linbox_check (y.size () == _indices.size ());
for (i = 0; i < _indices.size (); ++i)
_F.assign(y[i], x[_indices[i]]);
return y;
}
template<typename _Tp1>
struct rebind
{ typedef Permutation<_Tp1, Storage> other; };
/* Retreive row dimensions of BlackBox matrix.
* This may be needed for applying preconditioners.
* Required by abstract base class.
* @return integer number of rows of black box matrix.
*/
size_t rowdim (void) const
{
return _indices.size ();
}
/* Retreive column dimensions of BlackBox matrix.
* Required by abstract base class.
* @return integer number of columns of black box matrix.
*/
size_t coldim (void) const
{
return _indices.size ();
}
/** Add a transposition to the matrix
*/
void permute (size_t row1, size_t row2)
{
linbox_check (row1 >= 0 && row1 < _indices.size ());
linbox_check (row2 >= 0 && row2 < _indices.size ());
_swap (_indices[row1], _indices[row2]);
}
const Field& field() { return _F; }
#ifdef __LINBOX_XMLENABLED
std::ostream &write(std::ostream &out) const
{
LinBox::Writer W;
if( toTag(W) )
W.write(out);
return out;
}
bool toTag(LinBox::Writer &W) const
{
std::string s;
W.setTagName("MatrixOver");
W.setAttribute("rows", LinBox::Writer::numToString(s, _indices.size()));
W.setAttribute("cols", LinBox::Writer::numToString(s, _indices.size()));
W.setAttribute("implDetail", "permutation");
W.addTagChild();
W.setTagName("permutation");
W.addNumericalList(_indices);
W.upToParent();
return true;
}
#endif
private:
void _swap(typename Storage::value_type &x, typename Storage::value_type &y) const
{
typename Storage::value_type temp = x;
x = y;
y = temp;
}
// Vector of indices
Storage _indices;
}; // template <Vector> class Permutation
} // namespace LinBox
#endif // __PERMUTATION_H
|