From 0ca6cfe46fb0d54db8b423e3e9b94969f1cbd8ad Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Tue, 17 Nov 2026 14:44:06 +0100 Subject: [PATCH] NRMat::diagonalof for complex and complex --- mat.cc | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/mat.cc b/mat.cc index c022fda..28560e9 100644 --- a/mat.cc +++ b/mat.cc @@ -3954,6 +3954,88 @@ const float* NRMat::diagonalof(NRVec &r, const bool divide, bool c return ret; } +template<> +const std::complex* NRMat >::diagonalof(NRVec > &r, const bool divide, bool cache) const { +#ifdef DEBUG + if(r.size() != mm) laerror("incompatible vector in NRMat >::diagonalof(...)"); +#endif + NOT_GPU(*this); + NOT_GPU(r); + + std::complex a;//!< temporary variable for storing the scaling factor + r.copyonwrite(); + if(nn==mm){ + #ifdef MATPTR + if(divide){ + for(int i=0; i< nn; i++) if((a=v[i][i])!=(double)0) r[i] /= a; + }else{ + for(int i=0; i< nn; i++) r[i] = v[i][i]; + } + #else + if(divide){ + int i(0),j(0); + for(i=j=0; j +const std::complex * NRMat >::diagonalof(NRVec > &r, const bool divide, bool cache) const { +#ifdef DEBUG + if(r.size() != mm) laerror("incompatible vector in NRMat >::diagonalof(...)"); +#endif + NOT_GPU(*this); + NOT_GPU(r); + + std::complex a;//!< temporary variable for storing the scaling factor + r.copyonwrite(); + if(nn==mm){ + #ifdef MATPTR + if(divide){ + for(int i=0; i< nn; i++) if((a=v[i][i])!=(float)0) r[i] /= a; + }else{ + for(int i=0; i< nn; i++) r[i] = v[i][i]; + } + #else + if(divide){ + int i(0),j(0); + for(i=j=0; j