efficient swap operation for vector and matrix classes

This commit is contained in:
2021-06-29 14:39:04 +02:00
parent 3288e51fba
commit 9d0249cdc4
5 changed files with 57 additions and 0 deletions

16
mat.h
View File

@@ -390,6 +390,22 @@ public:
void strassen(const T beta, const NRMat &a, const char transa, const NRMat &b, const char transb, const T alpha);
void s_cutoff(const int,const int,const int,const int) const;
#endif
void swap(NRMat &rhs) //more efficient swap than via tmp and constructors and operator=
{
int tmpnn=nn; nn=rhs.nn; rhs.nn=tmpnn;
int tmpmm=mm; mm=rhs.mm; rhs.mm=tmpmm;
#ifdef MATPTR
T **
#else
T *
#endif
tmpv=v; v=rhs.v; rhs.v=tmpv;
int *tmpcount=count; count=rhs.count; rhs.count=tmpcount;
#ifdef CUDALA
GPUID tmplocation=location; location=rhs.location; rhs.location=tmplocation;
#endif
}
};
}//namespace