From e8641c283352d8d01b874d8f773596ccef7b5915 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Wed, 15 Jun 2022 14:42:19 +0200 Subject: [PATCH] vec.h added optional parameters to NRVec::norm() --- vec.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vec.h b/vec.h index 02e1bad..583bf0c 100644 --- a/vec.h +++ b/vec.h @@ -361,7 +361,7 @@ public: void dealloc(void) {resize(0);} //! determine the norm of this vector - inline const typename LA_traits::normtype norm() const; + inline const typename LA_traits::normtype norm(int length= -1, int offset=0, int stride=1) const; //! normalize this vector and optionally save the norm NRVec& normalize(typename LA_traits::normtype* norm = 0); @@ -1701,15 +1701,15 @@ inline const double NRVec >::asum() const { * @return \f$\sum_{i=1}^N\left|\vec{x}_i\right|^2\f$ ******************************************************************************/ template<> -inline const double NRVec::norm() const { +inline const double NRVec::norm(int length, int offset, int stride) const { double ret(0.); #ifdef CUDALA if(location == cpu){ #endif - ret = cblas_dnrm2(nn, v, 1); + ret = cblas_dnrm2((length>=0?length:nn), v+offset, stride); #ifdef CUDALA }else{ - ret = cublasDnrm2(nn, v, 1); + ret = cublasDnrm2((length>=0?length:nn), v+offset, stride); TEST_CUBLAS("cublasDnrm2"); } #endif @@ -1721,15 +1721,15 @@ inline const double NRVec::norm() const { * @return \f$\sum_{i=1}^N\left|\vec{x}_i\right|^2\f$ ******************************************************************************/ template<> -inline const double NRVec< std::complex >::norm() const { +inline const double NRVec< std::complex >::norm(int length, int offset, int stride) const { double ret(0.); #ifdef CUDALA if(location == cpu){ #endif - ret = cblas_dznrm2(nn, v, 1); + ret = cblas_dznrm2((length>=0?length:nn), v+offset, stride); #ifdef CUDALA }else{ - ret = cublasDznrm2(nn, (cuDoubleComplex*)v, 1); + ret = cublasDznrm2((length>=0?length:nn), ((cuDoubleComplex*)v)+offset, stride); TEST_CUBLAS("cublasDzrm2"); } #endif