progressing implementation of permutations

This commit is contained in:
2021-05-13 16:45:10 +02:00
parent 01665674c5
commit 60e8a379f5
9 changed files with 201 additions and 6 deletions

16
vec.cc
View File

@@ -833,6 +833,22 @@ NRVec<std::complex<double> > complexify(const NRVec<double> &rhs) {
return r;
}
template<typename T>
const NRVec<T> NRVec<T>::permute(const NRPerm<int> &p) const
{
#ifdef DEBUG
if(!p.is_valid()) laerror("invalid permutation of vector");
#endif
int n=p.size();
if(n!=(*this).size()) laerror("incompatible permutation and vector");
#ifdef CUDALA
if(this->getlocation() != cpu || p.getlocation() != cpu ) laerror("permutations can be done only in CPU memory");
#endif
NRVec<T> r(n);
for(int i=1; i<=n; ++i) r[i-1] = v[p[i]-1];
return r;
}
/***************************************************************************//**
* forced instantization in the corespoding object file
******************************************************************************/