14 #ifndef TBCI_F_BANDMATRIX_H
15 #define TBCI_F_BANDMATRIX_H
19 #include "tbci/matrix.h"
20 #include "tbci/vector.h"
23 #if !defined(NO_GD) && !defined(AUTO_DECL)
24 # include "f_bandmatrix_gd.h"
30 #ifndef TBCI_DISABLE_EXCEPT
42 # pragma interface "f_bandmatrix.h"
47 template <
typename T>
class Matrix;
69 unsigned int superDiags = 0,
70 unsigned int subDiags = 0)
71 {
allocate(dimension, superDiags, subDiags); }
80 inline T operator() (
unsigned int row,
unsigned int column)
const;
82 inline T&
operator() (
unsigned int row,
unsigned int column);
84 inline void setval(
const T z,
unsigned int row,
unsigned int column);
101 inline void resize(
unsigned int newDim,
unsigned int newSuper,
unsigned int newSub);
139 friend STD__ ostream& operator<< FGD (STD__ ostream& stream, const F_BandMatrix<T>& m);
150 void allocate(
unsigned int dimension,
151 unsigned int superDiags,
152 unsigned int subDiags);
167 template <
typename T>
172 if (row-column > sub)
175 if (column-row > super)
177 return comp[(super+row-column) + column*(super+sub+1)];
181 template <
typename T>
185 BCHK(column < row && row-column > sub,
F_BandMatErr, Illegal index, (row<column ? row : column), dummy=(
T)0);
186 BCHK(column > row && column-row > super,
F_BandMatErr, Illegal index, (row<column ? row : column), dummy=(
T)0);
187 return comp[super+row-column + column*(super+sub+1)];
192 template <
typename T>
196 BCHKNR(column < row && row-column > sub,
F_BandMatErr, Illegal index, (row<column ? row : column));
197 BCHKNR(column > row && column-row > super,
F_BandMatErr, Illegal index, (row<column ? row : column));
198 comp[super+row-column + column*(super+sub+1)] = z;
202 template <
typename T>
207 allocate(newDim, newSuper, newSub);
211 template <
typename T>
216 for (
unsigned int i=0;
i<dim;
i++)
217 ColVec.
set((*
this)(
i,column),
i);
222 template <
typename T>
226 for (
unsigned int i=0;
i<dim; ++
i) {
228 if (!(
i-column > sub))
229 (*this)(
i,column) =
v(i);
231 if (!(column-i > super))
232 (*this)(
i,column) =
v(i);
237 template <
typename T>
244 template <
typename T>
252 template <
typename T>
256 if (
this == &m)
return *
this;
259 CSTD__ memcpy(comp, m.
comp,
sizeof(
T)*(dim*(super+sub+1)));
269 template <
typename T>
272 if (m1.
dim != m2.
dim)
return false;
273 for (
unsigned int j=0; j<m1.
dim; j++)
274 for (
unsigned int i=0;
i<m1.
dim;
i++)
275 if (m1(
i,j) != m2(
i,j))
return false;
281 template <
typename T>
284 if (m1.
dim != m2.
dim)
return true;
285 for (
unsigned int j=0; j<m1.
dim; j++)
286 for (
unsigned int i=0;
i<m1.
dim;
i++)
287 if (m1(
i,j) != m2(
i,j))
return true;
292 template <
typename T>
296 for (
unsigned int j=0; j<(m.
dim*(m.
sub+m.
super+1)); ++j)
302 template <
typename T>
308 for (
unsigned int i=0;
i<m.
dim;
i++) {
310 unsigned int left = (
i>m.
sub ?
i-m.
sub : 0);
314 for (
unsigned int j=left; j<
right; j++)
321 template <
typename T>
328 template <
typename T>
336 template <
typename T>
344 template <
typename T>
349 for (
unsigned int j=0; j<dim; j++)
352 unsigned int left = (j>super ? j-super : 0);
354 unsigned int right =
MIN(j+sub+1,dim);
356 for (
unsigned int i=left;
i<
right;
i++)
357 sum += comp[(super+
i-j)+j*(super+sub+1)] *
v(
i);
363 template <
typename T>
367 return(this->transMult(v));
371 template <
typename T>
375 return(this->transMult(v));
379 template <
typename T>
383 for (
unsigned int j=0; j<(m.
dim*(m.
super+m.
sub+1)); ++j)
390 template <
typename T>
394 for (
unsigned int j=0; j<(m.
dim*(m.
super+m.
sub+1)); ++j)
399 template <
typename T>
405 template <
typename T>
412 template <
typename T>
415 for (
unsigned int j=0; j<(dim*(super+sub+1)); ++j)
422 template <
typename T>
426 for (
unsigned int j=0; j<(m.
dim*(m.
super+m.
sub+1)); ++j)
432 template <
typename T>
435 for (
unsigned int j=0; j<(dim*(super+sub+1)); ++j)
442 template <
typename T>
445 for (super = dim-1; super > 0; --super)
446 for (
unsigned r = 0; r < dim-super; ++r)
447 if (m(r, r+super) != (
T)0)
452 template <
typename T>
455 for (sub = dim-1; sub > 0; --sub)
456 for (
unsigned c = 0;
c < dim-sub; ++
c)
457 if (m(
c+sub,
c) != (
T)0)
461 template <
typename T>
466 this->find_super(m); this->find_sub(m);
468 this->allocate(dim, super, sub);
469 for (
unsigned r = 0; r < dim; ++r)
470 for (
unsigned c =
MAX(0, (
int)(r-sub));
471 c <
MIN(dim, r+super+1); ++
c)
472 (*
this)(r,
c) = m(r,
c);
475 #ifndef LAPACK_INLINE
476 # define LAPACK_INLINE
480 template <
typename T>
482 unsigned int superDiags,
483 unsigned int subDiags)
486 BCHKNR(superDiags >= dimension || subDiags >= dimension,
F_BandMatErr, Dimension conflict, (subDiags<superDiags? subDiags : superDiags));
490 unsigned int colSize = super + sub + 1;
491 comp =
new T[colSize*dim];
498 template <
typename T>
507 template <
typename T>
513 unsigned int colSize = super + sub + 1;
514 comp =
new T[colSize*dim];
516 CSTD__ memcpy(comp, m.
comp,
sizeof(
T)*(dim*colSize));
521 template <
typename T>
524 unsigned int numSub(0),numSuper(0),dim(0);
535 for(
unsigned int i(0);
i<C.size();
i++)
537 for(
int j(
i-C.numSub());j<=(int)(
i+C.numSuper());j++)
539 if((j>=0)&&(j<(int)C.size()))
543 C(
i,j)=A(
i,j)+B(
i,j);
554 template <
typename T>
567 for(
unsigned int i(0);
i<C.size();
i++)
569 for(
int j(
i-C.numSub());j<=(int)(
i+C.numSuper());j++)
571 if((j>=0)&&(j<(int)C.size()))
575 C(
i,j)=A(
i,j)-B(
i,j);
586 template <
typename T>
587 STD__ ostream& operator<< (STD__ ostream& stream, const F_BandMatrix<T>& m)
589 for (
unsigned int i = 0;
i < m.rows();
i++)
591 for (
unsigned int j = 0; j < m.columns(); j++)
592 stream << m(
i,j) <<
" ";
593 stream <<
STD__ endl;
599 template <
typename T>
602 for (
unsigned int j=0; j<(dim*(super+sub+1)); j++)
607 template <
typename T>
611 for (
unsigned int r = 0; r < dim; ++r)
612 for (
unsigned int c =
MAX(0, (
int)(r-super));
613 c <
MIN(dim, r+sub+1); ++
c)
614 f(r,
c) = (*this)(
c,r);
618 template <
typename T>
627 template <typename T>
633 template <
typename T>
F_BandMatrix< T > transposed_copy() const
BdMatrix< T > transpose(BdMatrix< T > &mat)
T sum(const FS_Vector< dims, T > &fv)
#define BCHKNR(cond, exc, txt, ind)
cplx< T > operator-(const T a, const cplx< T > &b)
void copy(const F_BandMatrix< T > &m)
unsigned int ldab() const
F_BandMatrix< T > & swap(F_BandMatrix< T > &m)
F_BandMatrix(unsigned int dimension, unsigned int superDiags=0, unsigned int subDiags=0)
void find_super(const Matrix< T > &m)
Find number of super diagonals.
F_BandMatrix(const F_BandMatrix< T > &m)
friend TVector< T > do_fbdmat_vec_mul FGD(const F_BandMatrix< T > &m, const Vector< T > &v)
exception base class for the TBCI NumLib
Common interface definition (signature) for all Matrices.
unsigned int size() const
#define BCHK(cond, exc, txt, ind, rtval)
TVector< T > get_col(unsigned int column) const
T aligned_value_type TALIGN(MIN_ALIGN2)
F_BandMatrix< T > & operator*=(const T z)
T & set(const T &val, const unsigned long i) const
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > & z
void allocate(unsigned int dimension, unsigned int superDiags, unsigned int subDiags)
unsigned int numSub() const
unsigned int columns() const
number of columns
long int Vector< T > & index
unsigned int numSuper() const
BdMatrix< T > operator*(const T &v, const BdMatrix< T > &m)
void find_sub(const Matrix< T > &m)
Find number of sub diagonals.
TVector< T > do_fbdmat_vec_mul(const F_BandMatrix< T > &m, const Vector< T > &v)
void SWAP(T &a, T &b)
SWAP function Note: We could implement a swap function without temporaries: a -= b b += a a -= b a = ...
F_BandMatrix< T > do_fbdmat_scale(const F_BandMatrix< T > &m, const T z)
unsigned long size() const
bool operator!=(const F_BandMatrix< T > &m1, const F_BandMatrix< T > &m2)
C++ class for banded matrices using band storage in a one-dimensional array.
F_BandMatrix< T > & operator/=(const T z)
T & setval(unsigned r, unsigned c)
TVector< T > transMult(const Vector< T > &v) const
Temporary Base Class Idiom: Class TVector is used for temporary variables.
void setval(const T z, unsigned int row, unsigned int column)
F_BandMatrix< T > & transpose()
transpose() does change the object!
T operator()(unsigned int row, unsigned int column) const
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int res
F_BandMatErr(const char *t, const long i=0)
bool operator==(const F_BandMatrix< T > &m1, const F_BandMatrix< T > &m2)
unsigned int columns() const
cplx< T > operator/(const T a, const cplx< T > &b)
T *const & get_fortran_matrix() const
void resize(unsigned int newDim, unsigned int newSuper, unsigned int newSub)
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int int char v
< find minimun of func on grid with resolution res
unsigned int rows() const
void set_col(const Vector< T > &v, unsigned int column)
unsigned int rows() const
number of rows
F_BandMatrix< T > & operator=(const F_BandMatrix< T > &m)
cplx< T > operator+(const T a, const cplx< T > &b)