18 #ifndef _SYMM_BAND_MATRIX
19 #define _SYMM_BAND_MATRIX
21 #include "tbci/vector.h"
22 #include "tbci/matrix_sig.h"
27 #if !defined(NO_GD) && !defined(AUTO_DECL)
28 # include "tbci/symm_bdmatrix_gd.h"
39 #ifndef TBCI_DISABLE_EXCEPT
47 :
NumErr(
"Error in var conf Symm_BdMatrix class") {}
75 void construct (
const unsigned int N,
const T&,
T*&,
78 inline void create (
const T& val,
const unsigned int N);
79 inline void create (
const T& val,
const unsigned int N,
91 inline void resize (
const T&,
const unsigned int);
92 inline void resize (
const unsigned int newDim) {
resize (0, newDim); }
98 const char*
mat_info ()
const {
return (
"Symm_BdMatrix"); }
101 const T&
operator() (
const unsigned int i,
const unsigned int k)
const;
102 const T&
get (
const unsigned int i,
const unsigned int k)
const
103 {
return (*
this) (
i, k); }
104 friend STD__ ostream& operator<< FGD (STD__ ostream&, const Symm_BdMatrix<T>&);
105 T&
setval (
const unsigned int i,
const unsigned int k);
106 void setval (
const T& wert,
const unsigned int i,
const unsigned int k)
108 void autoinsert (
const T& wert,
const unsigned int i,
const unsigned int k)
143 create (val, N, Diagconf);
158 rowOccupation.resize (dim);
162 STD__ cerr <<
"void Symm_BdMatrix<T>::Symm_BdMatrix(const T&, const unsigned int)" <<
STD__ endl
163 <<
"Invalid constructor parameters: Matrix can not have dimension == 0" <<
STD__ endl;
166 construct (dim, wert, elementPtr, conf, rowPtr, rowOccupation);
183 conf.resize(configVector.
size());
185 rowOccupation.resize(dim);
189 STD__ cerr <<
"void Symm_BdMatrix<T>::Symm_BdMatrix(const T&, const unsigned int, const BVector<unsigned int>&)" <<
STD__ endl
190 <<
"Invalid constructor parameters: Matrix can not have dimension == 0" <<
STD__ endl;
191 if(configVector.
size()>=dim)
192 STD__ cerr <<
"void Symm_BdMatrix<T>::Symm_BdMatrix(const T&, const unsigned int, const BVector<unsigned int>&)" <<
STD__ endl
193 <<
"Invalid constructor parameters: Number of off-diagonals larger than matrix dimension" <<
STD__ endl;
194 for(
unsigned i=0;
i<configVector.
size();
i++)
195 if(configVector(
i)>=dim)
196 STD__ cerr <<
"void Symm_BdMatrix<T>::Symm_BdMatrix(const T&, const unsigned int, const BVector<unsigned int>&)" <<
STD__ endl
197 <<
"Invalid constructor parameters: Off-diagonal is out of range" <<
STD__ endl;
200 construct(dim,wert,elementPtr,configVector,rowPtr,rowOccupation);
216 unsigned int i, j, length = dim;
217 for (i=0; i<ConfVector.
size(); i++)
218 length += dim - ConfVector.
get(i);
221 elemPtr =
new T [length];
222 for (i=0; i<length; i++)
226 if (ConfVector.
size()) {
227 unsigned int next = 0;
228 for (i=0; i<dim; i++) {
229 rPtr.
set(i) = &(elemPtr[next]);
230 next += ConfVector.
size()+1;
233 for (j = ConfVector.
size(); j >= 1; j--)
234 if(ConfVector.
get(j-1) +i >=dim) next--;
239 for (i=0; i<dim; i++) rPtr.
set(i) = &(elemPtr[
i]);
244 for (i=0; i<dim; i++)
247 for (i=0; i<ConfVector.
size(); i++)
248 rowOccup.
set(ConfVector.
get(i)) = i+1;
254 template <
typename T>
258 for (
unsigned i = 0;
i < m.
rows();
i++)
259 for (
unsigned j = 0; j < m.
columns(); j++)
261 this->setval(
i, j) = m (
i,j);
285 if((i>=dimension) || (k>=dimension))
286 STD__ cerr <<
"T& Symm_BdMatrix<T>::setval (const unsigned int, const unsigned int)" <<
STD__ endl
287 <<
"Invalid Index: Index out of range" <<
STD__ endl;
300 return *rowPtr.get(l);
303 if(rowOccupation(m-l) != 0) {
304 return *(rowPtr.get(l) + rowOccupation.get(m-l));
317 for(g=j=0; j<conf.
size(); j++,g++) {
319 if( conf.get(j) > (m-l)) {newConfVector.set(g++)= m-l; found=j;
break;}
320 newConfVector.
set(g) = conf.get(j);
323 for(; j<conf.
size(); j++,g++) {
324 newConfVector.set(g) = conf.get(j);
327 if(found == -1) {newConfVector.set(conf.size()) = m-l; found=conf.size();}
333 construct(dimension,
T(0),newmem,newConfVector,newrowPtr,neuerowOccupation);
341 for(h=1; h<dimension; h++){
343 while(newPtr != newrowPtr.
get(h)) {
344 *(newPtr++) = *(oldPtr++);
345 if( ((
int)j == found)&& (
int(found+1) < int(newrowPtr.
get(h) - newrowPtr.
get(h-1))) )
350 *(newPtr) = *(oldPtr);
357 rowOccupation = neuerowOccupation;
358 conf.
resize(newConfVector.size()) = newConfVector;
362 return *(rowPtr.get(l) + rowOccupation.get(m-l));
378 EXPCHK((i>=dimension) || (k>=dimension),
SymmBdMatrixErr,
"const T& Symm_BdMatrix<T>::operator() (const unsigned int, const unsigned int)const: inval idx", i, zero);
386 if(m==l)
return *rowPtr.get(l);
389 if(rowOccupation(m-l) != 0)
return *(rowPtr.get(l) + rowOccupation.get(m-l));
400 inline STD__ ostream& operator<< (STD__ ostream& out, const Symm_BdMatrix<T>& matrix)
403 for(i=0; i< matrix.dimension; i++){
405 for(k=0; k< matrix.dimension; k++) out << matrix(i,k) <<
" ";
419 if (Vector.
size() != dimension)
420 STD__ cerr <<
"TVector<T> Symm_BdMatrix<T>::operator* (const Vector<T>&)const" <<
STD__ endl
421 <<
"Matrix and Vector have different dimensions" <<
STD__ endl;
427 if (conf.size() == 0) {
428 for (i=0; i<dimension; i++)
429 result.setval(i) = ((*(rowPtr.get(i))) * Vector.
get(i));
483 unsigned int j, diagonal, confsize;
484 confsize=conf.size();
487 unsigned max_off=conf.get(confsize-1);
488 for(i=0; i<max_off; i++)
491 temp = ((*(rowPtr.get(i))) * Vector.
get(i));
493 for(j=0; ((diagonal=conf.get(j))<=i) && (j<confsize); j++)
494 temp += *(rowPtr.get(i-diagonal) + j +1) * Vector.
get(i-diagonal);
496 for(j=0; j<confsize; j++)
497 temp += *(rowPtr.get(i) + j +1) * Vector.
get(i + conf.
get(j));
498 result.setval(i)=temp;
500 for(i=max_off; i<dimension-max_off; i++)
503 temp = ((*(rowPtr.get(i))) * Vector.
get(i));
504 for(j=0; j<confsize; j++)
507 temp += *(rowPtr.get(i-conf.
get(j)) + j +1) * Vector.
get(i-conf.
get(j));
509 temp += *(rowPtr.get(i) + j +1) * Vector.
get(i + conf.
get(j));
511 result.setval(i)=temp;
513 for(i=dimension-max_off; i<dimension; i++)
516 temp = ((*(rowPtr.get(i))) * Vector.
get(i));
518 for(j=0; j<confsize; j++)
519 temp += *(rowPtr.get(i-conf.
get(j)) + j +1) * Vector.
get(i-conf.
get(j));
521 for(j=0; (conf.get(j)<dimension-
i) && (j<confsize); j++)
522 temp += *(rowPtr.get(i) + j +1) * Vector.
get(i + conf.
get(j));
523 result.setval(i)=temp;
640 while(Ptr != rowPtr.get(dimension-1)) (*Ptr++) =
T(0);
648 #endif // !defined(_Symm_BdMatrix)
void resize(const unsigned int newDim)
const Vector< T > const Vector< T > const Vector< T > int T h
unsigned long size() const HOT
exception base class for the TBCI NumLib
BVector< unsigned int > conf
unsigned int rows() const
Common interface definition (signature) for all Matrices.
tbci_traits< T >::const_refval_type get(const unsigned long i) const
unsigned int columns() const
virtual ~SymmBdMatrixErr()
const char * mat_info() const
Symm_BdMatrix(const T &val, const unsigned int N, const BVector< unsigned int > &diagConf)
Matrix class with optimized Matrix-Vector multiplication for symmetrical Matrices.
tbci_traits< T >::const_refval_type get(const unsigned long idx) const HOT
void create(const T &val, const unsigned int N)
Symm_BdMatrix(const unsigned int N)
Symm_BdMatrix(const T &val, const unsigned int N)
T aligned_value_type TALIGN(MIN_ALIGN2)
void resize(const T &, const unsigned int)
void construct(const unsigned int N, const T &, T *&, const BVector< unsigned int > &, BVector< T * > &, BVector< unsigned int > &)
SymmBdMatrixErr(const SymmBdMatrixErr &be)
unsigned int columns() const
SymmBdMatrixErr(const char *t, const long i=0)
T & set(const unsigned long idx) HOT
const T & operator()(const unsigned int i, const unsigned int k) const
unsigned long size() const
void autoinsert(const T &wert, const unsigned int i, const unsigned int k)
#define EXPCHK(cond, exc, txt, ind, rtval)
BVector< unsigned int > rowOccupation
BVector< T > & resize(const BVector< T > &)
Actually it's a resize and copy (some people would expect the assignment op to do this) ...
Temporary Base Class Idiom: Class TVector is used for temporary variables.
void setval(const T &wert, const unsigned int i, const unsigned int k)
T & setval(const unsigned int i, const unsigned int k)
TVector< T > operator*(const Vector< T > &) const
unsigned int rows() const