implementation of NRVec::permuted moved to permutation.h

This commit is contained in:
Jiri Pittner 2022-10-28 19:59:33 +02:00
parent 496f004b5b
commit 4e2ee8a14e
2 changed files with 26 additions and 25 deletions

View File

@ -240,5 +240,31 @@ template <typename T>
extern std::ostream & operator<<(std::ostream &s, const Sn_characters<T> &c); extern std::ostream & operator<<(std::ostream &s, const Sn_characters<T> &c);
template<typename T>
const NRVec<T> NRVec<T>::permuted(const NRPerm<int> &p, const bool inverse) 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);
if(inverse) for(int i=1; i<=n; ++i) r[i-1] = v[p[i]-1];
else for(int i=1; i<=n; ++i) r[p[i]-1] = v[i-1];
return r;
}
template<typename T>
void NRVec<T>::permuteme(const NRPerm<int> &p, bool inverse)
{
NRVec<T> tmp=permuted(p,inverse);
for(int i=0; i<size(); ++i) v[i] = tmp.v[i];
}
}//namespace }//namespace
#endif #endif

25
vec.cc
View File

@ -823,31 +823,6 @@ NRVec<std::complex<double> > complexify(const NRVec<double> &rhs) {
#endif #endif
return r; return r;
} }
template<typename T>
const NRVec<T> NRVec<T>::permuted(const NRPerm<int> &p, const bool inverse) 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);
if(inverse) for(int i=1; i<=n; ++i) r[i-1] = v[p[i]-1];
else for(int i=1; i<=n; ++i) r[p[i]-1] = v[i-1];
return r;
}
template<typename T>
void NRVec<T>::permuteme(const NRPerm<int> &p, bool inverse)
{
NRVec<T> tmp=permuted(p,inverse);
for(int i=0; i<size(); ++i) v[i] = tmp.v[i];
}
template<typename T> template<typename T>
void NRVec<T>::permuteme(const CyclePerm<int> &p) void NRVec<T>::permuteme(const CyclePerm<int> &p)
{ {