Go to the documentation of this file.00001
00002
00003 inline void zhsmatrix::clear()
00004 {VERBOSE_REPORT;
00005 n =0;
00006 data.clear();
00007 line.clear();
00008 }
00009
00010
00011
00012 inline zhsmatrix& zhsmatrix::zero()
00013 {VERBOSE_REPORT;
00014 data.resize(0);
00015 for(long i=0; i<n; i++){ line[i].resize(0); }
00016 return *this;
00017 }
00018
00019
00020
00021 inline void zhsmatrix::chsign()
00022 {VERBOSE_REPORT;
00023 for(std::vector<zcomponent>::iterator it=data.begin(); it!=data.end(); it++){
00024 it->v =-it->v;
00025 }
00026 }
00027
00028
00029
00030 inline void zhsmatrix::copy(const zhsmatrix& mat)
00031 {VERBOSE_REPORT;
00032 n =mat.n;
00033 data =mat.data;
00034 line =mat.line;
00035 }
00036
00037
00038
00039
00040 inline void zhsmatrix::shallow_copy(const _zhsmatrix& mat)
00041 {VERBOSE_REPORT;
00042 data.clear();
00043 line.clear();
00044
00045 n =mat.n;
00046 data.swap(mat.data);
00047 line.swap(mat.line);
00048
00049 mat.nullify();
00050 }
00051
00052
00053
00054 inline zhsmatrix& zhsmatrix::resize(const long& _n, const long _c, const long _l)
00055 {VERBOSE_REPORT;
00056 #ifdef CPPL_DEBUG
00057 if( _n<0 || _c<0 || _l<0 ){
00058 ERROR_REPORT;
00059 std::cerr << "Matrix sizes and the length of arrays must be positive integers. " << std::endl
00060 << "Your input was (" << _n << "," << _c << "," << _l << ")." << std::endl;
00061 exit(1);
00062 }
00063 #endif//CPPL_DEBUG
00064
00065 n =_n;
00066 data.resize(0);
00067 data.reserve(_c);
00068 line.resize(n);
00069 for(long i=0; i<n; i++){
00070 line[i].resize(0);
00071 line[i].reserve(_l);
00072 }
00073
00074 return *this;
00075 }
00076
00077
00078
00079 inline void zhsmatrix::stretch(const long& dn)
00080 {VERBOSE_REPORT;
00081 if(dn==0){ return; }
00082
00083 #ifdef CPPL_DEBUG
00084 if( n+dn<0 ){
00085 ERROR_REPORT;
00086 std::cerr << "The new matrix size must be larger than zero." << std::endl
00087 << "Your input was (" << dn << ")." << std::endl;
00088 exit(1);
00089 }
00090 #endif//CPPL_DEBUG
00091
00092 n +=dn;
00093
00094 if(dn<0){
00095
00096 for(std::vector<zcomponent>::reverse_iterator it=data.rbegin(); it!=data.rend(); it++){
00097 if( long(it->i)>=n ){ del(data.rend()-it-1); }
00098 }
00099
00100 for(long i=0; i<-dn; i++){
00101 line.pop_back();
00102 }
00103 }
00104 else{
00105
00106 for(long i=0; i<dn; i++){
00107 line.push_back( std::vector<uint32_t>(0) );
00108 }
00109 }
00110 }
00111
00112
00113
00114 inline bool zhsmatrix::isListed(const long& i, const long& j) const
00115 {VERBOSE_REPORT;
00116 #ifdef CPPL_DEBUG
00117 if( i<0 || j<0 || n<=i || n<=j ){
00118 ERROR_REPORT;
00119 std::cerr << "The required component is out of the matrix size." << std::endl
00120 << "Your input was (" << i << "," << j << ")." << std::endl;
00121 exit(1);
00122 }
00123 #endif//CPPL_DEBUG
00124
00125 const uint32_t ii(std::max(i,j)), jj(std::min(i,j));
00126 for(std::vector<uint32_t>::const_iterator p=line[ii].begin(); p!=line[ii].end(); p++){
00127 if(data[*p].j==jj){ return 1; }
00128 }
00129 return 0;
00130 }
00131
00132
00133
00134
00135 inline long zhsmatrix::number(const long& i, const long& j) const
00136 {VERBOSE_REPORT;
00137 #ifdef CPPL_DEBUG
00138 if( i<0 || j<0 || n<=i || n<=j ){
00139 ERROR_REPORT;
00140 std::cerr << "The required component is out of the matrix size." << std::endl
00141 << "Your input was (" << i << "," << j << ")." << std::endl;
00142 exit(1);
00143 }
00144 #endif//CPPL_DEBUG
00145
00146 const uint32_t ii(std::max(i,j)), jj(std::min(i,j));
00147 for(std::vector<uint32_t>::const_iterator p=line[ii].begin(); p!=line[ii].end(); p++){
00148 if(data[*p].j==jj){ return *p; }
00149 }
00150 return -1;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159 inline _zrovector zhsmatrix::row(const long& _m) const
00160 {VERBOSE_REPORT;
00161 #ifdef CPPL_DEBUG
00162 if( _m<0 || _m>m ){
00163 ERROR_REPORT;
00164 std::cerr << "Input row number must be between 0 and " << m << "." << std::endl
00165 << "Your input was " << _m << "." << std::endl;
00166 exit(1);
00167 }
00168 #endif//CPPL_DEBUG
00169
00170 zrovector vec( zrovector(n).zero() );
00171 for(std::vector<uint32_t>::const_iterator p=line[_m].begin(); p!=line[_m].end(); p++){
00172 if( long(data[*p].i)==_m ){
00173 vec(data[*p].j) =data[*p].v;
00174 }
00175 else{
00176 vec(data[*p].i) =std::conj(data[*p].v);
00177 }
00178 }
00179 return _(vec);
00180 }
00181
00182
00183
00184 inline _zcovector zhsmatrix::col(const long& _n) const
00185 {VERBOSE_REPORT;
00186 #ifdef CPPL_DEBUG
00187 if( _n<0 || _n>n ){
00188 ERROR_REPORT;
00189 std::cerr << "Input row number must be between 0 and " << n << "." << std::endl
00190 << "Your input was " << _n << "." << std::endl;
00191 exit(1);
00192 }
00193 #endif//CPPL_DEBUG
00194
00195 zcovector vec( zcovector(m).zero() );
00196 for(std::vector<uint32_t>::const_iterator p=line[_n].begin(); p!=line[_n].end(); p++){
00197 if( long(data[*p].i)==_n ){
00198 vec(data[*p].j) =std::conj(data[*p].v);
00199 }
00200 else{
00201 vec(data[*p].i) =data[*p].v;
00202 }
00203 }
00204 return _(vec);
00205 }
00206
00207
00208
00209 inline void zhsmatrix::diet(const double eps)
00210 {VERBOSE_REPORT;
00211 for(std::vector<zcomponent>::reverse_iterator it=data.rbegin(); it!=data.rend(); it++){
00212 if( fabs(it->v.real())<eps && fabs(it->v.imag())<eps ){
00213 del(data.rend()-it-1);
00214 }
00215 }
00216 }
00217
00218
00219
00220
00221
00222
00223
00224 inline void swap(zhsmatrix& A, zhsmatrix& B)
00225 {VERBOSE_REPORT;
00226 std::swap(A.n,B.n);
00227 std::swap(A.data,B.data);
00228 std::swap(A.line,B.line);
00229 }
00230
00231
00232
00233 inline _zhsmatrix _(zhsmatrix& mat)
00234 {VERBOSE_REPORT;
00235 _zhsmatrix newmat;
00236
00237 newmat.n =mat.n;
00238 std::swap(newmat.data, mat.data);
00239 std::swap(newmat.line, mat.line);
00240
00241 mat.n =0;
00242 return newmat;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251 inline void zhsmatrix::checkup()
00252 {VERBOSE_REPORT;
00253
00254 for(long i=0; i<m; i++){
00255 if( std::fabs((*this)(i,i).imag()) > DBL_MIN ){
00256 ERROR_REPORT;
00257 std::cerr << "Diagonal components of a Hermitian matrix have to be real numbers." << std::endl
00258 << "(*this)(" << i << "," << i << ") was a complex number, " << (*this)(i,i) << "." << std::endl;
00259 exit(1);
00260 }
00261 }
00262
00263
00264 std::cerr << "# [NOTE]@zhsmatrix::checkup(): This symmetric sparse matrix is fine." << std::endl;
00265 }