NRVec concatenation implemented

This commit is contained in:
Jiri Pittner 2021-10-22 13:28:13 +02:00
parent d1a43830fc
commit 1bfb548835
2 changed files with 53 additions and 1 deletions

42
vec.cc
View File

@ -163,6 +163,8 @@ const NRVec<double> NRVec<double>::operator-() const {
return result;
}
/***************************************************************************//**
* unary minus operator in case of complex double-precision vector
* @return the modified vector by value
@ -981,6 +983,46 @@ INSTANTIZE_NONCOMPLEX(unsigned long long)
INSTANTIZE_NONCOMPLEX(float)
INSTANTIZE_NONCOMPLEX(double)
/***************************************************************************
*some efficient specializations of concatenations for plain data types
******************************************************************************/
#define INSTANTIZE_CONCAT(T) \
template<> \
NRVec<T> NRVec<T>::concat(const NRVec<T> &rhs) const \
{ \
if(nn==0) return rhs; \
if(rhs.nn==0) return *this; \
NOT_GPU(*this); \
NOT_GPU(rhs); \
NRVec<T> r(nn+rhs.nn); \
memcpy(r.v,v,nn*sizeof(T)); \
memcpy(r.v+nn,rhs.v,rhs.nn*sizeof(T)); \
return r; \
} \
INSTANTIZE_CONCAT(char)
INSTANTIZE_CONCAT(unsigned char)
INSTANTIZE_CONCAT(short)
INSTANTIZE_CONCAT(unsigned short)
INSTANTIZE_CONCAT(int)
INSTANTIZE_CONCAT(unsigned int)
INSTANTIZE_CONCAT(long)
INSTANTIZE_CONCAT(unsigned long)
INSTANTIZE_CONCAT(long long)
INSTANTIZE_CONCAT(unsigned long long)
INSTANTIZE_CONCAT(float)
INSTANTIZE_CONCAT(double)
INSTANTIZE_CONCAT(std::complex<float>)
INSTANTIZE_CONCAT(std::complex<double>)
template class NRVec<double>;
template class NRVec<std::complex<double> >;
template class NRVec<char>;

12
vec.h
View File

@ -222,7 +222,17 @@ public:
inline const NRVec operator-(const T &a) const;
inline const NRVec operator*(const T &a) const;
inline const NRVec operator/(const T &a) const;
//!concatenate vectors
NRVec concat(const NRVec &rhs) const
{
if(nn==0) return rhs;
if(rhs.nn==0) return *this;
NRVec r(nn+rhs.nn);
for(int i=0; i<nn; ++i) r[i] = (*this)[i];
for(int i=0; i<rhs.nn; ++i) r[nn+i] = rhs[i];
return r;
}
//! determine the actual value of the reference counter
inline int getcount() const {return count?*count:0;}