From 6135a4b595f95ac8b25784606b73d279d2267184 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Mon, 24 May 2021 18:45:58 +0200 Subject: [PATCH] fixed clear() for nested types --- la_traits.h | 10 +++++----- mat.h | 2 +- smat.h | 2 +- sparsemat.h | 2 +- vec.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/la_traits.h b/la_traits.h index b51c4a1..7d82146 100644 --- a/la_traits.h +++ b/la_traits.h @@ -349,17 +349,17 @@ typedef X producttype; \ typedef typename LA_traits::normtype normtype; \ typedef X::realtype> realtype; \ typedef X::complextype> complextype; \ -static bool gencmp(const C *x, const C *y, size_t n) {for(size_t i=0; iy;} \ -static inline bool smaller(const C &x, const C &y) {return x *x, const X *y, size_t n) {for(size_t i=0; i &x, const X &y) {return x>y;} \ +static inline bool smaller(const X &x, const X &y) {return x &x) {return x.norm();} \ static inline void axpy (X&s, const X &x, const C c) {s.axpy(c,x);} \ static void put(int fd, const X &x, bool dimensions=1, bool transp=0) {x.put(fd,dimensions,transp);} \ static void get(int fd, X &x, bool dimensions=1, bool transp=0) {x.get(fd,dimensions,transp);} \ static void multiput(size_t n,int fd, const X *x, bool dimensions=1) {for(size_t i=0; i *x, bool dimensions=1) {for(size_t i=0; i *dest, X *src, size_t n) {for(size_t i=0; i *dest, size_t n) {for(size_t i=0; i &x) {x.copyonwrite();}\ static bool is_plaindata() {return false;}\ static void clearme(X &x) {x.clear();}\ diff --git a/mat.h b/mat.h index 9964b53..f2c421c 100644 --- a/mat.h +++ b/mat.h @@ -292,7 +292,7 @@ public: //! set all matrix elements equal to zero void clear(){ if(nn&&mm){ - copyonwrite(true); + copyonwrite(LA_traits::is_plaindata()); LA_traits::clear((*this)[0], (size_t)nn*mm); } }; diff --git a/smat.h b/smat.h index cc3c87e..2162779 100644 --- a/smat.h +++ b/smat.h @@ -162,7 +162,7 @@ public: void copyonwrite(bool detachonly=false); - void clear() {copyonwrite(true); LA_traits::clear(v,NN2);}; //zero out + void clear() {copyonwrite(LA_traits::is_plaindata()); LA_traits::clear(v,NN2);}; //zero out void resize(const int n); void dealloc(void) {resize(0);} diff --git a/sparsemat.h b/sparsemat.h index b71f5cf..57e57ec 100644 --- a/sparsemat.h +++ b/sparsemat.h @@ -133,7 +133,7 @@ public: inline bool issymmetric() const {return symmetric;} unsigned int length() const; void copyonwrite(bool detachonly=false); - void clear() {copyonwrite(true); if(count) {delete count; count=NULL;}} + void clear() {copyonwrite(LA_traits::is_plaindata()); if(count) {delete count; count=NULL;}} void simplify(); const T trace() const; const typename LA_traits::normtype norm(const T scalar=(T)0) const; //is const only mathematically, not in internal implementation - we have to simplify first diff --git a/vec.h b/vec.h index 4ba8ac2..6366656 100644 --- a/vec.h +++ b/vec.h @@ -155,7 +155,7 @@ public: void copyonwrite(bool detachonly=false); //! purge this vector - void clear() { copyonwrite(true); LA_traits::clear(v, nn); }; + void clear() { copyonwrite(LA_traits::is_plaindata()); LA_traits::clear(v, nn); }; //! assignment operator assigns given vector NRVec& operator=(const NRVec &rhs);