diff --git a/smat.h b/smat.h index fdd76fe..6be29fd 100644 --- a/smat.h +++ b/smat.h @@ -31,15 +31,6 @@ namespace LA { template class NRPerm; template class NRSMat_from1; -//return type of the const element access NRSMat::operator(): a reference, except for complex types, -//where the upper triangle has to be conjugated on the fly -template struct NRSMat_const_element {typedef const T& type;}; -template struct NRSMat_const_element > {typedef const std::complex type;}; - -//conjugation of the stored lower triangle element when the upper triangle element is requested -template inline const T& NRSMat_conj_upper(const T &x) {return x;} -template inline const std::complex NRSMat_conj_upper(const std::complex &x) {return std::conj(x);} - /***************************************************************************//** * This class implements a general symmetric or hermitian matrix the elements @@ -164,10 +155,9 @@ public: inline T& operator[](const size_t ij); //NOTE: complex NRSMat is hermitian, only the lower triangle is stored, the upper one is its complex conjugate - //const operator() returns conj(a(j,i)) for i::type operator()(const int i, const int j) const; + //operator() (both const and non-const) just accesses the storage: (i,j) and (j,i) refer to the same stored element, + //NO conjugation is performed for ij)? (i-2)*(i-1)/2+j-1 : (j-2)*(j-1)/2+i-1; /***************************************************************************//** * determine matrix element of this symmetric matrix of general type T - * PITFALL for complex (hermitian) matrices: for \f$i::operator()(const int i, const int j) { } /***************************************************************************//** - * determine matrix element of this symmetric or hermitian matrix of general type T + * determine matrix element of this symmetric matrix of general type T + * for complex (hermitian) matrices: for \f$i::operator[] ******************************************************************************/ template -inline typename NRSMat_const_element::type NRSMat::operator()(const int i, const int j) const { +inline const T & NRSMat::operator()(const int i, const int j) const { #ifdef DEBUG if(i<0||i>=nn||j<0||j>=nn) std::cout<<"INDEX PROBLEM "<<0<<" "<::operator()(const int, const int) first index out of range - low"); @@ -830,7 +820,7 @@ inline typename NRSMat_const_element::type NRSMat::operator()(const int i, #endif NOT_GPU(*this); - return (i>=j) ? v[SMat_index_igej(i,j)] : NRSMat_conj_upper(v[SMat_index_igej(j,i)]); + return v[SMat_index(i,j)]; } /***************************************************************************//** @@ -1357,7 +1347,7 @@ public: explicit NRSMat_from1(const NRMat &rhs): NRSMat(rhs) {}; explicit NRSMat_from1(const NRVec &rhs, const int n): NRSMat(rhs,n) {}; - inline typename NRSMat_const_element::type operator() (const int i, const int j) const { //for complex conjugated for i::operator() + inline const T& operator() (const int i, const int j) const { //storage access, no conjugation for complex i::operator() #ifdef DEBUG if(i<=0||i>NRSMat::nn||j<=0||j>NRSMat::nn) std::cout<<"INDEX PROBLEM "<<1<<" "<::nn<<" "<<1<<" "<::nn<::operator() (const int, const int) first indexout of range - low"); @@ -1365,10 +1355,10 @@ public: if(j<=0) laerror("index in const T& NRSMat_from1::operator() (const int, const int) second index out of range - low"); if(j>NRSMat::nn) laerror("index in const T& NRSMat_from1::operator() (const int, const int) second index out of range - high"); #endif - return (i>=j) ? NRSMat::v[SMat_index_1igej(i,j)] : NRSMat_conj_upper(NRSMat::v[SMat_index_1igej(j,i)]); + return NRSMat::v[SMat_index_1(i,j)]; } - inline T& operator() (const int i, const int j){ //PITFALL: no conjugation for complex i::operator() + inline T& operator() (const int i, const int j){ //storage access, no conjugation for complex i::operator() #ifdef DEBUG if(i<=0||i>NRSMat::nn||j<=0||j>NRSMat::nn) std::cout<<"INDEX PROBLEM "<<1<<" "<::nn<<" "<<1<<" "<::nn<::operator() (const int, const int) first indexout of range - low");