diff --git a/vec.h b/vec.h index 3992a7f..16f9597 100644 --- a/vec.h +++ b/vec.h @@ -201,10 +201,12 @@ public: //! extract specified subvector const NRVec subvector(const int from, const int to) const; const NRVec subvector(const NRVec &selection) const; - + void subvector_from(const NRVec &selection, const NRVec &rhs); //gather from rhs + //! store given vector at given position into the current vector (scatter) void storesubvector(const int from, const NRVec &rhs); - void storesubvector(const NRVec &selection, const NRVec &rhs); + void storesubvector(const NRVec &selection, const NRVec &rhs); + void storesubvector_to(const NRVec &selection, NRVec &rhs) const; //scatter to rhs //! relational operators const bool operator!=(const NRVec &rhs) const @@ -2280,6 +2282,25 @@ return r; } +template +void NRVec::subvector_from(const NRVec &selection, const NRVec &rhs) +{ + NOT_GPU(*this); + const int n = selection.size(); + if(n!=size()) laerror("size mismatch in subvector_from"); + copyonwrite(); + + for(int i=0; i=rhs.nn) laerror("bad row index in subvector"); +#endif + (*this)[i] = rhs[ii]; + } +} + + /***************************************************************************//** * places given vector as subvector at given position * @param[in] from coordinate @@ -2321,11 +2342,34 @@ void NRVec::storesubvector(const NRVec &selection, const NRVec &rhs) for(int i=0; i=nn) laerror("bad index in storesubvector"); +#endif (*this)[ii] = rhs[i]; } } +template +void NRVec::storesubvector_to(const NRVec &selection, NRVec &rhs) const +{ + NOT_GPU(*this); + const int n = selection.size(); + if(n!=size()) laerror("size mismatch in storesubvector"); + rhs.copyonwrite(); + + for(int i=0; i=rhs.nn) laerror("bad index in storesubvector"); +#endif + rhs[ii] = (*this)[i]; + } +} + + + + }//namespace