vec: subvector_from and _to
This commit is contained in:
1 parent
2e6ce0c13e
commit
9ff29754fd
1 file changed
+44
@@ -201,10 +201,12 @@ public:
|
|||||||
//! extract specified subvector
|
//! extract specified subvector
|
||||||
const NRVec subvector(const int from, const int to) const;
|
const NRVec subvector(const int from, const int to) const;
|
||||||
const NRVec subvector(const NRVec<int> &selection) const;
|
const NRVec subvector(const NRVec<int> &selection) const;
|
||||||
|
void subvector_from(const NRVec<int> &selection, const NRVec<T> &rhs); //gather from rhs
|
||||||
|
|
||||||
//! store given vector at given position into the current vector (scatter)
|
//! store given vector at given position into the current vector (scatter)
|
||||||
void storesubvector(const int from, const NRVec &rhs);
|
void storesubvector(const int from, const NRVec &rhs);
|
||||||
void storesubvector(const NRVec<int> &selection, const NRVec &rhs);
|
void storesubvector(const NRVec<int> &selection, const NRVec &rhs);
|
||||||
|
void storesubvector_to(const NRVec<int> &selection, NRVec &rhs) const; //scatter to rhs
|
||||||
|
|
||||||
//! relational operators
|
//! relational operators
|
||||||
const bool operator!=(const NRVec &rhs) const
|
const bool operator!=(const NRVec &rhs) const
|
||||||
@@ -2280,6 +2282,25 @@ return r;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void NRVec<T>::subvector_from(const NRVec<int> &selection, const NRVec<T> &rhs)
|
||||||
|
{
|
||||||
|
NOT_GPU(*this);
|
||||||
|
const int n = selection.size();
|
||||||
|
if(n!=size()) laerror("size mismatch in subvector_from");
|
||||||
|
copyonwrite();
|
||||||
|
|
||||||
|
for(int i=0; i<n; ++i)
|
||||||
|
{
|
||||||
|
int ii=selection[i];
|
||||||
|
#ifdef DEBUG
|
||||||
|
if(ii<0||ii>=rhs.nn) laerror("bad row index in subvector");
|
||||||
|
#endif
|
||||||
|
(*this)[i] = rhs[ii];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************//**
|
/***************************************************************************//**
|
||||||
* places given vector as subvector at given position
|
* places given vector as subvector at given position
|
||||||
* @param[in] from coordinate
|
* @param[in] from coordinate
|
||||||
@@ -2321,11 +2342,34 @@ void NRVec<T>::storesubvector(const NRVec<int> &selection, const NRVec &rhs)
|
|||||||
for(int i=0; i<n; ++i)
|
for(int i=0; i<n; ++i)
|
||||||
{
|
{
|
||||||
int ii=selection[i];
|
int ii=selection[i];
|
||||||
|
#ifdef DEBUG
|
||||||
if(ii<0||ii>=nn) laerror("bad index in storesubvector");
|
if(ii<0||ii>=nn) laerror("bad index in storesubvector");
|
||||||
|
#endif
|
||||||
(*this)[ii] = rhs[i];
|
(*this)[ii] = rhs[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void NRVec<T>::storesubvector_to(const NRVec<int> &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<n; ++i)
|
||||||
|
{
|
||||||
|
int ii=selection[i];
|
||||||
|
#ifdef DEBUG
|
||||||
|
if(ii<0||ii>=rhs.nn) laerror("bad index in storesubvector");
|
||||||
|
#endif
|
||||||
|
rhs[ii] = (*this)[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|||||||
Reference in new issue
Block a user