CPPLapack
 All Classes Files Functions Variables Friends Pages
dgrmatrix-misc.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! clear all the matrix data and set the sizes 0 */
3 inline void dgrmatrix::clear()
4 {CPPL_VERBOSE_REPORT;
5  m =0;
6  n =0;
7  a.clear();
8  ia.clear();
9  ja.clear();
10 }
11 
12 //=============================================================================
13 /*! change the matrix into a zero matrix with no change in structure */
15 {CPPL_VERBOSE_REPORT;
16  const std::vector<double>::iterator a_end =a.end();
17  for(std::vector<double>::iterator it=a.begin(); it!=a_end; it++){
18  (*it) =0.;
19  }
20  return *this;
21 }
22 
23 //=============================================================================
24 /*! make a deep copy of the matrix */
25 inline void dgrmatrix::copy(const dgrmatrix& mat)
26 {CPPL_VERBOSE_REPORT;
27  m =mat.m;
28  n =mat.n;
29  a =mat.a;
30  ia =mat.ia;
31  ja =mat.ja;
32 }
33 
34 //=============================================================================
35 /*! check if the component is listed */
36 inline bool dgrmatrix::isListed(const CPPL_INT& i, const CPPL_INT& j) const
37 {CPPL_VERBOSE_REPORT;
38 #ifdef CPPL_DEBUG
39  if( i<0 || j<0 || m<=i || n<=j ){
40  ERROR_REPORT;
41  std::cerr << "The required component is out of the matrix size." << std::endl
42  << "Your input is (" << i << "," << j << "), whereas the matrix size is " << m << "x" << n << "." << std::endl;
43  exit(1);
44  }
45 #endif//CPPL_DEBUG
46  //////// search ////////
47  int k_beg =ia[i]-1;
48  int k_end =ia[i+1]-1;
49  for(int k=k_beg; k<k_end; k++){
50  if(ja[k]==j+1){
51  return true;//found
52  }
53  }
54  //////// not found ////////
55  return false;
56 }
57 
58 ///////////////////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////////////
61 
62 //=============================================================================
63 /*! health checkup */
64 inline void dgrmatrix::checkup()
65 {CPPL_VERBOSE_REPORT;
66  //////// size check ////////
67  if(m<0){
68  ERROR_REPORT;
69  std::cerr << "m<0" << std::endl;
70  exit(1);
71  }
72  if(n<0){
73  ERROR_REPORT;
74  std::cerr << "n<0" << std::endl;
75  exit(1);
76  }
77  if(a.size()!=ja.size()){
78  ERROR_REPORT;
79  std::cerr << "a.size()!=ja.size()" << std::endl;
80  exit(1);
81  }
82  if(ia.size()!=size_t(m+1)){
83  ERROR_REPORT;
84  std::cerr << "ia.size()!=m+1" << std::endl;
85  exit(1);
86  }
87  if(a.size()>size_t(m*n)){
88  ERROR_REPORT;
89  std::cerr << "a.size()>m*n" << std::endl;
90  exit(1);
91  }
92 
93  //////// index check ////////
94  //not yet....
95 
96  std::cerr << "# [NOTE]@dgrmatrix::checkup(): This matrix is fine." << std::endl;
97 }
98 
99 ///////////////////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////////////////
101 ///////////////////////////////////////////////////////////////////////////////
102 
103 //=============================================================================
104 /*! swap two matrices */
105 inline void swap(dgrmatrix& A, dgrmatrix& B)
106 {CPPL_VERBOSE_REPORT;
107  std::swap(A.n,B.n);
108  std::swap(A.m,B.m);
109  std::swap(A.a,B.a);
110  std::swap(A.ia,B.ia);
111  std::swap(A.ja,B.ja);
112 }
void copy(const dgrmatrix &)
dgrmatrix & zero()
std::vector< double > a
matrix component values
Definition: dgrmatrix.hpp:11
void swap(dgrmatrix &A, dgrmatrix &B)
std::vector< CPPL_INT > ia
rowIndex (NOT zero-based BUT one-based indexing)
Definition: dgrmatrix.hpp:12
_dgematrix i(const _dgbmatrix &mat)
CPPL_INT n
matrix column size
Definition: dgrmatrix.hpp:10
void clear()
void checkup()
bool isListed(const CPPL_INT &, const CPPL_INT &) const
CPPL_INT m
matrix row size
Definition: dgrmatrix.hpp:9
std::vector< CPPL_INT > ja
columns (NOT zero-based BUT one-based indexing)
Definition: dgrmatrix.hpp:13
Real Double-precision General Compressed Sparse Row (CSR) Matrix Class.
Definition: dgrmatrix.hpp:3