fixed clear() for nested types

This commit is contained in:
Jiri Pittner 2021-05-24 18:45:58 +02:00
parent 222c1cfb8c
commit 6135a4b595
5 changed files with 9 additions and 9 deletions

View File

@ -349,17 +349,17 @@ typedef X<C> producttype; \
typedef typename LA_traits<C>::normtype normtype; \
typedef X<typename LA_traits<C>::realtype> realtype; \
typedef X<typename LA_traits<C>::complextype> complextype; \
static bool gencmp(const C *x, const C *y, size_t n) {for(size_t i=0; i<n; ++i) if(x[i]!=y[i]) return true; return false;} \
static inline bool bigger(const C &x, const C &y) {return x>y;} \
static inline bool smaller(const C &x, const C &y) {return x<y;} \
static bool gencmp(const X<C> *x, const X<C> *y, size_t n) {for(size_t i=0; i<n; ++i) if(x[i]!=y[i]) return true; return false;} \
static inline bool bigger(const X<C> &x, const X<C> &y) {return x>y;} \
static inline bool smaller(const X<C> &x, const X<C> &y) {return x<y;} \
static inline normtype norm (const X<C> &x) {return x.norm();} \
static inline void axpy (X<C>&s, const X<C> &x, const C c) {s.axpy(c,x);} \
static void put(int fd, const X<C> &x, bool dimensions=1, bool transp=0) {x.put(fd,dimensions,transp);} \
static void get(int fd, X<C> &x, bool dimensions=1, bool transp=0) {x.get(fd,dimensions,transp);} \
static void multiput(size_t n,int fd, const X<C> *x, bool dimensions=1) {for(size_t i=0; i<n; ++i) x[i].put(fd,dimensions);} \
static void multiget(size_t n,int fd, X<C> *x, bool dimensions=1) {for(size_t i=0; i<n; ++i) x[i].get(fd,dimensions);} \
static void copy(C *dest, C *src, size_t n) {for(size_t i=0; i<n; ++i) dest[i]=src[i];} \
static void clear(C *dest, size_t n) {for(size_t i=0; i<n; ++i) dest[i].clear();}\
static void copy(X<C> *dest, X<C> *src, size_t n) {for(size_t i=0; i<n; ++i) dest[i]=src[i];} \
static void clear(X<C> *dest, size_t n) {for(size_t i=0; i<n; ++i) dest[i].clear();}\
static void copyonwrite(X<C> &x) {x.copyonwrite();}\
static bool is_plaindata() {return false;}\
static void clearme(X<C> &x) {x.clear();}\

2
mat.h
View File

@ -292,7 +292,7 @@ public:
//! set all matrix elements equal to zero
void clear(){
if(nn&&mm){
copyonwrite(true);
copyonwrite(LA_traits<T>::is_plaindata());
LA_traits<T>::clear((*this)[0], (size_t)nn*mm);
}
};

2
smat.h
View File

@ -162,7 +162,7 @@ public:
void copyonwrite(bool detachonly=false);
void clear() {copyonwrite(true); LA_traits<T>::clear(v,NN2);}; //zero out
void clear() {copyonwrite(LA_traits<T>::is_plaindata()); LA_traits<T>::clear(v,NN2);}; //zero out
void resize(const int n);
void dealloc(void) {resize(0);}

View File

@ -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<T>::is_plaindata()); if(count) {delete count; count=NULL;}}
void simplify();
const T trace() const;
const typename LA_traits<T>::normtype norm(const T scalar=(T)0) const; //is const only mathematically, not in internal implementation - we have to simplify first

2
vec.h
View File

@ -155,7 +155,7 @@ public:
void copyonwrite(bool detachonly=false);
//! purge this vector
void clear() { copyonwrite(true); LA_traits<T>::clear(v, nn); };
void clear() { copyonwrite(LA_traits<T>::is_plaindata()); LA_traits<T>::clear(v, nn); };
//! assignment operator assigns given vector
NRVec& operator=(const NRVec &rhs);