From 4bacfc02f942dad14636f3b2139c8dce0f390408 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Wed, 18 Mar 2026 14:53:52 +0100 Subject: [PATCH] NRVec::iamax() --- vec.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/vec.h b/vec.h index 3ae2902..63f4909 100644 --- a/vec.h +++ b/vec.h @@ -445,7 +445,9 @@ public: const int findthr(const T &val, const typename LA_traits::normtype &thr=0) const; //! determine the maximal element (in the absolute value) of this vector + inline int iamax() const; inline const T amax() const; + //! determine the minimal element (in the absolute value) of this vector inline const T amin() const; @@ -539,6 +541,7 @@ public: explicit NRVec_from1(const std::list l) : NRVec(l) {}; inline const T& operator[] (const int i) const; inline T& operator[] (const int i); + inline int iamax() const {return NRVec::iamax() + 1;}; }; @@ -1944,6 +1947,23 @@ inline const double NRVec::amax() const { return ret; } +template<> +inline int NRVec::iamax() const { + int ret; +#ifdef CUDALA + if(location == cpu){ +#endif + ret = cblas_idamax(nn, v, 1); +#ifdef CUDALA + }else{ + ret = cublasIdamax(nn, v, 1) ; + TEST_CUBLAS("cublasIdamax"); + } +#endif + return ret; +} + + /***************************************************************************//** * for this real vector \f$\vec{x}\f$ determine the element with smallest absolute value * @return \f$\vec{x}_i\f$ where \f$\left|\vec{x]_i\right|=\mathrm{min}_{j}\left|\vec{x}_{j}\right|\f$ @@ -1994,6 +2014,23 @@ inline const std::complex NRVec >::amax() const { return ret; } +template<> +inline int NRVec >::iamax() const { + int ret; +#ifdef CUDALA + if(location == cpu){ +#endif + ret = cblas_izamax(nn, v, 1); +#ifdef CUDALA + }else{ + ret = cublasIzamax(nn, (cuDoubleComplex*)v, 1); + TEST_CUBLAS("cublasIzamax"); + } +#endif + return ret; +} + + /***************************************************************************//** * for a given complex vector \f$\vec{v}\f$, determine the smallest index of the minimum * magnitude element, i.e. minimal element in the 1-norm