diff --git a/vec.cc b/vec.cc index 6425bbd..7fe3348 100644 --- a/vec.cc +++ b/vec.cc @@ -163,6 +163,8 @@ const NRVec NRVec::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 NRVec::concat(const NRVec &rhs) const \ +{ \ +if(nn==0) return rhs; \ +if(rhs.nn==0) return *this; \ +NOT_GPU(*this); \ +NOT_GPU(rhs); \ +NRVec 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) +INSTANTIZE_CONCAT(std::complex) + + + + template class NRVec; template class NRVec >; template class NRVec; diff --git a/vec.h b/vec.h index 456aa0a..2be55a0 100644 --- a/vec.h +++ b/vec.h @@ -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