CPPLapack
 All Classes Files Functions Variables Friends Pages
dsymatrix-misc.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! complete the upper-right components */
3 inline void dsymatrix::complete() const
4 {CPPL_VERBOSE_REPORT;
5  for(CPPL_INT i=0; i<n; i++){
6  for(CPPL_INT j=0; j<i; j++){
7  darray[i][j] =darray[j][i];
8  }
9  }
10 }
11 
12 //=============================================================================
13 /*! clear all the matrix data and set the sizes 0 */
14 inline void dsymatrix::clear()
15 {CPPL_VERBOSE_REPORT;
16  n =0;
17  delete [] array;
18  array =NULL;
19  delete [] darray;
20  darray =NULL;
21 }
22 
23 //=============================================================================
24 /*! change the matrix into a zero matrix */
26 {CPPL_VERBOSE_REPORT;
27  for(CPPL_INT j=0; j<n; j++){
28  for(CPPL_INT i=j; i<n; i++){
29  darray[j][i] =0.;
30  }
31  }
32  return *this;
33 }
34 
35 //=============================================================================
36 /*! change the matrix into an identity matrix */
38 {CPPL_VERBOSE_REPORT;
39  for(CPPL_INT j=0; j<n; j++){
40  darray[j][j] =1.;
41  for(CPPL_INT i=j+1; i<n; i++){
42  darray[j][i] =0.;
43  }
44  }
45  return *this;
46 }
47 
48 //=============================================================================
49 /*! change sign(+/-) of the matrix */
50 inline void dsymatrix::chsign()
51 {CPPL_VERBOSE_REPORT;
52  for(CPPL_INT j=0; j<n; j++){
53  for(CPPL_INT i=j; i<n; i++){
54  darray[j][i] =-darray[j][i];
55  }
56  }
57 }
58 
59 //=============================================================================
60 /*! make a deep copy of the matrix */
61 inline void dsymatrix::copy(const dsymatrix& mat)
62 {CPPL_VERBOSE_REPORT;
63  n =mat.n;
64  delete [] array;
65  array =new double[n*n];
66  delete [] darray;
67  darray =new double*[n];
68  for(int i=0; i<n; i++){
69  darray[i] =&array[i*n];
70  }
71 
72  for(CPPL_INT j=0; j<n; j++){
73  for(CPPL_INT i=j; i<n; i++){
74  darray[j][i] =mat.darray[j][i];
75  }
76  }
77 }
78 
79 //=============================================================================
80 /*! make a shallow copy of the matrix\n
81  This function is not designed to be used in project codes. */
82 inline void dsymatrix::shallow_copy(const _dsymatrix& mat)
83 {CPPL_VERBOSE_REPORT;
84  n =mat.n;
85  delete [] array;
86  array =mat.array;
87  delete [] darray;
88  darray =mat.darray;
89 
90  mat.nullify();
91 }
92 
93 //=============================================================================
94 /*! resize the matrix */
95 inline dsymatrix& dsymatrix::resize(const CPPL_INT& _n)
96 {CPPL_VERBOSE_REPORT;
97 #ifdef CPPL_DEBUG
98  if( _n<0 ){
99  ERROR_REPORT;
100  std::cerr << "Matrix sizes must be positive integers." << std::endl
101  << "Your input was (" << _n << ")." << std::endl;
102  exit(1);
103  }
104 #endif//CPPL_DEBUG
105 
106  n =_n;
107  delete [] array;
108  array =new double[n*n];
109  delete [] darray;
110  darray =new double*[n];
111  for(int i=0; i<n; i++){
112  darray[i] =&array[i*n];
113  }
114 
115  return *this;
116 }
117 
118 ///////////////////////////////////////////////////////////////////////////////
119 ///////////////////////////////////////////////////////////////////////////////
120 ///////////////////////////////////////////////////////////////////////////////
121 
122 //=============================================================================
123 /*! get row of the matrix */
124 inline _drovector dsymatrix::row(const CPPL_INT& _m) const
125 {CPPL_VERBOSE_REPORT;
126 #ifdef CPPL_DEBUG
127  if( _m<0 || _m>m ){
128  ERROR_REPORT;
129  std::cerr << "Input row number must be between 0 and " << m << "." << std::endl
130  << "Your input was " << _m << "." << std::endl;
131  exit(1);
132  }
133 #endif//CPPL_DEBUG
134 
135  drovector v(n);
136  for(CPPL_INT j=0; j<n; j++){
137  v(j)=(*this)(_m,j);
138  }
139  return _(v);
140 }
141 
142 //=============================================================================
143 /*! get column of the matrix */
144 inline _dcovector dsymatrix::col(const CPPL_INT& _n) const
145 {CPPL_VERBOSE_REPORT;
146 #ifdef CPPL_DEBUG
147  if( _n<0 || _n>n ){
148  ERROR_REPORT;
149  std::cerr << "Input row number must be between 0 and " << n << "." << std::endl
150  << "Your input was " << _n << "." << std::endl;
151  exit(1);
152  }
153 #endif//CPPL_DEBUG
154 
155  dcovector v(m);
156  for(CPPL_INT i=0; i<m; i++){
157  v(i)=(*this)(i,_n);
158  }
159  return _(v);
160 }
161 
162 ///////////////////////////////////////////////////////////////////////////////
163 ///////////////////////////////////////////////////////////////////////////////
164 ///////////////////////////////////////////////////////////////////////////////
165 
166 //=============================================================================
167 /*! swap two matrices */
168 inline void swap(dsymatrix& A, dsymatrix& B)
169 {CPPL_VERBOSE_REPORT;
170  CPPL_INT A_n =A.n;
171  double* A_array =A.array;
172  double** A_darray =A.darray;
173  A.n=B.n; A.array=B.array; A.darray=B.darray;
174  B.n=A_n; B.array=A_array; B.darray=A_darray;
175 }
176 
177 //=============================================================================
178 /*! convert user object to smart-temporary object */
179 inline _dsymatrix _(dsymatrix& mat)
180 {CPPL_VERBOSE_REPORT;
181  _dsymatrix newmat;
182 
183  //////// shallow copy ////////
184  newmat.n =mat.n;
185  newmat.array =mat.array;
186  newmat.darray =mat.darray;
187 
188  //////// nullify ////////
189  mat.n =0;
190  mat.array =NULL;
191  mat.darray =NULL;
192 
193  return newmat;
194 }
_dcovector col(const CPPL_INT &) const
void swap(dsymatrix &A, dsymatrix &B)
friend _dsymatrix _(dsymatrix &)
dsymatrix & zero()
Real Double-precision Symmetric Matrix Class [l-type (UPLO=l) Strage].
Definition: dsymatrix.hpp:3
dsymatrix & identity()
double * array
1D array to store matrix data
Definition: _dsymatrix.hpp:12
Real Double-precision Row Vector Class.
Definition: drovector.hpp:3
CPPL_INT const & m
matrix row size
Definition: dsymatrix.hpp:9
_drovector row(const CPPL_INT &) const
(DO NOT USE) Smart-temporary Real Double-precision Row Vector Class
Definition: _drovector.hpp:3
friend _dsymatrix i(const dsymatrix &)
double ** darray
array of pointers of column head addresses
Definition: _dsymatrix.hpp:13
CPPL_INT n
matrix column size
Definition: dsymatrix.hpp:10
void shallow_copy(const _dsymatrix &)
_dsymatrix _(dsymatrix &mat)
(DO NOT USE) Smart-temporary Real Double-precision Symmetric Matrix Class
Definition: _dsymatrix.hpp:3
Real Double-precision Column Vector Class.
Definition: dcovector.hpp:3
void complete() const
double * array
1D array to store matrix data
Definition: dsymatrix.hpp:11
dsymatrix & resize(const CPPL_INT &)
void copy(const dsymatrix &)
CPPL_INT n
matrix column size
Definition: _dsymatrix.hpp:11
double ** darray
array of pointers of column head addresses
Definition: dsymatrix.hpp:12
(DO NOT USE) Smart-temporary Real Double-precision Column Vector Class
Definition: _dcovector.hpp:3
void nullify() const