CPPLapack
 All Classes Files Functions Variables Friends Pages
dgsmatrix-calc.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! return transposed dgsmatrix */
3 inline _dgsmatrix t(const dgsmatrix& mat)
4 {CPPL_VERBOSE_REPORT;
5  dgsmatrix newmat =mat;
6 
7  std::swap(newmat.m,newmat.n);
8  std::swap(newmat.rows,newmat.cols);
9  const std::vector<dcomponent>::iterator newmat_data_end =newmat.data.end();
10  for(std::vector<dcomponent>::iterator it=newmat.data.begin(); it!=newmat_data_end; it++){
11  std::swap(it->i,it->j);
12  }
13 
14  return _(newmat);
15 }
16 
17 ///////////////////////////////////////////////////////////////////////////////
18 ///////////////////////////////////////////////////////////////////////////////
19 ///////////////////////////////////////////////////////////////////////////////
20 
21 //=============================================================================
22 /*! search the index of element having the largest absolute value in 0-based numbering system */
23 inline void idamax(CPPL_INT& i, CPPL_INT& j, const dgsmatrix& mat)
24 {CPPL_VERBOSE_REPORT;
25  //////// exception ////////
26  if(mat.data.size()==0){
27  WARNING_REPORT;
28  std::cerr << "The dgsmatrix is a zero matrix." << std::endl;
29  return;
30  }
31 
32  //////// find ////////
33  std::vector<dcomponent>::const_iterator itx(mat.data.begin());
34  double vmax =0.;
35 
36  const std::vector<dcomponent>::const_iterator mat_data_end =mat.data.end();
37  for(std::vector<dcomponent>::const_iterator it=mat.data.begin(); it!=mat_data_end; it++){
38  if( vmax < fabs(it->v) ){
39  vmax =fabs(it->v);
40  itx =it;
41  }
42  }
43 
44  i =itx->i;
45  j =itx->j;
46 }
47 
48 //=============================================================================
49 /*! return its largest absolute value */
50 inline double damax(const dgsmatrix& mat)
51 {CPPL_VERBOSE_REPORT;
52  //////// exception ////////
53  if(mat.data.size()==0){
54  return 0.;
55  }
56 
57  //////// find ////////
58  std::vector<dcomponent>::const_iterator itx(mat.data.begin());
59  double vmax =0.;
60 
61  const std::vector<dcomponent>::const_iterator mat_data_end =mat.data.end();
62  for(std::vector<dcomponent>::const_iterator it=mat.data.begin(); it!=mat_data_end; it++){
63  if( vmax < fabs(it->v) ){
64  vmax =fabs(it->v);
65  itx =it;
66  }
67  }
68 
69  return itx->v;
70 }
Real Double-precision General Sparse Matrix Class.
Definition: dgsmatrix.hpp:3
std::vector< dcomponent > data
matrix data
Definition: dgsmatrix.hpp:11
CPPL_INT n
matrix column size
Definition: dgsmatrix.hpp:10
std::vector< std::vector< CPPL_INT > > cols
array of vector to store the entry information of component for each column
Definition: dgsmatrix.hpp:13
_dgematrix i(const _dgbmatrix &mat)
(DO NOT USE) Smart-temporary Real Double-precision General Sparse Matrix Class
Definition: _dgsmatrix.hpp:3
void swap(dcovector &u, dcovector &v)
_dgsmatrix t(const dgsmatrix &mat)
double damax(const dgsmatrix &mat)
_dcovector _(dcovector &vec)
std::vector< std::vector< CPPL_INT > > rows
array of vector to store the entry information of component for each row
Definition: dgsmatrix.hpp:12
CPPL_INT m
matrix row size
Definition: dgsmatrix.hpp:9
void idamax(CPPL_INT &i, CPPL_INT &j, const dgsmatrix &mat)