From b1fea2f1c2f0baccf8952cedf4698b4b66a61e2f Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Sat, 13 Nov 2021 19:00:46 +0100 Subject: [PATCH] diffabs return normtype entity, elementwise abs() implemented --- mat.h | 23 +++++++++++++++-------- smat.h | 20 ++++++++++++++++---- vec.h | 16 +++++++++++++--- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/mat.h b/mat.h index 512843f..1e0ff9b 100644 --- a/mat.h +++ b/mat.h @@ -409,7 +409,8 @@ public: #endif } - NRMat diffabs(const NRMat &rhs) const; //difference of absolute values + NRMat::normtype> abs() const; //elementwise absolute values + NRMat::normtype> diffabs(const NRMat &rhs) const; //difference of absolute values }; }//namespace @@ -1505,19 +1506,25 @@ NRMat & NRMat::operator-=(const NRMat &rhs) { /*difference of absolute values*/ template -NRMat NRMat::diffabs(const NRMat &rhs) const { +NRMat::normtype> NRMat::diffabs(const NRMat &rhs) const { #ifdef DEBUG if (nn != rhs.nn ||mm!=rhs.mm) laerror("incompatible dimensions"); #endif NOT_GPU(*this); NOT_GPU(rhs); -NRMat r(nn,mm); - #ifdef MATPTR - for(size_t i=0; i< (size_t)nn*mm; i++) r.v[0][i] = MYABS(v[0][i]) - MYABS(rhs.v[0][i]); - #else - for(size_t i=0; i<(size_t) nn*mm; i++) r.v[i] = MYABS(v[i]) - MYABS(rhs.v[i]); - #endif + NRMat::normtype> r(nn,mm); + for(size_t i=0; i< nn; i++) for(size_t j=0; j< mm; j++) r(i,j) = MYABS((*this)(i,j)) - MYABS(rhs(i,j)); + return r; +} + +/*elementwise absolute values*/ +template +NRMat::normtype> NRMat::abs() const { + NOT_GPU(*this); + + NRMat::normtype> r(nn,mm); + for(size_t i=0; i< nn; i++) for(size_t j=0; j< mm; j++) r(i,j) = MYABS((*this)(i,j)); return r; } diff --git a/smat.h b/smat.h index 975e5b4..621e33a 100644 --- a/smat.h +++ b/smat.h @@ -186,7 +186,8 @@ public: #endif } - NRSMat diffabs(const NRSMat &rhs) const; //difference of absolute values + NRSMat::normtype> diffabs(const NRSMat &rhs) const; //difference of absolute values + NRSMat::normtype> abs() const; //elementwise absolute values }; }//namespace @@ -395,18 +396,29 @@ inline NRSMat & NRSMat::operator-=(const T &a) { /*difference of absolute values*/ template -NRSMat NRSMat::diffabs(const NRSMat &rhs) const { +NRSMat::normtype> NRSMat::diffabs(const NRSMat &rhs) const { #ifdef DEBUG if (nn != rhs.nn) laerror("incompatible dimensions"); #endif NOT_GPU(*this); NOT_GPU(rhs); -NRSMat r(nn); - for(int i=0; i::normtype> r(nn); + for(int i=0; i +NRSMat::normtype> NRSMat::abs() const { + NOT_GPU(*this); + +NRSMat::normtype> r(nn); + for(int i=0; i::normtype> diffabs(const NRVec &rhs) const; //difference of absolute values + NRVec::normtype> abs() const; //element-wise absolute values }; @@ -834,18 +835,27 @@ inline NRVec & NRVec::operator-=(const NRVec &rhs) { * @return reference to the modified vector ******************************************************************************/ template -NRVec NRVec::diffabs(const NRVec &rhs) const { +NRVec::normtype> NRVec::diffabs(const NRVec &rhs) const { #ifdef DEBUG if (nn != rhs.nn) laerror("incompatible dimensions"); #endif NOT_GPU(*this); NOT_GPU(rhs); -NRVec r(nn); +NRVec::normtype> r(nn); for(int i=0; i +NRVec::normtype> NRVec::abs() const { + NOT_GPU(*this); + +NRVec::normtype> r(nn); + for(int i=0; i