NRVec sorting moved to .h to be available for newly derived non-plain data types

This commit is contained in:
Jiri Pittner 2022-06-09 21:36:42 +02:00
parent 3a163ae81f
commit 23d70d3808
3 changed files with 22 additions and 20 deletions

View File

@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "vec.h"
#include "permutation.h" #include "permutation.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

20
vec.cc
View File

@ -26,7 +26,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include "vec.h" #include "vec.h"
#include "qsort.h"
#include <unistd.h> #include <unistd.h>
@ -807,25 +806,6 @@ NRVec<std::complex<double> >::otimes(const NRVec<std::complex<double> > &b, cons
return result; return result;
} }
template<typename T>
int NRVec<T>::sort(int direction, int from, int to, int *perm) {
NOT_GPU(*this);
copyonwrite();
if(to == -1) to = nn - 1;
if(direction) return memqsort<1, NRVec<T>, int, int>(*this, perm, from, to);
else return memqsort<0, NRVec<T>, int, int>(*this, perm, from, to);
}
template<typename T>
int NRVec<T>::sort(int direction, NRPerm<int> &perm)
{
if(nn!=perm.size()) laerror("incompatible vector and permutation");
perm.identity();
int r=sort(direction,0,nn-1,&perm[1]);
return r;
}
template<> template<>
NRVec<std::complex<double> > complexify(const NRVec<double> &rhs) { NRVec<std::complex<double> > complexify(const NRVec<double> &rhs) {
NRVec<std::complex<double> > r(rhs.size(), rhs.getlocation()); NRVec<std::complex<double> > r(rhs.size(), rhs.getlocation());

21
vec.h
View File

@ -476,6 +476,7 @@ public:
#include "smat.h" #include "smat.h"
#include "sparsemat.h" #include "sparsemat.h"
#include "sparsesmat.h" #include "sparsesmat.h"
#include "qsort.h"
@ -485,6 +486,26 @@ public:
namespace LA { namespace LA {
template<typename T>
int NRVec<T>::sort(int direction, int from, int to, int *perm) {
NOT_GPU(*this);
copyonwrite();
if(to == -1) to = nn - 1;
if(direction) return memqsort<1, NRVec<T>, int, int>(*this, perm, from, to);
else return memqsort<0, NRVec<T>, int, int>(*this, perm, from, to);
}
template<typename T>
int NRVec<T>::sort(int direction, NRPerm<int> &perm)
{
if(nn!=perm.size()) laerror("incompatible vector and permutation");
perm.identity();
int r=sort(direction,0,nn-1,&perm[1]);
return r;
}
/***************************************************************************//** /***************************************************************************//**
* indexing operator giving the element at given position with range checking in * indexing operator giving the element at given position with range checking in
* the DEBUG mode * the DEBUG mode