/usr/include/linbox/algorithms/whisart_trace.h is in liblinbox-dev 1.3.2-1.1build2.
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 | /* linbox/algorithms/cra-domain.h
* Copyright (C) 1999-2010 The LinBox group
*
* Time-stamp: <19 Apr 10 18:35:14 Jean-Guillaume.Dumas@imag.fr>
* Computes the trace of D1 B D2 B^T D1 or D1 B^T D2 B D1
*
* ========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========
*/
#ifndef __LINBOX_whisart_trace_H
#define __LINBOX_whisart_trace_H
#include "linbox/field/modular.h"
#include "linbox/blackbox/compose.h"
#include "linbox/blackbox/transpose.h"
#include "linbox/blackbox/sparse.h"
#include "linbox/blackbox/lambda-sparse.h"
// #include "linbox/blackbox/subrowmatrix.h"
#include "linbox/solutions/trace.h"
namespace LinBox
{
// Trait to show whether or not the BB class has a Indexed iterator
template<class BB> struct IndexedCategory;
/// limited doc so far
namespace IndexedTags
{
struct HasIndexed{};
struct NoIndexed{};
}
template<class BB> struct IndexedCategory {
typedef IndexedTags::NoIndexed Tag;
};
template<class Field>
struct IndexedCategory< BlasMatrix<Field> > {
typedef IndexedTags::HasIndexed Tag; };
template<class Field, class Row>
struct IndexedCategory< LambdaSparseMatrix<Field,Row> > {
typedef IndexedTags::HasIndexed Tag; };
template<class Field, class Row>
struct IndexedCategory< SparseMatrix<Field,Row> > {
typedef IndexedTags::HasIndexed Tag; };
#if 0
template<class Matrix, class MatrixCategory>
struct IndexedCategory< SubRowMatrix<Matrix,MatrixCategory> > {
typedef IndexedTags::HasIndexed Tag;
};
#endif
template<class Field, class BB>
typename Field::Element& WhisartTrace(
typename Field::Element& trace,
const Field& F,
const LinBox::Diagonal<Field>& ExtD,
const BB& A,
const LinBox::Diagonal<Field>& InD)
{
return WhisartTrace(trace, F, ExtD, A, InD, typename IndexedCategory<BB>::Tag() );
}
template<class Field, class BB>
typename Field::Element& WhisartTraceTranspose(
typename Field::Element& trace,
const Field& F,
const LinBox::Diagonal<Field>& ExtD,
const BB& A,
const LinBox::Diagonal<Field>& InD)
{
return WhisartTraceTranspose(trace, F, ExtD, A, InD, typename IndexedCategory<BB>::Tag() );
}
template<class Field, class BB>
typename Field::Element& WhisartTrace(
typename Field::Element& tr,
const Field& F,
const LinBox::Diagonal<Field>& ExtD,
const BB& A,
const LinBox::Diagonal<Field>& InD, IndexedTags::NoIndexed t)
{
// Trace of ExtD B InD B^T ExtD
typedef Compose<Diagonal<Field>, BB > C_DB;
C_DB B1 (&ExtD, &A); // D1 A
typedef Compose<C_DB, Diagonal<Field> > C_DBD;
C_DBD B2 (&B1, &InD); // D1 A D2
Transpose<BB> AT (&A);
typedef Compose<C_DBD, Transpose<BB> > C_DBDBt;
C_DBDBt B3 (&B2, &AT); // D1 A D2 A^T
typedef Compose<C_DBDBt, Diagonal<Field> > C_DBDBtD;
C_DBDBtD B (&B3, &ExtD); // D1 A D2 A^T D1
return trace(tr, B);
}
template<class Field, class BB>
typename Field::Element& WhisartTraceTranspose(
typename Field::Element& tr,
const Field& F,
const LinBox::Diagonal<Field>& ExtD,
const BB& A,
const LinBox::Diagonal<Field>& InD,
IndexedTags::NoIndexed t)
{
// Trace of ExtD A^T InD A ExtD
Transpose<BB> AT (&A);
typedef Compose<Diagonal<Field>,Transpose<BB> > C_DBt;
C_DBt B1 (&ExtD, &AT); // D1 A^T
typedef Compose<C_DBt, Diagonal<Field> > C_DBtD;
C_DBtD B2 (&B1, &InD); // D1 A^T D2
typedef Compose<C_DBtD, BB> C_DBtDB;
C_DBtDB B3 (&B2, &A); // D1 A^T D2 A
typedef Compose<C_DBtDB, Diagonal<Field> > C_DBtDBD;
C_DBtDBD B (&B3, &ExtD); // D1 A^T D2 A D1
return trace(tr, B);
}
template<class Field, class BB>
typename Field::Element& WhisartTrace(
typename Field::Element& tr,
const Field& F,
const LinBox::Diagonal<Field>& ExtD,
const BB& A,
const LinBox::Diagonal<Field>& InD,
IndexedTags::HasIndexed )
{
// Trace of ExtD B InD B^T ExtD
// is sum ExtD_i^2 B_{i,j} InD_j
F.init(tr, 0);
for(typename BB::ConstIndexedIterator it = A.IndexedBegin();
it != A.IndexedEnd(); ++it) {
typename Field::Element tmp,e,i;
F.init(tmp);
F.init(e);F.init(i);
F.mul(tmp,it.value(),it.value());
ExtD.getEntry(e, it.rowIndex(),it.rowIndex());
InD.getEntry(i, it.colIndex(),it.colIndex());
F.mulin(tmp,e);
F.mulin(tmp,e);
F.mulin(tmp,i);
F.addin(tr, tmp);
}
return tr;
}
template<class Field, class BB>
typename Field::Element& WhisartTraceTranspose(
typename Field::Element& tr,
const Field& F,
const LinBox::Diagonal<Field>& ExtD,
const BB& A,
const LinBox::Diagonal<Field>& InD,
IndexedTags::HasIndexed )
{
// Trace of ExtD B^T InD B ExtD
// is sum ExtD_j^2 B_{i,j} InD_i
F.init(tr, 0);
for(typename BB::ConstIndexedIterator it = A.IndexedBegin();
it != A.IndexedEnd(); ++it) {
typename Field::Element tmp,e,i;
F.init(tmp,0UL);
F.init(e,0UL);
F.init(i,0UL);
F.mul(tmp, it.value(),it.value());
ExtD.getEntry(e, it.colIndex(),it.colIndex());
InD.getEntry(i, it.rowIndex(),it.rowIndex());
F.mulin(tmp,e);
F.mulin(tmp,e);
F.mulin(tmp,i);
F.addin(tr, tmp);
}
return tr;
}
}
#endif //__LINBOX_whisart_trace_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:
|