/usr/include/linbox/algorithms/matrix-hom.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 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 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
// Time-stamp: <12 Jul 05 18:26:56 Jean-Guillaume.Dumas@imag.fr>
#ifndef __LINBOX_MATRIX_HOM_H__
#define __LINBOX_MATRIX_HOM_H__
#include <linbox/blackbox/blas-blackbox.h>
#include <linbox/blackbox/sparse.h>
#include <linbox/blackbox/dense.h>
#include <linbox/blackbox/compose.h>
#include <linbox/blackbox/polynomial.h>
#include <linbox/blackbox/scalar-matrix.h>
#include <linbox/integer.h>
#include <linbox/field/hom.h>
#include <linbox/field/multimod-field.h>
#include <linbox/matrix/dense.h>
#include <linbox/matrix/matrix-category.h>
namespace LinBox {
// try to map a blackbox over a homorphic ring
// The most suitable type
template <class Blackbox, class Field>
struct MatrixHomTrait{
//typedef ... FBlackbox
// donot know
typedef Blackbox value_type;
};
/*
// Vector<Ring>::Sparse = Vector<Ring>::SparsePar
template <class Ring, class Field>
struct Convert<SparseMatrix<Ring, typename Vector<Ring>::Sparse>, Field> {
typedef SparseMatrix<Field, typename Vector<Field>::Sparse> value_type;
};
*/
template <class RingElement, class Field>
struct MatrixHomTrait<DenseMatrixBase<RingElement>, Field> {
typedef DenseMatrixBase<typename Field::Element> value_type;
};
template <class Ring, class Field>
struct MatrixHomTrait<SparseMatrix<Ring, typename Vector<Ring>::SparseSeq>, Field> {
typedef SparseMatrix<Field, typename Vector<Field>::SparseSeq> value_type;
};
template <class Ring, class Field>
struct MatrixHomTrait<SparseMatrix<Ring, typename Vector<Ring>::SparsePar>, Field> {
typedef SparseMatrix<Field, typename Vector<Field>::SparsePar> value_type;
};
template <class Ring, class Field>
struct MatrixHomTrait<SparseMatrix<Ring, typename Vector<Ring>::SparseMap>, Field> {
typedef SparseMatrix<Field, typename Vector<Field>::SparseMap> value_type;
};
template <class Ring, class Field>
struct MatrixHomTrait<DenseMatrix<Ring>, Field> {
typedef DenseMatrix<Field> value_type;
};
template <class Ring, class Field>
struct MatrixHomTrait<BlasBlackbox<Ring>, Field> {
typedef BlasBlackbox<Field> value_type;
};
/// \brief Limited doc so far. Used in RationalSolver.
namespace MatrixHom {
//public:
template<class FMatrix, class IMatrix, class Field>
void map (FMatrix* & Ap, const IMatrix& A, const Field& F) {
typename IMatrix::template rebind<Field>()( Ap, A, F);
}
// construct a dense matrix over finite field, such that *Ap = A mod p, where F = Ring / <p>
template<class Field, class IMatrix>
void map (DenseMatrix<Field>* &Ap, const IMatrix& A, const Field& F);
// construct a dense matrix over finite field, such that *Ap = A mod p, where F = Ring / <p>
template<class Ring, class Field>
void map (DenseMatrixBase<typename Field::Element>* &Ap, const DenseMatrixBase<typename Ring::Element>& A, const Field& F){
typename DenseMatrixBase<typename Ring::Element>::template rebind<Field>()( Ap, A, F);
}
// construct a sparse matrix over finite field, such that *Ap = A mod p, where F = Ring / <p>
template<class Field, class Vect, class IMatrix>
void map (SparseMatrix<Field, Vect>* &Ap, const IMatrix& A, const Field &F);
// construct a dense matrix over finite field, such that *Ap = A mod p, where F = Ring / <p>
template<class Ring, class Field>
void map (DenseMatrix<Field>* &Ap, const DenseMatrix<Ring>& A, const Field &F){
typename DenseMatrix<Ring>::template rebind<Field>()( Ap, A, F);
}
// construct a dense matrix over finite field, such that *Ap = A mod p, where F = Ring / <p>
template<class Ring, class Vect, class Field>
void map (DenseMatrix<Field>* &Ap, const SparseMatrix<Ring, Vect>& A, const Field &F);
// construct a sparse matrix over finite field, such that *Ap = A mod p, where F = Ring / <p>
template<class Ring, class Vect1, class Field, class Vect2>
void map (SparseMatrix<Field, Vect2>*& Ap, const SparseMatrix<Ring, Vect1>& A, const Field& F) {
typename SparseMatrix<Ring,Vect1>::template rebind<Field,Vect2>()( Ap, A, F);
}
// function class to hanle map to BlasBlackbox (needed to allow partial specialization)
template< class Field, class IMatrix, class Type>
class BlasBlackboxMAP {
public:
void operator() (BlasBlackbox<Field> *&Ap, const IMatrix& A, const Field& F, Type type);
};
// construct a BlasBlackbox over finite fiel, such that *Ap - A mod p, where F = Ring / <p>
template<class Ring, class Field>
void map (BlasBlackbox<Field>* &Ap, const BlasBlackbox<Ring>& A, const Field &F){
typename BlasBlackbox<Ring>::template rebind<Field>()( Ap, A, F);
}
template <class Field, class IMatrix>
void map (BlasBlackbox<Field> *&Ap, const IMatrix &A, const Field &F) {
BlasBlackboxMAP<Field, IMatrix, typename MatrixContainerTrait<IMatrix>::Type> ()(Ap, A, F, typename MatrixContainerTrait<IMatrix>::Type());
}
template <class Field, class IPoly, class IMatrix>
void map (PolynomialBB< typename IMatrix::template rebind<Field>::other, typename IPoly::template rebind<Field>::other> *&Ap,
const PolynomialBB<IMatrix, IPoly> &A, const Field & F){
typename PolynomialBB<IMatrix,IPoly>::template rebind<Field>() (Ap, A, F);
}
template <class Field, class Ring>
void map (ScalarMatrix<Field> *&Ap,
const ScalarMatrix<Ring> &A,
const Field & F){
typename ScalarMatrix<Ring>::template rebind<Field>() (Ap, A, F);
}
}
template <class Field, class IMatrix>
void MatrixHom::map (DenseMatrix<Field>* &Ap, const IMatrix& A, const Field &F) {
Ap = new DenseMatrix<Field>(F, A.rowdim(), A.coldim());
typedef typename IMatrix::Field Ring;
Ring r = A.field();
typename Ring::Element one, zero;
r. init(one, 1);
r. init(zero, 0);
std::vector<typename Ring::Element> e(A.coldim(), zero), tmp(A.rowdim());
typename DenseMatrix<Field>::ColIterator col_p;
typename DenseMatrix<Field>::Col::iterator elt_p;
typename std::vector<typename Ring::Element>::iterator e_p, tmp_p;
Hom<Ring, Field> hom(A. field(), F);
for (col_p = Ap -> colBegin(), e_p = e.begin();
e_p != e.end(); ++ col_p, ++ e_p) {
r.assign(*e_p, one);
A.apply (tmp, e);
for (tmp_p = tmp.begin(), elt_p = col_p -> begin();
tmp_p != tmp.end(); ++ tmp_p, ++ elt_p)
hom.image (*elt_p, *tmp_p);
r.assign(*e_p, zero);
}
}
template <class Field, class Vect, class IMatrix>
void MatrixHom::map (SparseMatrix<Field, Vect>* &Ap, const IMatrix& A, const Field &F) {
Ap = new SparseMatrix<Field, Vect>(F, A.rowdim(), A.coldim());
typedef typename IMatrix::Field Ring;
Ring r = A.field();
typename Ring::Element one, zero;
r. init(one, 1);
r. init(zero, 0);
std::vector<typename Ring::Element> e(A.coldim(), zero), tmp(A.rowdim());
typename std::vector<typename Ring::Element>::iterator iter, e_p;
typename Field::Element val;
int i = 0;
Hom<Ring, Field> hom(A. field(), F);
for (e_p=e.begin();e_p != e.end(); ++e_p,i++){
r.assign(*e_p, one);
A.apply(tmp,e);
int j;
for (iter=tmp.begin(),j=0; iter != tmp.end(); ++iter,j++) {
hom. image (val, *iter);
if (!F.isZero(val))
Ap -> setEntry (j,i, val);
}
r.assign(*e_p, zero);
}
}
template <class Ring, class Vect, class Field>
void MatrixHom::map (DenseMatrix<Field>*& Ap, const SparseMatrix<Ring, Vect>& A, const Field &F) {
Ap = new DenseMatrix<Field>(F, A.rowdim(), A.coldim());
typename DenseMatrix<Field>::Element zero; F. init (zero, 0);
typename DenseMatrix<Field>::RawIterator raw_p;
for (raw_p = Ap -> rawBegin(); raw_p != Ap -> rawEnd(); ++ raw_p)
F. assign (*raw_p, zero);
typename SparseMatrix<Ring, Vect>::ConstRowIterator row_p;
std::vector<size_t>::const_iterator j_p;
typename std::vector<typename Ring::Element>::const_iterator e_p;
typename Field::Element e;
int i = 0;
Hom<Ring, Field> hom(A. field(), F);
for (row_p = A.rowBegin(); row_p != A.rowEnd(); ++ row_p, ++ i)
for (j_p = row_p -> first. begin(), e_p = row_p -> second. begin();
j_p != row_p -> first. end(); ++ e_p, ++ j_p) {
//F.init (e, *e_p);
hom. image (e, *e_p);
if (!F.isZero(e))
Ap -> setEntry (i, *j_p, e);
}
}
namespace MatrixHom {
template<class Field, class IMatrix>
class BlasBlackboxMAP<Field, IMatrix, MatrixContainerCategory::Blackbox> {
public:
void operator() (BlasBlackbox<Field> *&Ap, const IMatrix &A, const Field &F, MatrixContainerCategory::Blackbox type) {
Ap = new BlasBlackbox<Field>(F, A.rowdim(), A.coldim());
typedef typename IMatrix::Field Ring;
Ring r = A.field();
typename Ring::Element one, zero;
r. init(one, 1);
r. init(zero, 0);
std::vector<typename Ring::Element> e(A.coldim(), zero), tmp(A.rowdim());
typename BlasBlackbox<Field>::ColIterator col_p;
typename BlasBlackbox<Field>::Col::iterator elt_p;
typename std::vector<typename Ring::Element>::iterator e_p, tmp_p;
Hom<Ring, Field> hom(A. field(), F);
for (col_p = Ap -> colBegin(), e_p = e.begin();
e_p != e.end(); ++ col_p, ++ e_p) {
r.assign(*e_p, one);
A.apply (tmp, e);
for (tmp_p = tmp.begin(), elt_p = col_p -> begin();
tmp_p != tmp.end(); ++ tmp_p, ++ elt_p)
hom.image (*elt_p, *tmp_p);
r.assign(*e_p, zero);
}
}
};
template<class Field, class IMatrix>
class BlasBlackboxMAP<Field, IMatrix, MatrixContainerCategory::Container> {
public:
void operator() (BlasBlackbox<Field> *&Ap, const IMatrix &A, const Field &F, MatrixContainerCategory::Container type) {
Ap = new BlasBlackbox<Field>(F, A.rowdim(), A.coldim());
Hom<typename IMatrix::Field , Field> hom(A.field(), F);
typename Field::Element e, zero;
F.init(zero,0UL);
for( typename IMatrix::ConstRawIndexedIterator indices = A.rawIndexedBegin();
(indices != A.rawIndexedEnd()) ;
++indices ) {
hom. image (e, A.getEntry(indices.rowIndex(),indices.colIndex()) );
if (!F.isZero(e))
Ap -> setEntry (indices.rowIndex(),
indices.colIndex(), e);
else
Ap -> setEntry (indices.rowIndex(),
indices.colIndex(), zero);
}
}
};
template<class Field, class IMatrix>
class BlasBlackboxMAP<Field, IMatrix, MatrixContainerCategory::BlasContainer> {
public:
void operator() (BlasBlackbox<Field> *&Ap, const IMatrix &A, const Field &F, MatrixContainerCategory::BlasContainer type) {
Ap = new BlasBlackbox<Field>(F, A.rowdim(), A.coldim());
Hom<typename IMatrix::Field , Field> hom(A.field(), F);
typename IMatrix::ConstRawIterator iterA = A.rawBegin();
typename BlasBlackbox<Field>::RawIterator iterAp = Ap->rawBegin();
for(; iterA != A.rawEnd(); iterA++, iterAp++)
hom. image (*iterAp, *iterA);
}
};
template< class IMatrix>
class BlasBlackboxMAP<MultiModDouble, IMatrix, MatrixContainerCategory::BlasContainer > {
public:
void operator() (BlasBlackbox<MultiModDouble> *&Ap, const IMatrix &A, const MultiModDouble &F, MatrixContainerCategory::BlasContainer type) {
Ap = new BlasBlackbox<MultiModDouble>(F, A.rowdim(), A.coldim());
for (size_t i=0; i<F.size();++i)
MatrixHom::map(Ap->getMatrix(i), A, F.getBase(i));
}
};
template< class IMatrix>
class BlasBlackboxMAP<MultiModDouble, IMatrix, MatrixContainerCategory::Container > {
public:
void operator() (BlasBlackbox<MultiModDouble> *&Ap, const IMatrix &A, const MultiModDouble &F, MatrixContainerCategory::Container type) {
Ap = new BlasBlackbox<MultiModDouble>(F, A.rowdim(), A.coldim());
for (size_t i=0; i<F.size();++i)
MatrixHom::map(Ap->getMatrix(i), A, F.getBase(i));
}
};
template< class IMatrix>
class BlasBlackboxMAP<MultiModDouble, IMatrix, MatrixContainerCategory::Blackbox > {
public:
void operator() (BlasBlackbox<MultiModDouble> *&Ap, const IMatrix &A, const MultiModDouble &F, MatrixContainerCategory::Blackbox type) {
Ap = new BlasBlackbox<MultiModDouble>(F, A.rowdim(), A.coldim());
for (size_t i=0; i<F.size();++i)
MatrixHom::map(Ap->getMatrix(i), A, F.getBase(i));
}
};
}
}
#endif
|