implemented subvector/submatrix with individual index selection

This commit is contained in:
2023-07-26 21:18:57 +02:00
parent 85a514a50e
commit 51a26337c6
6 changed files with 204 additions and 0 deletions

34
vec.cc
View File

@@ -837,6 +837,24 @@ const NRVec<T> NRVec<T>::subvector(const int from, const int to) const
return r;
}
template <typename T>
const NRVec<T> NRVec<T>::subvector(const NRVec<int> &selection) const
{
NOT_GPU(*this);
const int n = selection.size();
NRVec<T> r(n);
for(int i=0; i<n; ++i)
{
int ii=selection[i];
if(ii<0||ii>=nn) laerror("bad row index in subvector");
r[i] = (*this)[ii];
}
return r;
}
/***************************************************************************//**
* places given vector as subvector at given position
* @param[in] from coordinate
@@ -866,6 +884,22 @@ void NRVec<T>::storesubvector(const int from, const NRVec &rhs)
}
template <typename T>
void NRVec<T>::storesubvector(const NRVec<int> &selection, const NRVec &rhs)
{
NOT_GPU(*this);
const int n = selection.size();
if(n!=rhs.size()) laerror("size mismatch in storesubvector");
for(int i=0; i<n; ++i)
{
int ii=selection[i];
if(ii<0||ii>=nn) laerror("bad index in storesubvector");
(*this)[ii] = rhs[i];
}
}
/***************************************************************************//**
* forced instantization in the corespoding object file
******************************************************************************/