*** empty log message ***

This commit is contained in:
jiri 2021-04-21 13:04:37 +00:00
parent 853008caf1
commit e4937a41f0
18 changed files with 350 additions and 285 deletions

View File

@ -17,6 +17,7 @@
*/
#include "bitvector.h"
#include <unistd.h>
namespace LA {
@ -187,5 +188,26 @@ if(modulo)
return s+word_popul(a);
}
void bitvector::read(int fd, bool dimensions, bool transp)
{
if(dimensions)
{
int r = ::read(fd,&modulo,sizeof(modulo));
if(r!=sizeof(modulo)) laerror("cannot read in bitvector");
}
NRVec<bitvector_block>::get(fd,dimensions,transp);
}
void bitvector::write(int fd, bool dimensions, bool transp)
{
if(dimensions)
{
int r = ::write(fd,&modulo,sizeof(modulo));
if(r!=sizeof(modulo)) laerror("cannot write in bitvector");
}
NRVec<bitvector_block>::put(fd,dimensions,transp);
}
}//namespace

View File

@ -75,6 +75,9 @@ public:
//extended, truncated const i.e. not on *this but return new entity, take care of modulo's bits
//logical shifts <<= >>= << >> not implemented yet
//logical rotations not implemented yet
//unformatted file IO
void read(int fd, bool dimensions=1, bool transp=0);
void write(int fd, bool dimensions=1, bool transp=0);
};
extern std::ostream & operator<<(std::ostream &s, const bitvector &x);

View File

@ -48,7 +48,7 @@ template void CSRMat<T>::put(int fd, bool dimen, bool transp) const; \
INSTANTIZE(double)
INSTANTIZE(complex<double>)
INSTANTIZE(std::complex<double>)
*/
//// forced instantization of functions in the header in the corresponding object file

4
la.h
View File

@ -48,9 +48,9 @@
using namespace LA;
typedef NRMat<int> NRIMat;
typedef NRMat<double> NRDMat;
typedef NRMat<complex<double> > NRCMat;
typedef NRMat<std::complex<double> > NRCMat;
typedef NRVec<int> NRIVec;
typedef NRVec<double> NRDVec;
typedef NRVec<complex<double> > NRCVec;
typedef NRVec<std::complex<double> > NRCVec;
#endif /* _LA_H_ */

View File

@ -39,7 +39,6 @@
//using namespace std;
#define complex std::complex
#include "laerror.h"
@ -79,6 +78,18 @@ template<typename C> class SparseMat;
template<typename C> class SparseSMat;
template<typename C> class CSRMat;
//trick to allow real and imag part of complex as l-values
template<typename T>
T &real(std::complex<T> &c) {
return reinterpret_cast<T*>(&c)[0];
}
template<typename T>
T &imag(std::complex<T> &c) {
return reinterpret_cast<T*>(&c)[1];
}
//
typedef class {} Dummy_type;
typedef class {} Dummy_type2;
@ -96,7 +107,7 @@ struct LA_traits_complex
#define SPECIALIZE_COMPLEX(T) \
template<> \
struct LA_traits_complex<complex<T> > \
struct LA_traits_complex<std::complex<T> > \
{ \
typedef T Component_type; \
typedef NRVec<T> NRVec_Noncomplex_type; \
@ -106,9 +117,9 @@ struct LA_traits_complex<complex<T> > \
SPECIALIZE_COMPLEX(double)
SPECIALIZE_COMPLEX(complex<double>)
SPECIALIZE_COMPLEX(std::complex<double>)
SPECIALIZE_COMPLEX(float)
SPECIALIZE_COMPLEX(complex<float>)
SPECIALIZE_COMPLEX(std::complex<float>)
SPECIALIZE_COMPLEX(char)
SPECIALIZE_COMPLEX(unsigned char)
SPECIALIZE_COMPLEX(short)
@ -172,9 +183,9 @@ class isscalar { public: typedef scalar_false scalar_type;};
template<>\
class isscalar<X> {public: typedef scalar_true scalar_type;};\
template<>\
class isscalar<complex<X> > {public: typedef scalar_true scalar_type;};\
class isscalar<std::complex<X> > {public: typedef scalar_true scalar_type;};\
template<>\
class isscalar<complex<complex<X> > > {public: typedef scalar_true scalar_type;};\
class isscalar<std::complex<std::complex<X> > > {public: typedef scalar_true scalar_type;};\
//declare what is scalar
@ -211,56 +222,56 @@ template<typename C, typename Scalar> struct LA_traits_aux
//complex scalars
template<typename C>
struct LA_traits_aux<complex<C>, scalar_true> {
typedef complex<C> elementtype;
typedef complex<C> producttype;
struct LA_traits_aux<std::complex<C>, scalar_true> {
typedef std::complex<C> elementtype;
typedef std::complex<C> producttype;
typedef C normtype;
typedef C realtype;
typedef complex<C> complextype;
static inline C sqrabs(const complex<C> x) { return x.real()*x.real()+x.imag()*x.imag();}
static inline bool gencmp(const complex<C> *x, const complex<C> *y, size_t n) {return memcmp(x,y,n*sizeof(complex<C>));}
static bool bigger(const complex<C> &x, const complex<C> &y) {laerror("complex comparison undefined"); return false;}
static bool smaller(const complex<C> &x, const complex<C> &y) {laerror("complex comparison undefined"); return false;}
static inline normtype norm (const complex<C> &x) {return std::abs(x);}
static inline void axpy (complex<C> &s, const complex<C> &x, const complex<C> &c) {s+=x*c;}
static inline void get(int fd, complex<C> &x, bool dimensions=0, bool transp=0) {if(sizeof(complex<C>)!=read(fd,&x,sizeof(complex<C>))) laerror("read error");}
static inline void put(int fd, const complex<C> &x, bool dimensions=0, bool transp=0) {if(sizeof(complex<C>)!=write(fd,&x,sizeof(complex<C>))) laerror("write error");}
static void multiget(size_t n,int fd, complex<C> *x, bool dimensions=0)
typedef std::complex<C> complextype;
static inline C sqrabs(const std::complex<C> x) { return x.real()*x.real()+x.imag()*x.imag();}
static inline bool gencmp(const std::complex<C> *x, const std::complex<C> *y, size_t n) {return memcmp(x,y,n*sizeof(std::complex<C>));}
static bool bigger(const std::complex<C> &x, const std::complex<C> &y) {laerror("std::complex comparison undefined"); return false;}
static bool smaller(const std::complex<C> &x, const std::complex<C> &y) {laerror("std::complex comparison undefined"); return false;}
static inline normtype norm (const std::complex<C> &x) {return std::abs(x);}
static inline void axpy (std::complex<C> &s, const std::complex<C> &x, const std::complex<C> &c) {s+=x*c;}
static inline void get(int fd, std::complex<C> &x, bool dimensions=0, bool transp=0) {if(sizeof(std::complex<C>)!=read(fd,&x,sizeof(std::complex<C>))) laerror("read error");}
static inline void put(int fd, const std::complex<C> &x, bool dimensions=0, bool transp=0) {if(sizeof(std::complex<C>)!=write(fd,&x,sizeof(std::complex<C>))) laerror("write error");}
static void multiget(size_t n,int fd, std::complex<C> *x, bool dimensions=0)
{
size_t total=0;
size_t system_limit = (1L<<30)/sizeof(complex<C>); //do not expect too much from the system and read at most 1GB at once
size_t system_limit = (1L<<30)/sizeof(std::complex<C>); //do not expect too much from the system and read at most 1GB at once
ssize_t r;
size_t nn;
do{
r=read(fd,x+total,nn=(n-total > system_limit ? system_limit : n-total)*sizeof(complex<C>));
r=read(fd,x+total,nn=(n-total > system_limit ? system_limit : n-total)*sizeof(std::complex<C>));
if(r<0 || r==0 && nn!=0 ) {std::cout<<"read returned "<<r<<" perror "<<strerror(errno) <<std::endl; laerror("read error");}
else total += r/sizeof(complex<C>);
if(r%sizeof(complex<C>)) laerror("read error 2");
else total += r/sizeof(std::complex<C>);
if(r%sizeof(std::complex<C>)) laerror("read error 2");
}
while(total < n);
}
static void multiput(size_t n, int fd, const complex<C> *x, bool dimensions=0)
static void multiput(size_t n, int fd, const std::complex<C> *x, bool dimensions=0)
{
size_t total=0;
size_t system_limit = (1L<<30)/sizeof(complex<C>); //do not expect too much from the system and write at most 1GB at once
size_t system_limit = (1L<<30)/sizeof(std::complex<C>); //do not expect too much from the system and write at most 1GB at once
ssize_t r;
size_t nn;
do{
r=write(fd,x+total,nn=(n-total > system_limit ? system_limit : n-total)*sizeof(complex<C>));
r=write(fd,x+total,nn=(n-total > system_limit ? system_limit : n-total)*sizeof(std::complex<C>));
if(r<0 || r==0 && nn!=0 ) {std::cout<<"write returned "<<r<<" perror "<<strerror(errno) <<std::endl; laerror("write error");}
else total += r/sizeof(complex<C>);
if(r%sizeof(complex<C>)) laerror("write error 2");
else total += r/sizeof(std::complex<C>);
if(r%sizeof(std::complex<C>)) laerror("write error 2");
}
while(total < n);
}
static void copy(complex<C> *dest, complex<C> *src, size_t n) {memcpy(dest,src,n*sizeof(complex<C>));}
static void clear(complex<C> *dest, size_t n) {memset(dest,0,n*sizeof(complex<C>));}
static void copyonwrite(complex<C> &x) {};
static void clearme(complex<C> &x) {x=0;};
static void deallocate(complex<C> &x) {};
static inline complex<C> conjugate(const complex<C> &x) {return complex<C>(x.real(),-x.imag());};
static inline C realpart(const complex<C> &x) {return x.real();}
static inline C imagpart(const complex<C> &x) {return x.imag();}
static void copy(std::complex<C> *dest, std::complex<C> *src, size_t n) {memcpy(dest,src,n*sizeof(std::complex<C>));}
static void clear(std::complex<C> *dest, size_t n) {memset(dest,0,n*sizeof(std::complex<C>));}
static void copyonwrite(std::complex<C> &x) {};
static void clearme(std::complex<C> &x) {x=0;};
static void deallocate(std::complex<C> &x) {};
static inline std::complex<C> conjugate(const std::complex<C> &x) {return std::complex<C>(x.real(),-x.imag());};
static inline C realpart(const std::complex<C> &x) {return x.real();}
static inline C imagpart(const std::complex<C> &x) {return x.imag();}
};
@ -271,7 +282,7 @@ typedef C elementtype;
typedef C producttype;
typedef C normtype;
typedef C realtype;
typedef complex<C> complextype;
typedef std::complex<C> complextype;
static inline C sqrabs(const C x) { return x*x;}
static inline bool gencmp(const C *x, const C *y, size_t n) {return memcmp(x,y,n*sizeof(C));}
static inline bool bigger(const C &x, const C &y) {return x>y;}

184
mat.cc
View File

@ -276,7 +276,7 @@ NRMat<double>& NRMat<double>::operator=(const double &a){
* @return reference to the modified matrix
******************************************************************************/
template <>
NRMat<complex<double> >& NRMat<complex<double> >::operator=(const complex<double> &a){
NRMat<std::complex<double> >& NRMat<std::complex<double> >::operator=(const std::complex<double> &a){
const int n2 = nn*nn;
copyonwrite();
#ifdef DEBUG
@ -286,7 +286,7 @@ NRMat<complex<double> >& NRMat<complex<double> >::operator=(const complex<double
if(location == cpu){
#endif
#ifdef MATPTR
memset(v[0], 0, n2*sizeof(complex<double>));
memset(v[0], 0, n2*sizeof(std::complex<double>));
for(register int i=0; i< nn; i++) v[i][i] = a;
#else
//set all matrix elements equal to zero
@ -340,7 +340,7 @@ NRMat<double> & NRMat<double>::operator+=(const double& a) {
* @return reference to the modified matrix
******************************************************************************/
template <>
NRMat<complex<double> > & NRMat<complex<double> >::operator+=(const complex<double>& a) {
NRMat<std::complex<double> > & NRMat<std::complex<double> >::operator+=(const std::complex<double>& a) {
copyonwrite();
#ifdef DEBUG
if(nn != mm) laerror("nonsquare matrix");
@ -355,7 +355,7 @@ NRMat<complex<double> > & NRMat<complex<double> >::operator+=(const complex<doub
#endif
#ifdef CUDALA
}else{
complex<double>* d = gpuputcomplex(a);
std::complex<double>* d = gpuputcomplex(a);
cublasZaxpy(nn, CUMONE, (cuDoubleComplex*)d, 0, (cuDoubleComplex*)v, nn+1);
TEST_CUBLAS("cublasDaxpy");
gpufree(d);
@ -402,7 +402,7 @@ NRMat<double>& NRMat<double>::operator-=(const double& a) {
* @return reference to the modified matrix
******************************************************************************/
template <>
NRMat<complex<double> >& NRMat<complex<double> >::operator-=(const complex<double>& a) {
NRMat<std::complex<double> >& NRMat<std::complex<double> >::operator-=(const std::complex<double>& a) {
copyonwrite();
#ifdef DEBUG
if(nn != mm) laerror("nonsquare matrix");
@ -417,7 +417,7 @@ NRMat<complex<double> >& NRMat<complex<double> >::operator-=(const complex<doubl
#endif
#ifdef CUDALA
}else{
complex<double>* d = gpuputcomplex(a);
std::complex<double>* d = gpuputcomplex(a);
cublasZaxpy(nn, CUMONE, (cuDoubleComplex*)d, 0, (cuDoubleComplex*)v, nn+1);
TEST_CUBLAS("cublasDaxpy");
gpufree(d);
@ -502,16 +502,16 @@ const NRMat<double> NRMat<double>::operator-() const {
* @return modified copy of this matrix
******************************************************************************/
template <>
const NRMat<complex<double> > NRMat<complex<double> >::operator-() const {
const NRMat<std::complex<double> > NRMat<std::complex<double> >::operator-() const {
const size_t nm = (size_t)nn*mm;
NRMat<complex<double> > result(nn, mm, getlocation());
NRMat<std::complex<double> > result(nn, mm, getlocation());
#ifdef CUDALA
if(location == cpu) {
#endif
#ifdef MATPTR
for(register size_t i=0; i<nm; i++) result.v[0][i]= -v[0][i];
#else
memcpy(result.v, v, nm*sizeof(complex<double>));
memcpy(result.v, v, nm*sizeof(std::complex<double>));
cblas_zscal(nm, &CMONE, result.v, 1);
#endif
#ifdef CUDALA
@ -631,8 +631,8 @@ const NRVec<double> NRMat<double>::csum() const {
* @return summed columns in a form of a vector
******************************************************************************/
template <>
const NRVec<complex<double> > NRMat<complex<double> >::csum() const {
NRVec<complex<double> > result(nn, getlocation());
const NRVec<std::complex<double> > NRMat<std::complex<double> >::csum() const {
NRVec<std::complex<double> > result(nn, getlocation());
result = 0.0;
#ifdef CUDALA
if(location == cpu){
@ -699,8 +699,8 @@ const NRVec<double> NRMat<double>::rsum() const {
* @return summed rows in a form of a vector
******************************************************************************/
template <>
const NRVec<complex<double> > NRMat<complex<double> >::rsum() const {
NRVec<complex<double> > result(mm, getlocation());
const NRVec<std::complex<double> > NRMat<std::complex<double> >::rsum() const {
NRVec<std::complex<double> > result(mm, getlocation());
result = 0.0;
#ifdef CUDALA
if(location == cpu){
@ -873,24 +873,24 @@ laerror("nonsymmetry not implemented on GPU yet");
* compute matrix non-hermiticity
******************************************************************************/
template <>
const double NRMat<complex<double> >::nonhermiticity() const {
const double NRMat<std::complex<double> >::nonhermiticity() const {
#ifdef DEBUG
if (nn != mm) laerror("NRMat<T>:nonsymmetry() invalid for non-square matrix");
#endif
double sum = 0;
complex<double> tmp;
std::complex<double> tmp;
#ifdef CUDALA
if(location == cpu){
#endif
for(register int i=1; i<nn; i++){
for(register int j=0; j<=i; j++){
#ifdef MATPTR
tmp = complex<double> (v[i][j].real()-v[j][i].real(),v[i][j].imag()+v[j][i].imag());
tmp = std::complex<double> (v[i][j].real()-v[j][i].real(),v[i][j].imag()+v[j][i].imag());
#else
register int a, b;
a = i*(size_t)mm + j;
b = j*(size_t)mm + i;
tmp = complex<double> (v[a].real() - v[b].real(), v[a].imag()+v[b].imag());
tmp = std::complex<double> (v[a].real() - v[b].real(), v[a].imag()+v[b].imag());
#endif
sum += tmp.real()*tmp.real()+tmp.imag()*tmp.imag();
}
@ -905,12 +905,12 @@ laerror("nonsymmetry not implemented on GPU yet");
}
template <>
const double NRMat<complex<double> >::nonsymmetry() const {
const double NRMat<std::complex<double> >::nonsymmetry() const {
#ifdef DEBUG
if (nn != mm) laerror("NRMat<T>:nonsymmetry() invalid for non-square matrix");
#endif
double sum = 0;
complex<double> tmp;
std::complex<double> tmp;
#ifdef CUDALA
if(location == cpu){
#endif
@ -945,28 +945,28 @@ laerror("nonsymmetry not implemented on GPU yet");
* or imaginary part of the complex matrix being created
******************************************************************************/
template<>
NRMat<complex<double> >::NRMat(const NRMat<double> &rhs, bool imagpart): nn(rhs.nrows()), mm(rhs.ncols()), count(new int(1)) {
NRMat<std::complex<double> >::NRMat(const NRMat<double> &rhs, bool imagpart): nn(rhs.nrows()), mm(rhs.ncols()), count(new int(1)) {
const size_t nn_mm = (size_t)nn*mm;
#ifdef CUDALA
if(location == cpu){
#endif
#ifdef MATPTR
v = new complex<double>*[n];
v[0] = new complex<double>[nn_mm];
v = new std::complex<double>*[n];
v[0] = new std::complex<double>[nn_mm];
for(register int i=1; i<n; i++) v[i] = v[i-1] + m;
memset(v[0], 0, nn_mm*sizeof(complex<double>));
memset(v[0], 0, nn_mm*sizeof(std::complex<double>));
cblas_dcopy(nn_mm, &rhs[0][0], 1, ((double *)v[0]) + (imagpart?1:0), 2);
#else
v = new complex<double>[nn_mm];
memset(v, 0, nn_mm*sizeof(complex<double>));
v = new std::complex<double>[nn_mm];
memset(v, 0, nn_mm*sizeof(std::complex<double>));
cblas_dcopy(nn_mm, &rhs[0][0], 1, ((double *)v) + (imagpart?1:0), 2);
#endif
#ifdef CUDALA
}else{
v = (complex<double>*)gpualloc(sizeof(complex<double>)*nn_mm);
complex<double> *_val = gpuputcomplex(CZERO);
v = (std::complex<double>*)gpualloc(sizeof(std::complex<double>)*nn_mm);
std::complex<double> *_val = gpuputcomplex(CZERO);
cublasZcopy(nn_mm, (cuDoubleComplex*)_val, 0, (cuDoubleComplex*)v, 1);
TEST_CUBLAS("cublasZcopy");
gpufree(_val);
@ -986,7 +986,7 @@ NRMat<complex<double> >::NRMat(const NRMat<double> &rhs, bool imagpart): nn(rhs.
* or imaginary part of the input complex matrix
******************************************************************************/
template<>
NRMat<double>::NRMat(const NRMat<complex<double> > &rhs, bool imagpart): nn(rhs.nrows()), mm(rhs.ncols()), count(new int(1)) {
NRMat<double>::NRMat(const NRMat<std::complex<double> > &rhs, bool imagpart): nn(rhs.nrows()), mm(rhs.ncols()), count(new int(1)) {
const size_t nn_mm = (size_t) nn*mm;
#ifdef CUDALA
if(location == cpu){
@ -1109,9 +1109,9 @@ const NRSMat<double> NRMat<double>::transposedtimes() const {
* @return complex NRSMat object because of the hermiticity of \f$A^\dagger{}A\f$
******************************************************************************/
template<>
const NRSMat<complex<double> > NRMat<complex<double> >::transposedtimes() const {
const NRSMat<std::complex<double> > NRMat<std::complex<double> >::transposedtimes() const {
int i(0), j(0);
NRSMat<complex<double> > r(mm, getlocation());
NRSMat<std::complex<double> > r(mm, getlocation());
#ifdef CUDALA
if(location == cpu){
#endif
@ -1130,7 +1130,7 @@ const NRSMat<complex<double> > NRMat<complex<double> >::transposedtimes() const
for(j=0; j<=i; ++j){
cuDoubleComplex val = cublasZdotc(nn, (const cuDoubleComplex*)(v + i), mm, (const cuDoubleComplex*)(v + j), mm);
TEST_CUBLAS("cublasZdotc");
r(i, j) = *(reinterpret_cast<complex<double>*> (&val));
r(i, j) = *(reinterpret_cast<std::complex<double>*> (&val));
}
}
r.moveto(this->location);
@ -1201,9 +1201,9 @@ const NRSMat<double> NRMat<double>::timestransposed() const {
* @return complex NRSMat object because of the hermiticity of \f$AA^\dagger{}\f$
******************************************************************************/
template<>
const NRSMat<complex<double> > NRMat<complex<double> >::timestransposed() const {
const NRSMat<std::complex<double> > NRMat<std::complex<double> >::timestransposed() const {
int i(0), j(0);
NRSMat<complex<double> > r(nn, getlocation());
NRSMat<std::complex<double> > r(nn, getlocation());
#ifdef CUDALA
if(location == cpu){
#endif
@ -1222,7 +1222,7 @@ const NRSMat<complex<double> > NRMat<complex<double> >::timestransposed() const
for(j=0; j<=i; ++j){
cuDoubleComplex val = cublasZdotc(nn, (const cuDoubleComplex *)(v + i*(size_t)mm), 1, (const cuDoubleComplex *)(v + j*(size_t)mm), 1);
TEST_CUBLAS("cublasZdotc");
r(i, j) = *(reinterpret_cast<complex<double>*> (&val));
r(i, j) = *(reinterpret_cast<std::complex<double>*> (&val));
}
}
r.moveto(this->location);
@ -1287,7 +1287,7 @@ void NRMat<double>::randomize(const double &x) {
* @param[in] x generate random numbers from the interval [0, x]
******************************************************************************/
template<>
void NRMat<complex<double> >::randomize(const double &x) {
void NRMat<std::complex<double> >::randomize(const double &x) {
#ifdef CUDALA
if(location == cpu){
#endif
@ -1295,17 +1295,17 @@ void NRMat<complex<double> >::randomize(const double &x) {
for(register int j=0; j<mm; ++j){
const double re = x*(2.*random()/(1. + RAND_MAX) - 1.);
const double im = x*(2.*random()/(1. + RAND_MAX) - 1.);
(*this)(i,j) = complex<double>(re, im);
(*this)(i,j) = std::complex<double>(re, im);
}
}
#ifdef CUDALA
}else{
NRMat<complex<double> > tmp(nn, mm, cpu);
complex<double> *tmp_data = tmp;
NRMat<std::complex<double> > tmp(nn, mm, cpu);
std::complex<double> *tmp_data = tmp;
for(register size_t i=0; i<(size_t)nn*mm; ++i){
const double re = x*(2.*random()/(1. + RAND_MAX) - 1.);
const double im = x*(2.*random()/(1. + RAND_MAX) - 1.);
tmp_data[i] = complex<double>(re, im);
tmp_data[i] = std::complex<double>(re, im);
}
tmp.moveto(this->location);
*this |= tmp;
@ -1342,8 +1342,8 @@ NRMat<double>& NRMat<double>::operator*=(const double &a) {
* @return reference to the modified matrix
******************************************************************************/
template<>
NRMat<complex<double> > &
NRMat<complex<double> >::operator*=(const complex<double> &a) {
NRMat<std::complex<double> > &
NRMat<std::complex<double> >::operator*=(const std::complex<double> &a) {
copyonwrite();
#ifdef CUDALA
if(location == cpu){
@ -1409,8 +1409,8 @@ NRMat<double> & NRMat<double>::operator+=(const NRMat<double> &rhs) {
* @return reference to the modified matrix
******************************************************************************/
template<>
NRMat<complex<double> > &
NRMat<complex<double> >::operator+=(const NRMat< complex<double> > &rhs) {
NRMat<std::complex<double> > &
NRMat<std::complex<double> >::operator+=(const NRMat< std::complex<double> > &rhs) {
#ifdef DEBUG
if (nn != rhs.nn || mm != rhs.mm) laerror("incompatible matrices");
#endif
@ -1483,8 +1483,8 @@ NRMat<double> & NRMat<double>::operator-=(const NRMat<double> &rhs) {
* @return reference to the modified matrix
******************************************************************************/
template<>
NRMat< complex<double> > &
NRMat< complex<double> >::operator-=(const NRMat< complex<double> > &rhs) {
NRMat< std::complex<double> > &
NRMat< std::complex<double> >::operator-=(const NRMat< std::complex<double> > &rhs) {
#ifdef DEBUG
if (nn != rhs.nn || mm != rhs.mm) laerror("incompatible matrices");
#endif
@ -1584,13 +1584,13 @@ NRMat<double> & NRMat<double>::operator+=(const NRSMat<double> &rhs) {
* @see NRSMat<T>
******************************************************************************/
template<>
NRMat< complex<double> > &
NRMat< complex<double> >::operator+=(const NRSMat< complex<double> > &rhs)
NRMat< std::complex<double> > &
NRMat< std::complex<double> >::operator+=(const NRSMat< std::complex<double> > &rhs)
{
#ifdef DEBUG
if (nn != rhs.nn || mm != rhs.nn) laerror("incompatible matrices");
#endif
const complex<double> *p = rhs;
const std::complex<double> *p = rhs;
SAME_LOC(*this, rhs);
copyonwrite();
@ -1709,12 +1709,12 @@ NRMat<double> & NRMat<double>::operator-=(const NRSMat<double> &rhs)
* @see NRSMat<T>
******************************************************************************/
template<>
NRMat<complex<double> > &
NRMat<complex<double> >::operator-=(const NRSMat<complex<double> > &rhs) {
NRMat<std::complex<double> > &
NRMat<std::complex<double> >::operator-=(const NRSMat<std::complex<double> > &rhs) {
#ifdef DEBUG
if (nn != rhs.nn || mm != rhs.nn) laerror("incompatible matrices");
#endif
const complex<double> *p = rhs;
const std::complex<double> *p = rhs;
SAME_LOC(*this, rhs);
copyonwrite();
@ -1810,13 +1810,13 @@ const double NRMat<double>::dot(const NRMat<double> &rhs) const {
* @return computed scalar product
******************************************************************************/
template<>
const complex<double>
NRMat<complex<double> >::dot(const NRMat<complex<double> > &rhs) const {
const std::complex<double>
NRMat<std::complex<double> >::dot(const NRMat<std::complex<double> > &rhs) const {
#ifdef DEBUG
if(nn != rhs.nn || mm != rhs.mm) laerror("incompatible matrices in NRMat<complex<double> >::dot(const NRMat<complex<double> >&)");
if(nn != rhs.nn || mm != rhs.mm) laerror("incompatible matrices in NRMat<std::complex<double> >::dot(const NRMat<std::complex<double> >&)");
#endif
complex<double> ret(0.0, 0.0);
std::complex<double> ret(0.0, 0.0);
#ifdef CUDALA
if(location == cpu){
#endif
@ -1824,7 +1824,7 @@ NRMat<complex<double> >::dot(const NRMat<complex<double> > &rhs) const {
#ifdef CUDALA
}else{
cuDoubleComplex val = cublasZdotc((size_t)nn*mm, (cuDoubleComplex*)v, 1, (cuDoubleComplex*)(rhs.v), 1);
ret = *(reinterpret_cast<complex<double>*> (&val));
ret = *(reinterpret_cast<std::complex<double>*> (&val));
}
#endif
return ret;
@ -1862,14 +1862,14 @@ const NRMat<double> NRMat<double>::operator*(const NRMat<double> &rhs) const {
* @return computed product by value
******************************************************************************/
template<>
const NRMat< complex<double> >
NRMat< complex<double> >::operator*(const NRMat< complex<double> > &rhs) const {
const NRMat< std::complex<double> >
NRMat< std::complex<double> >::operator*(const NRMat< std::complex<double> > &rhs) const {
#ifdef DEBUG
if(mm != rhs.nn) laerror("incompatible matrices in NRMat<complex<double> >::operator*(const NRMat<complex<double> >&)");
if(mm != rhs.nn) laerror("incompatible matrices in NRMat<std::complex<double> >::operator*(const NRMat<std::complex<double> >&)");
if(rhs.mm <= 0) laerror("illegal matrix dimension in gemm");
#endif
SAME_LOC(*this, rhs);
NRMat<complex<double> > result(nn, rhs.mm, getlocation());
NRMat<std::complex<double> > result(nn, rhs.mm, getlocation());
#ifdef CUDALA
if(location == cpu){
#endif
@ -1914,9 +1914,9 @@ void NRMat<double>::diagmultl(const NRVec<double> &rhs) {
* @param[in] rhs complex vector represeting the diagonal of matrix \f$D\f$
******************************************************************************/
template<>
void NRMat< complex<double> >::diagmultl(const NRVec< complex<double> > &rhs) {
void NRMat< std::complex<double> >::diagmultl(const NRVec< std::complex<double> > &rhs) {
#ifdef DEBUG
if (nn != rhs.size()) laerror("incompatible matrices in NRMat<complex<double> >::diagmultl(const NRVec<complex<double> >&)");
if (nn != rhs.size()) laerror("incompatible matrices in NRMat<std::complex<double> >::diagmultl(const NRVec<std::complex<double> >&)");
#endif
NOT_GPU(rhs);
copyonwrite();
@ -1965,9 +1965,9 @@ void NRMat<double>::diagmultr(const NRVec<double> &rhs) {
* @param[in] rhs complex vector represeting the diagonal of matrix \f$D\f$
******************************************************************************/
template<>
void NRMat< complex<double> >::diagmultr(const NRVec< complex<double> > &rhs) {
void NRMat< std::complex<double> >::diagmultr(const NRVec< std::complex<double> > &rhs) {
#ifdef DEBUG
if(mm != rhs.size()) laerror("incompatible matrices in NRMat<complex<double> >::diagmultr(const NRVec<complex<double> >&)");
if(mm != rhs.size()) laerror("incompatible matrices in NRMat<std::complex<double> >::diagmultr(const NRVec<std::complex<double> >&)");
#endif
NOT_GPU(rhs);
copyonwrite();
@ -2027,14 +2027,14 @@ NRMat<double>::operator*(const NRSMat<double> &rhs) const {
* @return \f$A\times\S\f$ by value
******************************************************************************/
template<>
const NRMat< complex<double> >
NRMat< complex<double> >::operator*(const NRSMat< complex<double> > &rhs) const {
const NRMat< std::complex<double> >
NRMat< std::complex<double> >::operator*(const NRSMat< std::complex<double> > &rhs) const {
#ifdef DEBUG
if(mm != rhs.nrows()) laerror("incompatible matrices int NRMat<complex<double> >::operator*(const NRSMat<complex<double> > &)");
if(mm != rhs.nrows()) laerror("incompatible matrices int NRMat<std::complex<double> >::operator*(const NRSMat<std::complex<double> > &)");
#endif
SAME_LOC(*this, rhs);
const int rhs_ncols = rhs.ncols();
NRMat<complex<double> > result(nn, rhs_ncols, getlocation());
NRMat<std::complex<double> > result(nn, rhs_ncols, getlocation());
#ifdef CUDALA
if(location == cpu){
@ -2068,7 +2068,7 @@ NRMat<double>& NRMat<double>::conjugateme() {
* @return reference to the modified matrix
******************************************************************************/
template<>
NRMat<complex<double> >& NRMat<complex<double> >::conjugateme() {
NRMat<std::complex<double> >& NRMat<std::complex<double> >::conjugateme() {
copyonwrite();
#ifdef CUDALA
if(location == cpu){
@ -2111,9 +2111,9 @@ const NRMat<double> NRMat<double>::transpose(bool conj) const {
* @return transposed (conjugated) matrix by value
******************************************************************************/
template<>
const NRMat<complex<double> >
NRMat<complex<double> >::transpose(bool conj) const {
NRMat<complex<double> > result(mm, nn, getlocation());
const NRMat<std::complex<double> >
NRMat<std::complex<double> >::transpose(bool conj) const {
NRMat<std::complex<double> > result(mm, nn, getlocation());
#ifdef CUDALA
if(location == cpu){
#endif
@ -2177,10 +2177,10 @@ void NRMat<double>::gemm(const double &beta, const NRMat<double> &a,
template<>
void NRMat<complex<double> >::gemm(const complex<double> & beta,
const NRMat<complex<double> > & a, const char transa,
const NRMat<complex<double> > & b, const char transb,
const complex<double> & alpha)
void NRMat<std::complex<double> >::gemm(const std::complex<double> & beta,
const NRMat<std::complex<double> > & a, const char transa,
const NRMat<std::complex<double> > & b, const char transb,
const std::complex<double> & alpha)
{
int k(tolower(transa)=='n'?a.mm:a.nn);
@ -2188,7 +2188,7 @@ void NRMat<complex<double> >::gemm(const complex<double> & beta,
int l(tolower(transa)=='n'?a.nn:a.mm);
int kk(tolower(transb)=='n'?b.nn:b.mm);
int ll(tolower(transb)=='n'?b.mm:b.nn);
if (l!=nn || ll!=mm || k!=kk) laerror("incompatible matrices in NRMat<complex<double> >::gemm(...)");
if (l!=nn || ll!=mm || k!=kk) laerror("incompatible matrices in NRMat<std::complex<double> >::gemm(...)");
#endif
if (alpha==CZERO && beta==CONE) return;
@ -2246,7 +2246,7 @@ const double NRMat<double>::norm(const double scalar) const {
* @return computed norm
******************************************************************************/
template<>
const double NRMat<complex<double> >::norm(const complex<double> scalar) const {
const double NRMat<std::complex<double> >::norm(const std::complex<double> scalar) const {
if(scalar == CZERO){
#ifdef CUDALA
if(location == cpu){
@ -2263,7 +2263,7 @@ const double NRMat<complex<double> >::norm(const complex<double> scalar) const {
double sum(0.0);
for(register int i=0; i<nn; i++)
for(register int j=0; j<mm; j++) {
register complex<double> tmp(0.0, 0.0);
register std::complex<double> tmp(0.0, 0.0);
#ifdef MATPTR
tmp = v[i][j];
#else
@ -2310,10 +2310,10 @@ void NRMat<double>::axpy(const double alpha, const NRMat<double> &mat) {
* @param[in] mat complex matrix \f$B\f$
******************************************************************************/
template<>
void NRMat<complex<double> >::axpy(const complex<double> alpha,
const NRMat<complex<double> > & mat) {
void NRMat<std::complex<double> >::axpy(const std::complex<double> alpha,
const NRMat<std::complex<double> > & mat) {
#ifdef DEBUG
if (nn != mat.nn || mm != mat.mm) laerror("incompatible matrices in NRMat<complex<double> >::axpy(...)");
if (nn != mat.nn || mm != mat.mm) laerror("incompatible matrices in NRMat<std::complex<double> >::axpy(...)");
#endif
SAME_LOC(*this, mat);
copyonwrite();
@ -2470,10 +2470,10 @@ int nnmin= nn<=mm?nn:mm;
* @return void
******************************************************************************/
template<>
void NRMat<complex<double> >::diagonalset(const NRVec<complex<double> > &r) {
void NRMat<std::complex<double> >::diagonalset(const NRVec<std::complex<double> > &r) {
int nnmin= nn<=mm?nn:mm;
#ifdef DEBUG
if(r.size() != nnmin) laerror("incompatible vectors int NRMat<complex<double> >::diagonalset(...)");
if(r.size() != nnmin) laerror("incompatible vectors int NRMat<std::complex<double> >::diagonalset(...)");
#endif
SAME_LOC(*this, r);
copyonwrite();
@ -2683,7 +2683,7 @@ NRMat<double>& NRMat<double>::swap_rows(const int i, const int j){
* @return reference to the modified matrix
******************************************************************************/
template<>
NRMat<complex<double> >& NRMat<complex<double> >::swap_rows(){
NRMat<std::complex<double> >& NRMat<std::complex<double> >::swap_rows(){
copyonwrite();
const int n_pul = this->nn >> 1;
@ -2705,7 +2705,7 @@ NRMat<complex<double> >& NRMat<complex<double> >::swap_rows(){
}
template<>
NRMat<complex<double> >& NRMat<complex<double> >::swap_rows(const int i, const int j){
NRMat<std::complex<double> >& NRMat<std::complex<double> >::swap_rows(const int i, const int j){
copyonwrite();
#ifdef CUDALA
@ -2802,7 +2802,7 @@ NRMat<double>& NRMat<double>::swap_cols(const int i, const int j){
* @return reference to the modified matrix
******************************************************************************/
template<>
NRMat<complex<double> >& NRMat<complex<double> >::swap_cols(){
NRMat<std::complex<double> >& NRMat<std::complex<double> >::swap_cols(){
copyonwrite();
const int m_pul = mm >> 1;
@ -2824,7 +2824,7 @@ NRMat<complex<double> >& NRMat<complex<double> >::swap_cols(){
}
template<>
NRMat<complex<double> >& NRMat<complex<double> >::swap_cols(const int i, const int j){
NRMat<std::complex<double> >& NRMat<std::complex<double> >::swap_cols(const int i, const int j){
copyonwrite();
#ifdef CUDALA
@ -2986,11 +2986,11 @@ NRMat<double>& NRMat<double>::swap_rows_cols(){
* @return reference to the modified matrix
******************************************************************************/
template<>
NRMat<complex<double> >& NRMat<complex<double> >::swap_rows_cols(){
NRMat<std::complex<double> >& NRMat<std::complex<double> >::swap_rows_cols(){
const int n_pul = nn >> 1;
const int m_pul = mm >> 1;
complex<double> tmp(0.0, 0.0);
std::complex<double> tmp(0.0, 0.0);
copyonwrite();
#ifdef CUDALA
@ -3014,7 +3014,7 @@ NRMat<complex<double> >& NRMat<complex<double> >::swap_rows_cols(){
TEST_CUBLAS("cublasZswap");
}
if(nn & 1){
void *gpu_ptr = gpualloc(sizeof(complex<double>)*mm);
void *gpu_ptr = gpualloc(sizeof(std::complex<double>)*mm);
cublasZswap(mm, (cuDoubleComplex*)(v + n_pul*mm + mm - 1), -1, (cuDoubleComplex*)gpu_ptr, 1);
cublasZcopy(mm, (cuDoubleComplex*)gpu_ptr, 1, (cuDoubleComplex*)(v + n_pul*mm), 1);
gpufree(gpu_ptr);
@ -3079,7 +3079,7 @@ NRMat<T>& NRMat<T>::swap_rows_cols(){
* forced instantization in the corresponding object file
******************************************************************************/
template class NRMat<double>;
template class NRMat<complex<double> >;
template class NRMat<std::complex<double> >;
template class NRMat<long long>;
template class NRMat<long>;
template class NRMat<int>;

27
mat.h
View File

@ -83,7 +83,7 @@ public:
//! complexifying constructor
NRMat(const typename LA_traits_complex<T>::NRMat_Noncomplex_type &rhs, bool imagpart = false);
//! explicit decomplexifying constructor
explicit NRMat(const NRMat<complex<T> > &rhs, bool imagpart = false);
explicit NRMat(const NRMat<std::complex<T> > &rhs, bool imagpart = false);
//! explicit constructor converting symmetric matrix stored in packed form into a <code>NRMat<T></code> object
explicit NRMat(const NRSMat<T> &rhs);
@ -191,8 +191,8 @@ public:
return result;
};
//! multiply this matrix of general type <code>T</code> by vector of type <code>complex<T></code>
const NRVec<complex<T> > operator*(const NRVec<complex<T> > &rhs) const {
NRVec<complex<T> > result(nn, rhs.getlocation());
const NRVec<std::complex<T> > operator*(const NRVec<std::complex<T> > &rhs) const {
NRVec<std::complex<T> > result(nn, rhs.getlocation());
result.gemv((T)0, *this, 'n', (T)1, rhs);
return result;
};
@ -243,7 +243,7 @@ public:
//! perform the <b>gemv</b> operation with vector of type <code>T</code>
void gemv(const T beta, NRVec<T> &r, const char trans, const T alpha, const NRVec<T> &x) const { r.gemv(beta, *this, trans, alpha, x); };
//! perform the <b>gemv</b> operation with vector of type <code>complex<T></code>
void gemv(const T beta, NRVec<complex<T> > &r, const char trans, const T alpha, const NRVec<complex<T> > &x) const { r.gemv(beta, *this, trans, alpha, x); };
void gemv(const T beta, NRVec<std::complex<T> > &r, const char trans, const T alpha, const NRVec<std::complex<T> > &x) const { r.gemv(beta, *this, trans, alpha, x); };
//! determine the pointer to the i<sup>th</sup> row
inline T* operator[](const int i);
@ -289,6 +289,7 @@ public:
//! get the pointer to the data
inline operator T*();
//! get the const pointer to the data
inline operator const T*() const;
@ -858,7 +859,7 @@ inline const double NRMat<double>::amin() const{
* @return \f$A_{l,m}\f$ which maximizes \f$\left\{\left|\Re{}A_{i,j}\right|+\left|\Im{}A_{i,j}\right|\right}\f$
******************************************************************************/
template<>
inline const complex<double> NRMat<complex<double> >::amax() const{
inline const std::complex<double> NRMat<std::complex<double> >::amax() const{
#ifdef CUDALA
if(location == cpu){
#endif
@ -869,10 +870,10 @@ inline const complex<double> NRMat<complex<double> >::amax() const{
#endif
#ifdef CUDALA
}else{
complex<double> ret(0.0, 0.0);
std::complex<double> ret(0.0, 0.0);
const size_t pozice = cublasIzamax((size_t)nn*mm, (cuDoubleComplex*)v, 1) - 1;
TEST_CUBLAS("cublasIzamax");
gpuget(1, sizeof(complex<double>), v + pozice, &ret);
gpuget(1, sizeof(std::complex<double>), v + pozice, &ret);
return ret;
}
#endif
@ -885,8 +886,8 @@ inline const complex<double> NRMat<complex<double> >::amax() const{
* @return \f$A_{l,m}\f$ which minimizes \f$\left\{\left|\Re{}A_{i,j}\right|+\left|\Im{}A_{i,j}\right|\right}\f$
******************************************************************************/
template<>
inline const complex<double> NRMat<complex<double> >::amin() const{
complex<double> ret(0.0, 0.0);
inline const std::complex<double> NRMat<std::complex<double> >::amin() const{
std::complex<double> ret(0.0, 0.0);
#ifdef CUDALA
if(location == cpu){
#endif
@ -894,7 +895,7 @@ inline const complex<double> NRMat<complex<double> >::amin() const{
const size_t nm = (size_t)nn*mm;
int index(-1);
double val(0.0), min_val(0.0);
complex<double> z_val(0.0, 0.0);
std::complex<double> z_val(0.0, 0.0);
min_val = std::numeric_limits<double>::max();
for(register int i=0; i < nm; i++){
@ -915,7 +916,7 @@ inline const complex<double> NRMat<complex<double> >::amin() const{
}else{
const size_t pozice = cublasIzamin((size_t)nn*mm, (cuDoubleComplex*)v, 1) - 1;
TEST_CUBLAS("cublasIzamin");
gpuget(1, sizeof(complex<double>), v + pozice, &ret);
gpuget(1, sizeof(std::complex<double>), v + pozice, &ret);
}
#endif
return ret;
@ -1139,10 +1140,10 @@ void NRMat<T>::resize(int n, int m) {
* @return matrix \f$B\f$ where \f$\Re B=A\f$ and \f$\Im B = 0\f$
******************************************************************************/
template<typename T>
NRMat<complex<T> > complexify(const NRMat<T> &rhs) {
NRMat<std::complex<T> > complexify(const NRMat<T> &rhs) {
NOT_GPU(rhs);
NRMat<complex<T> > r(rhs.nrows(), rhs.ncols(), rhs.getlocation());
NRMat<std::complex<T> > r(rhs.nrows(), rhs.ncols(), rhs.getlocation());
for(register int i=0; i<rhs.nrows(); ++i){
for(register int j=0; j<rhs.ncols(); ++j) r(i,j) = rhs(i,j);
}

View File

@ -764,6 +764,7 @@ extern "C" void FORNAME(dgesvd)(const char *JOBU, const char *JOBVT, const FIN
const FINT *N, double *A, const FINT *LDA, double *S, double *U, const FINT *LDU,
double *VT, const FINT *LDVT, double *WORK, const FINT *LWORK, FINT *INFO );
//normally in v returns vtransposed for default vnotdagger=0
void singular_decomposition(NRMat<double> &a, NRMat<double> *u, NRVec<double> &s,
NRMat<double> *v, const bool vnotdagger, int m, int n)
{

View File

@ -331,10 +331,11 @@ case Euler_case('z','x','y'):
}
//
template<typename T>
void Quaternion<T>::axis2normquat(const T *axis, const T &angle)
{
T a = (T).5*angle;
T a = ((T).5)*angle;
q[0]=cos(a);
T s=sin(a);
q[1]=axis[0]*s;

View File

@ -102,8 +102,8 @@ public:
//C-style IO
void fprintf(FILE *f, const char *format) const {::fprintf(f,format,q[0],q[1],q[2],q[3]);};
void sprintf(char *f, const char *format) const {::sprintf(f,format,q[0],q[1],q[2],q[3]);};
int fprintf(FILE *f, const char *format) const {return ::fprintf(f,format,q[0],q[1],q[2],q[3]);};
int sprintf(char *f, const char *format) const {return ::sprintf(f,format,q[0],q[1],q[2],q[3]);};
int fscanf(FILE *f, const char *format) const {return ::fscanf(f,format,q[0],q[1],q[2],q[3]);};
int sscanf(char *f, const char *format) const {return ::sscanf(f,format,q[0],q[1],q[2],q[3]);};
};

65
smat.cc
View File

@ -208,12 +208,12 @@ const NRSMat<double> NRSMat<double>::operator-() const {
* @return modified copy of this matrix
******************************************************************************/
template <>
const NRSMat<complex<double> > NRSMat<complex<double> >::operator-() const {
NRSMat<complex<double> > result(nn, getlocation());
const NRSMat<std::complex<double> > NRSMat<std::complex<double> >::operator-() const {
NRSMat<std::complex<double> > result(nn, getlocation());
#ifdef CUDALA
if(location == cpu) {
#endif
memcpy(result.v, v, NN2*sizeof(complex<double>));
memcpy(result.v, v, NN2*sizeof(std::complex<double>));
cblas_zscal(NN2, &CMONE, result.v, 1);
#ifdef CUDALA
@ -258,7 +258,7 @@ void NRSMat<double>::randomize(const double &x) {
* distribution. The real and imaginary parts are generated independently.
******************************************************************************/
template<>
void NRSMat<complex<double> >::randomize(const double &x) {
void NRSMat<std::complex<double> >::randomize(const double &x) {
for(register size_t i=0; i<NN2; ++i) v[i].real(x*(2.*random()/(1. + RAND_MAX) -1.));
for(register size_t i=0; i<NN2; ++i) v[i].imag(x*(2.*random()/(1. + RAND_MAX) -1.));
for(register int i=0; i<nn; ++i){
@ -342,13 +342,13 @@ const NRMat<double> NRSMat<double>::operator*(const NRMat<double> &rhs) const {
* @return matrix produt \f$S\times{}A\f$
******************************************************************************/
template<>
const NRMat<complex<double> >
NRSMat<complex<double> >::operator*(const NRMat<complex<double> > &rhs) const {
const NRMat<std::complex<double> >
NRSMat<std::complex<double> >::operator*(const NRMat<std::complex<double> > &rhs) const {
#ifdef DEBUG
if (nn != rhs.nrows()) laerror("incompatible dimensions in NRSMat<complex<double> >::operator*(const NRMat<complex<double> > &)");
if (nn != rhs.nrows()) laerror("incompatible dimensions in NRSMat<std::complex<double> >::operator*(const NRMat<std::complex<double> > &)");
#endif
SAME_LOC(*this, rhs);
NRMat<complex<double> > result(nn, rhs.ncols(), getlocation());
NRMat<std::complex<double> > result(nn, rhs.ncols(), getlocation());
#ifdef CUDALA
if(location == cpu){
#endif
@ -429,14 +429,14 @@ const NRMat<double> NRSMat<double>::operator*(const NRSMat<double> &rhs) const {
* @return matrix produt \f$G\times{}H\f$ (not necessarily symmetric)
******************************************************************************/
template<>
const NRMat<complex<double> >
NRSMat<complex<double> >::operator*(const NRSMat<complex<double> > &rhs) const {
const NRMat<std::complex<double> >
NRSMat<std::complex<double> >::operator*(const NRSMat<std::complex<double> > &rhs) const {
#ifdef DEBUG
if (nn != rhs.nn) laerror("incompatible dimensions in NRSMat<complex<double> >::operator*(const NRSMat<complex<double> > &)");
if (nn != rhs.nn) laerror("incompatible dimensions in NRSMat<std::complex<double> >::operator*(const NRSMat<std::complex<double> > &)");
#endif
SAME_LOC(*this, rhs);
NRMat<complex<double> > result(nn, nn, getlocation());
NRMat<complex<double> > rhsmat(rhs);
NRMat<std::complex<double> > result(nn, nn, getlocation());
NRMat<std::complex<double> > rhsmat(rhs);
result = *this * rhsmat;
return result;
}
@ -477,11 +477,11 @@ const double NRSMat<double>::dot(const NRSMat<double> &rhs) const {
* @return computed inner product
******************************************************************************/
template<>
const complex<double> NRSMat<complex<double> >::dot(const NRSMat<complex<double> > &rhs) const {
const std::complex<double> NRSMat<std::complex<double> >::dot(const NRSMat<std::complex<double> > &rhs) const {
#ifdef DEBUG
if (nn != rhs.nn) laerror("incompatible dimensions in complex<double> NRSMat<complex<double> >::dot(const NRSMat<complex<double> > &)");
if (nn != rhs.nn) laerror("incompatible dimensions in std::complex<double> NRSMat<std::complex<double> >::dot(const NRSMat<std::complex<double> > &)");
#endif
complex<double> dot(0., 0.);
std::complex<double> dot(0., 0.);
SAME_LOC(*this, rhs);
#ifdef CUDALA
@ -491,7 +491,7 @@ const complex<double> NRSMat<complex<double> >::dot(const NRSMat<complex<double>
#ifdef CUDALA
}else{
const cuDoubleComplex _dot = cublasZdotc(NN2, (cuDoubleComplex*)v, 1, (cuDoubleComplex*)(rhs.v), 1);
dot = complex<double>(cuCreal(_dot), cuCimag(_dot));
dot = std::complex<double>(cuCreal(_dot), cuCimag(_dot));
TEST_CUBLAS("cublasZdotc");
}
#endif
@ -522,6 +522,7 @@ const double NRSMat<double>::dot(const NRVec<double> &rhs) const {
TEST_CUBLAS("cublasDdot");
}
#endif
return ret;
}
@ -532,12 +533,12 @@ const double NRSMat<double>::dot(const NRVec<double> &rhs) const {
* @return computed inner product
******************************************************************************/
template<>
const complex<double>
NRSMat<complex<double> >::dot(const NRVec<complex<double> > &rhs) const {
const std::complex<double>
NRSMat<std::complex<double> >::dot(const NRVec<std::complex<double> > &rhs) const {
#ifdef DEBUG
if(NN2 != rhs.nn) laerror("incompatible dimensions in complex<double> NRSMat<complex<double> >::dot(const NRVec<complex<double> > &)");
if(NN2 != rhs.nn) laerror("incompatible dimensions in std::complex<double> NRSMat<std::complex<double> >::dot(const NRVec<std::complex<double> > &)");
#endif
complex<double> dot(0., 0.);
std::complex<double> dot(0., 0.);
SAME_LOC(*this, rhs);
#ifdef CUDALA
if(location == cpu){
@ -547,7 +548,7 @@ NRSMat<complex<double> >::dot(const NRVec<complex<double> > &rhs) const {
}else{
const cuDoubleComplex _dot = cublasZdotc(NN2, (cuDoubleComplex*)v, 1, (cuDoubleComplex*)rhs.v, 1);
TEST_CUBLAS("cublasZdotc");
dot = complex<double>(cuCreal(_dot), cuCimag(_dot));
dot = std::complex<double>(cuCreal(_dot), cuCimag(_dot));
}
#endif
return dot;
@ -593,7 +594,7 @@ const double NRSMat<double>::norm(const double scalar) const {
* @param[in] scalar subtract this scalar value from the diagonal elements before the norm computation
******************************************************************************/
template<>
const double NRSMat< complex<double> >::norm(const complex<double> scalar) const {
const double NRSMat< std::complex<double> >::norm(const std::complex<double> scalar) const {
if(!(scalar.real()) && !(scalar.imag())){
double ret(0.);
#ifdef CUDALA
@ -611,7 +612,7 @@ const double NRSMat< complex<double> >::norm(const complex<double> scalar) const
int k(0);
double sum(0.);
complex<double> tmp;
std::complex<double> tmp;
for(register int i=0; i<nn; ++i){
for(register int j=0; j<=i; ++j){
@ -655,9 +656,9 @@ void NRSMat<double>::axpy(const double alpha, const NRSMat<double> &x) {
* \f[H \leftarrow \alpha G + H\f]
******************************************************************************/
template<>
void NRSMat<complex<double> >::axpy(const complex<double> alpha, const NRSMat<complex<double> > & x) {
void NRSMat<std::complex<double> >::axpy(const std::complex<double> alpha, const NRSMat<std::complex<double> > & x) {
#ifdef DEBUG
if(nn != x.nn) laerror("incompatible dimensions in void NRSMat<complex<double> >::axpy(const complex<double> , const NRSMat<complex<double> >&)");
if(nn != x.nn) laerror("incompatible dimensions in void NRSMat<std::complex<double> >::axpy(const std::complex<double> , const NRSMat<std::complex<double> >&)");
#endif
SAME_LOC(*this, x);
copyonwrite();
@ -682,21 +683,21 @@ void NRSMat<complex<double> >::axpy(const complex<double> alpha, const NRSMat<co
* @param[in] imagpart flag determining whether \f$S\f$ should correspond to the real or imaginary part of \f$H\f$
******************************************************************************/
template<>
NRSMat<complex<double> >::NRSMat(const NRSMat<double> &rhs, bool imagpart): nn(rhs.nrows()), count(new int(1)) {
NRSMat<std::complex<double> >::NRSMat(const NRSMat<double> &rhs, bool imagpart): nn(rhs.nrows()), count(new int(1)) {
//inconsistent in general case?
const int nnp1 = nn*(nn + 1)/2;
#ifdef CUDALA
location = rhs.getlocation();
if(location == cpu){
#endif
v = new complex<double>[nnp1];
memset(v, 0, nnp1*sizeof(complex<double>));
v = new std::complex<double>[nnp1];
memset(v, 0, nnp1*sizeof(std::complex<double>));
cblas_dcopy(nnp1, &rhs(0, 0), 1, ((double *)v) + (imagpart?1:0), 2);
#ifdef CUDALA
}else{
v = (complex<double>*) gpualloc(nnp1*sizeof(complex<double>));
v = (std::complex<double>*) gpualloc(nnp1*sizeof(std::complex<double>));
complex<double> *_val = gpuputcomplex(CZERO);
std::complex<double> *_val = gpuputcomplex(CZERO);
cublasZcopy(nnp1, (cuDoubleComplex*)_val, 0, (cuDoubleComplex*)v, 1);
TEST_CUBLAS("cublasZcopy");
gpufree(_val);
@ -711,7 +712,7 @@ NRSMat<complex<double> >::NRSMat(const NRSMat<double> &rhs, bool imagpart): nn(r
* forced instantization in the corresponding object file
******************************************************************************/
template class NRSMat<double>;
template class NRSMat<complex<double> >;
template class NRSMat<std::complex<double> >;
template class NRSMat<long long>;
template class NRSMat<long>;

50
smat.h
View File

@ -127,12 +127,12 @@ public:
const T dot(const NRVec<T> &rhs) const;
const NRVec<T> operator*(const NRVec<T> &rhs) const {NRVec<T> result(nn,rhs.getlocation()); result.gemv((T)0,*this,'n',(T)1,rhs); return result;};
const NRVec<complex<T> > operator*(const NRVec<complex<T> > &rhs) const {NRVec<complex<T> > result(nn,rhs.getlocation()); result.gemv((T)0,*this,'n',(T)1,rhs); return result;};
const NRVec<std::complex<T> > operator*(const NRVec<std::complex<T> > &rhs) const {NRVec<std::complex<T> > result(nn,rhs.getlocation()); result.gemv((T)0,*this,'n',(T)1,rhs); return result;};
const T* diagonalof(NRVec<T> &, const bool divide = 0, bool cache = false) const;
void gemv(const T beta, NRVec<T> &r, const char trans, const T alpha, const NRVec<T> &x) const {r.gemv(beta,*this,trans,alpha,x);};
void gemv(const T beta, NRVec<complex<T> > &r, const char trans, const T alpha, const NRVec<complex<T> > &x) const {r.gemv(beta,*this,trans,alpha,x);};
void gemv(const T beta, NRVec<std::complex<T> > &r, const char trans, const T alpha, const NRVec<std::complex<T> > &x) const {r.gemv(beta,*this,trans,alpha,x);};
inline const T& operator[](const size_t ij) const;
inline T& operator[](const size_t ij);
@ -309,8 +309,8 @@ inline NRSMat<double> & NRSMat<double>::operator*=(const double &a) {
* @return reference to the modified matrix
******************************************************************************/
template<>
inline NRSMat<complex<double> > &
NRSMat<complex<double> >::operator*=(const complex<double> &a) {
inline NRSMat<std::complex<double> > &
NRSMat<std::complex<double> >::operator*=(const std::complex<double> &a) {
copyonwrite();
#ifdef CUDALA
if(location == cpu){
@ -320,7 +320,7 @@ NRSMat<complex<double> >::operator*=(const complex<double> &a) {
}else{
const cuDoubleComplex _a = make_cuDoubleComplex(a.real(), a.imag());
cublasZscal(NN2, _a, (cuDoubleComplex*)v, 1);
TEST_CUBLAS("cublasZscal");//"NRSMat<complex<double> >& NRSMat<complex<double> >::operator*=(const complex<double> &)"
TEST_CUBLAS("cublasZscal");//"NRSMat<std::complex<double> >& NRSMat<std::complex<double> >::operator*=(const std::complex<double> &)"
}
#endif
return *this;
@ -404,9 +404,9 @@ inline NRSMat<double>& NRSMat<double>::operator+=(const NRSMat<double> & rhs) {
* @return reference to the modified matrix
******************************************************************************/
template<>
inline NRSMat<complex<double> >& NRSMat<complex<double> >::operator+=(const NRSMat<complex<double> > & rhs) {
inline NRSMat<std::complex<double> >& NRSMat<std::complex<double> >::operator+=(const NRSMat<std::complex<double> > & rhs) {
#ifdef DEBUG
if(nn != rhs.nn) laerror("incompatible dimensions in NRSMat<complex<double> >& NRSMat<complex<double> >::operator+=(const NRSMat<complex<double> > &)");
if(nn != rhs.nn) laerror("incompatible dimensions in NRSMat<std::complex<double> >& NRSMat<std::complex<double> >::operator+=(const NRSMat<std::complex<double> > &)");
#endif
SAME_LOC(*this, rhs);
copyonwrite();
@ -418,7 +418,7 @@ inline NRSMat<complex<double> >& NRSMat<complex<double> >::operator+=(const NRSM
#ifdef CUDALA
}else{
cublasZaxpy(NN2, CUONE, (cuDoubleComplex*)(rhs.v), 1, (cuDoubleComplex*)v, 1);
TEST_CUBLAS("cublasZaxpy");//"NRSMat<complex<double> >& NRSMat<complex<double> >::operator+=(const NRSMat<complex<double> > &)"
TEST_CUBLAS("cublasZaxpy");//"NRSMat<std::complex<double> >& NRSMat<std::complex<double> >::operator+=(const NRSMat<std::complex<double> > &)"
}
#endif
return *this;
@ -474,9 +474,9 @@ inline NRSMat<double>& NRSMat<double>::operator-=(const NRSMat<double>& rhs) {
* @return reference to the modified matrix
******************************************************************************/
template<>
inline NRSMat<complex<double> >& NRSMat<complex<double> >::operator-=(const NRSMat<complex<double> >& rhs) {
inline NRSMat<std::complex<double> >& NRSMat<std::complex<double> >::operator-=(const NRSMat<std::complex<double> >& rhs) {
#ifdef DEBUG
if(nn != rhs.nn) laerror("incompatible dimensions in NRSMat<complex<double> >& NRSMat<complex<double> >::operator-=(const NRSMat<complex<double> > &)");
if(nn != rhs.nn) laerror("incompatible dimensions in NRSMat<std::complex<double> >& NRSMat<std::complex<double> >::operator-=(const NRSMat<std::complex<double> > &)");
#endif
SAME_LOC(*this, rhs);
copyonwrite();
@ -488,7 +488,7 @@ inline NRSMat<complex<double> >& NRSMat<complex<double> >::operator-=(const NRSM
#ifdef CUDALA
}else{
cublasZaxpy(NN2, CUMONE, (cuDoubleComplex*)(rhs.v), 1, (cuDoubleComplex*)v, 1);
TEST_CUBLAS("cublasZaxpy");//"NRSMat<complex<double> >& NRSMat<complex<double> >::operator-=(const NRSMat<complex<double> > &)"
TEST_CUBLAS("cublasZaxpy");//"NRSMat<std::complex<double> >& NRSMat<std::complex<double> >::operator-=(const NRSMat<std::complex<double> > &)"
}
#endif
return *this;
@ -779,8 +779,8 @@ inline const double NRSMat<double>::amin() const {
* @return \f$A_{l,m}\f$ which maximizes \f$\left|\Re{}A_{i,j}\right| + \left|\Im{}A_{i,j}\right|\f$
******************************************************************************/
template<>
inline const complex<double> NRSMat< complex<double> >::amax() const{
complex<double> ret(0., 0.);
inline const std::complex<double> NRSMat< std::complex<double> >::amax() const{
std::complex<double> ret(0., 0.);
#ifdef CUDALA
if(location == cpu){
#endif
@ -788,8 +788,8 @@ inline const complex<double> NRSMat< complex<double> >::amax() const{
#ifdef CUDALA
}else{
const int pozice = cublasIzamax(NN2, (cuDoubleComplex*)v, 1) - 1;
TEST_CUBLAS("cublasIzamax");//"complex<double> NRSMat<complex<double> >::amax()"
gpuget(1, sizeof(complex<double>), v + pozice, &ret);
TEST_CUBLAS("cublasIzamax");//"std::complex<double> NRSMat<std::complex<double> >::amax()"
gpuget(1, sizeof(std::complex<double>), v + pozice, &ret);
}
#endif
return ret;
@ -801,15 +801,15 @@ inline const complex<double> NRSMat< complex<double> >::amax() const{
* @return \f$A_{l,m}\f$ which minimizes \f$\left|\Re{}A_{i,j}\right| + \left|\Im{}A_{i,j}\right|\f$
******************************************************************************/
template<>
inline const complex<double> NRSMat<complex<double> >::amin() const{
complex<double> ret(0., 0.);
inline const std::complex<double> NRSMat<std::complex<double> >::amin() const{
std::complex<double> ret(0., 0.);
#ifdef CUDALA
if(location == cpu){
#endif
// izamin seems not to be supported
int index(0);
double val(0.0), min_val(0.0);
complex<double> z_val(0.0, 0.0);
std::complex<double> z_val(0.0, 0.0);
min_val = std::numeric_limits<double>::max();
for(register size_t i = 0; i < NN2; i++){
@ -821,8 +821,8 @@ inline const complex<double> NRSMat<complex<double> >::amin() const{
#ifdef CUDALA
}else{
const int pozice = cublasIzamin(nn, (cuDoubleComplex*)v, 1) - 1;
TEST_CUBLAS("cublasIzamin");//"complex<double> NRSMat<complex<double> >::amin()"
gpuget(1, sizeof(complex<double>), v + pozice, &ret);
TEST_CUBLAS("cublasIzamin");//"std::complex<double> NRSMat<std::complex<double> >::amin()"
gpuget(1, sizeof(std::complex<double>), v + pozice, &ret);
}
#endif
return ret;
@ -1056,10 +1056,10 @@ void NRSMat<T>::moveto(const GPUID dest) {
* @return matrix \f$B\f$ where \f$\Re B=A\f$ and \f$\Im B = 0\f$
******************************************************************************/
template<typename T>
NRSMat<complex<T> > complexify(const NRSMat<T> &rhs) {
NRSMat<std::complex<T> > complexify(const NRSMat<T> &rhs) {
NOT_GPU(rhs);
NRSMat<complex<T> > r(rhs.nrows());
NRSMat<std::complex<T> > r(rhs.nrows());
for(register int i = 0; i<rhs.nrows(); ++i)
for(register int j = 0; j<=i; ++j) r(i,j) = rhs(i,j);
return r;
@ -1073,8 +1073,8 @@ NRSMat<complex<T> > complexify(const NRSMat<T> &rhs) {
******************************************************************************/
/*
template<>
NRSMat<complex<double> > complexify(const NRSMat<double> &rhs) {
NRSMat<complex<double> > r(rhs.nrows(), rhs.getlocation());
NRSMat<std::complex<double> > complexify(const NRSMat<double> &rhs) {
NRSMat<std::complex<double> > r(rhs.nrows(), rhs.getlocation());
#ifdef CUDALA
if(rhs.getlocation() == cpu){
#endif
@ -1082,7 +1082,7 @@ NRSMat<complex<double> > complexify(const NRSMat<double> &rhs) {
#ifdef CUDALA
}else{
cublasDcopy(rhs.size(), &(rhs[0]), 1, (double*)(&(r[0])), 2);
TEST_CUBLAS("cublasDcopy");//"NRSMat<complex<double> > complexify(const NRSMat<double> &)"
TEST_CUBLAS("cublasDcopy");//"NRSMat<std::complex<double> > complexify(const NRSMat<double> &)"
}
#endif
return r;

View File

@ -764,7 +764,7 @@ return r;
}
template<>
void NRMat<complex<double> >::gemm(const complex<double> &beta, const SparseMat<complex<double> > &a, const char transa, const NRMat<complex<double> > &b, const char transb, const complex<double> &alpha)
void NRMat<std::complex<double> >::gemm(const std::complex<double> &beta, const SparseMat<std::complex<double> > &a, const char transa, const NRMat<std::complex<double> > &b, const char transb, const std::complex<double> &alpha)
{
laerror("not implemented yet");
}
@ -1291,13 +1291,13 @@ template void SparseMat<T>::permuteindices(const NRVec<SPMatindex> &p);\
INSTANTIZE(double)
INSTANTIZE(complex<double>) //some functions are not OK for hermitean matrices, needs a revision!!!
INSTANTIZE(std::complex<double>) //some functions are not OK for hermitean matrices, needs a revision!!!
*/
//////////////////////////////////////////////////////////////////////////////
//// forced instantization in the corresponding object file
template class SparseMat<double>;
template class SparseMat<complex<double> >;
template class SparseMat<std::complex<double> >;
#define INSTANTIZE(T) \
template NRMat<T>::NRMat(const SparseMat<T> &rhs); \
@ -1305,7 +1305,7 @@ template NRSMat<T>::NRSMat(const SparseMat<T> &rhs); \
template NRVec<T>::NRVec(const SparseMat<T> &rhs);
INSTANTIZE(double)
INSTANTIZE(complex<double>)
INSTANTIZE(std::complex<double>)
}//namespace

View File

@ -357,7 +357,7 @@ INSTANTIZE(complex<double>)
//// forced instantization of functions in the header in the corresponding object file
template class SparseSMat<double>;
template class SparseSMat<complex<double> >;
template class SparseSMat<std::complex<double> >;
/*activate this if needed
template void SparseSMat<NRMat<double> >::put(int fd, bool dimen, bool transp) const;

28
t.cc
View File

@ -922,6 +922,24 @@ cout <<r2;
cout <<"error = "<<(r1-r2).norm()<<endl;
}
if(0)
{
int dim; cin>>dim;
int degree; cin >>degree;
NRMat<double> h(dim,dim);
NRMat<double> t(dim,dim);
NRVec<double> x(dim);
h.randomize(1.);
t.randomize(1.);
x.randomize(2.);
NRVec<double> y1 = exp(-t) * h * exp(t) *x;
NRVec<double> y2 = BCHtimes(h,'n',t,'n',x,degree,true);
NRVec<double> y3 = exp(t) * h * exp(-t) *x;
NRVec<double> y4 = BCHtimes(h,'n',t,'n',x,degree,false);
cout <<"BCHtimes error = "<<(y1-y2).norm()<<endl;
cout <<"BCHtimes error = "<<(y3-y4).norm()<<endl;
}
if(0)
{
int n;
@ -1863,7 +1881,7 @@ cin >>v;
cout <<v;
}
if(1)
if(0)
{
Quaternion<double> q(1.);
Quaternion<double> p,r(q);
@ -1962,5 +1980,11 @@ cout <<"normquat2euler test "<<endl<<qq<<endl<<xqq<<endl<<qq-xqq<<endl;
}
if(1)
{
NRVec<double> a,b,c;
cin >>a>>b;
c=a+b;
cout<<c;
}
}

88
vec.cc
View File

@ -168,8 +168,8 @@ const NRVec<double> NRVec<double>::operator-() const {
* @return the modified vector by value
******************************************************************************/
template<>
const NRVec<complex<double> > NRVec<complex<double> >::operator-() const {
NRVec<complex<double> > result(*this);
const NRVec<std::complex<double> > NRVec<std::complex<double> >::operator-() const {
NRVec<std::complex<double> > result(*this);
result.copyonwrite();
#ifdef CUDALA
if(location == cpu){
@ -262,11 +262,11 @@ void NRVec<double>::randomize(const double &x){
* \li \c true current vector is smaller than vector \c rhs
******************************************************************************/
template<>
void NRVec<complex<double> >::randomize(const double &x) {
void NRVec<std::complex<double> >::randomize(const double &x) {
NOT_GPU(*this);
for(register int i=0; i<nn; ++i){
v[i] = complex<double>(x*(2.*random()/(1. + RAND_MAX) - 1.), x*(2.*random()/(1. + RAND_MAX) - 1.));
v[i] = std::complex<double>(x*(2.*random()/(1. + RAND_MAX) - 1.), x*(2.*random()/(1. + RAND_MAX) - 1.));
}
}
@ -281,7 +281,7 @@ void NRVec<complex<double> >::randomize(const double &x) {
* \li \c true current vector is smaller than vector \c rhs
******************************************************************************/
template<>
NRVec<complex<double> >::NRVec(const NRVec<double> &rhs, bool imagpart): nn(rhs.size()){
NRVec<std::complex<double> >::NRVec(const NRVec<double> &rhs, bool imagpart): nn(rhs.size()){
count = new int;
*count = 1;
@ -289,12 +289,12 @@ NRVec<complex<double> >::NRVec(const NRVec<double> &rhs, bool imagpart): nn(rhs.
location = rhs.getlocation();
if(location == cpu){
#endif
v = (complex<double>*)new complex<double>[nn];
memset(v, 0, nn*sizeof(complex<double>));
v = (std::complex<double>*)new std::complex<double>[nn];
memset(v, 0, nn*sizeof(std::complex<double>));
cblas_dcopy(nn, &rhs[0], 1, ((double *)v) + (imagpart?1:0), 2);
#ifdef CUDALA
}else{
v = (complex<double>*) gpualloc(nn*sizeof(complex<double>));
v = (std::complex<double>*) gpualloc(nn*sizeof(std::complex<double>));
cublasZscal(nn, CUZERO, (cuDoubleComplex*)v, 1);
TEST_CUBLAS("cublasZscal");
@ -338,7 +338,7 @@ void NRVec<double>::axpy(const double alpha, const NRVec<double> &x) {
* @param[in] x complex vector \f$\vec{x}\f$
******************************************************************************/
template<>
void NRVec<complex<double> >::axpy(const complex<double> alpha, const NRVec<complex<double> > &x){
void NRVec<std::complex<double> >::axpy(const std::complex<double> alpha, const NRVec<std::complex<double> > &x){
#ifdef DEBUG
if (nn != x.nn) laerror("incompatible vectors");
#endif
@ -382,7 +382,7 @@ void NRVec<double>::axpy(const double alpha, const double *x, const int stride){
* @param[in] stride sets the stride
******************************************************************************/
template<>
void NRVec<complex<double> >::axpy(const complex<double> alpha, const complex<double> *x, const int stride){
void NRVec<std::complex<double> >::axpy(const std::complex<double> alpha, const std::complex<double> *x, const int stride){
NOT_GPU(*this);
copyonwrite();
@ -416,7 +416,7 @@ copyonwrite();
* @return reference to the modified vector
******************************************************************************/
template<>
NRVec<complex<double> >& NRVec<complex<double> >::operator=(const complex<double> &a){
NRVec<std::complex<double> >& NRVec<std::complex<double> >::operator=(const std::complex<double> &a){
copyonwrite();
#ifdef CUDALA
@ -425,7 +425,7 @@ copyonwrite();
cblas_zcopy(nn, &a, 0, v, 1);
#ifdef CUDALA
}else{
smart_gpu_set(nn, (complex<double>)0, v);
smart_gpu_set(nn, (std::complex<double>)0, v);
}
#endif
return *this;
@ -492,7 +492,7 @@ NRVec<double>& NRVec<double>::normalize(double *norm){
* @return reference to the modified vector
******************************************************************************/
template<>
NRVec<complex<double> > & NRVec<complex<double> >::normalize(double *norm){
NRVec<std::complex<double> > & NRVec<std::complex<double> >::normalize(double *norm){
double tmp(0.0);
#ifdef CUDALA
if(location == cpu){
@ -566,8 +566,8 @@ void NRVec<double>::gemv(const double beta, const NRMat<double> &A,
* @see gemm
******************************************************************************/
template<>
void NRVec<complex<double> >::gemv(const double beta, const NRMat<double> &A,
const char trans, const double alpha, const NRVec<complex<double> > &x) {
void NRVec<std::complex<double> >::gemv(const double beta, const NRMat<double> &A,
const char trans, const double alpha, const NRVec<std::complex<double> > &x) {
#ifdef DEBUG
if ((tolower(trans) == 'n'?A.ncols():A.nrows()) != x.size()){ laerror("incompatible vectors"); }
#endif
@ -604,9 +604,9 @@ void NRVec<complex<double> >::gemv(const double beta, const NRMat<double> &A,
* @see gemm
******************************************************************************/
template<>
void NRVec<complex<double> >::gemv(const complex<double> beta,
const NRMat<complex<double> > &A, const char trans,
const complex<double> alpha, const NRVec<complex<double> > &x) {
void NRVec<std::complex<double> >::gemv(const std::complex<double> beta,
const NRMat<std::complex<double> > &A, const char trans,
const std::complex<double> alpha, const NRVec<std::complex<double> > &x) {
#ifdef DEBUG
if ((tolower(trans) == 'n'?A.ncols():A.nrows()) != x.size()){ laerror("incompatible vectors"); }
#endif
@ -673,8 +673,8 @@ void NRVec<double>::gemv(const double beta, const NRSMat<double> &A,
* @see gemm, NRSMat<T>
******************************************************************************/
template<>
void NRVec<complex<double> >::gemv(const double beta, const NRSMat<double> &A,
const char trans, const double alpha, const NRVec<complex<double> > &x) {
void NRVec<std::complex<double> >::gemv(const double beta, const NRSMat<double> &A,
const char trans, const double alpha, const NRVec<std::complex<double> > &x) {
#ifdef DEBUG
if(A.ncols() != x.size()){ laerror("incompatible dimensions"); }
#endif
@ -708,9 +708,9 @@ void NRVec<complex<double> >::gemv(const double beta, const NRSMat<double> &A,
* @see gemm, NRSMat<T>
******************************************************************************/
template<>
void NRVec<complex<double> >::gemv(const complex<double> beta,
const NRSMat<complex<double> > &A, const char trans,
const complex<double> alpha, const NRVec<complex<double> > &x){
void NRVec<std::complex<double> >::gemv(const std::complex<double> beta,
const NRSMat<std::complex<double> > &A, const char trans,
const std::complex<double> alpha, const NRVec<std::complex<double> > &x){
#ifdef DEBUG
if(A.ncols() != x.size()) laerror("incompatible dimensions");
#endif
@ -726,7 +726,7 @@ void NRVec<complex<double> >::gemv(const complex<double> beta,
const cuDoubleComplex _alpha = make_cuDoubleComplex(alpha.real(), alpha.imag());
const cuDoubleComplex _beta = make_cuDoubleComplex(beta.real(), beta.imag());
cublasZhpmv('U', A.ncols(), _alpha, (cuDoubleComplex*)((const complex<double>*)A), (cuDoubleComplex*)(x.v), 1, _beta, (cuDoubleComplex*)(this->v), 1);
cublasZhpmv('U', A.ncols(), _alpha, (cuDoubleComplex*)((const std::complex<double>*)A), (cuDoubleComplex*)(x.v), 1, _beta, (cuDoubleComplex*)(this->v), 1);
TEST_CUBLAS("cublasZhpmv");
}
#endif
@ -771,11 +771,11 @@ const NRMat<double> NRVec<double>::otimes(const NRVec<double> &b,const bool conj
* @param[in] scale complex scaling factor \f$\alpha\f$
******************************************************************************/
template<>
const NRMat<complex<double> >
NRVec<complex<double> >::otimes(const NRVec<complex<double> > &b, const bool conj, const complex<double> &scale) const {
const NRMat<std::complex<double> >
NRVec<std::complex<double> >::otimes(const NRVec<std::complex<double> > &b, const bool conj, const std::complex<double> &scale) const {
SAME_LOC(*this, b);
NRMat<complex<double> > result(0., nn, b.nn, this->getlocation());
NRMat<std::complex<double> > result(0., nn, b.nn, this->getlocation());
#ifdef CUDALA
if(location == cpu){
@ -816,8 +816,8 @@ int NRVec<T>::sort(int direction, int from, int to, int *perm) {
}
template<>
NRVec<complex<double> > complexify(const NRVec<double> &rhs) {
NRVec<complex<double> > r(rhs.size(), rhs.getlocation());
NRVec<std::complex<double> > complexify(const NRVec<double> &rhs) {
NRVec<std::complex<double> > r(rhs.size(), rhs.getlocation());
#ifdef CUDALA
if(rhs.getlocation() == cpu){
@ -844,7 +844,7 @@ template void NRVec<T>::put(int fd, bool dim, bool transp) const; \
template void NRVec<T>::get(int fd, bool dim, bool transp); \
INSTANTIZE(double)
INSTANTIZE(complex<double>)
INSTANTIZE(std::complex<double>)
INSTANTIZE(char)
INSTANTIZE(short)
INSTANTIZE(int)
@ -869,7 +869,7 @@ template<> const NRMat<T> NRVec<T>::otimes(const NRVec<T> &b,const bool conj, co
// Roman
// following gemv are not implemented
template<> void NRVec<double>::gemv(const double beta, const SparseMat<double> &a, const char trans, const double alpha, const NRVec<double> &x, bool s) { laerror("gemv on unsupported types"); }
template<> void NRVec< complex<double> >::gemv(const complex<double> beta, const SparseMat< complex<double> > &a, const char trans, const complex<double> alpha, const NRVec< complex<double> > &x, bool s) { laerror("gemv on unsupported types"); }
template<> void NRVec< std::complex<double> >::gemv(const std::complex<double> beta, const SparseMat< std::complex<double> > &a, const char trans, const std::complex<double> alpha, const NRVec< std::complex<double> > &x, bool s) { laerror("gemv on unsupported types"); }
INSTANTIZE_DUMMY(char)
@ -882,21 +882,21 @@ INSTANTIZE_DUMMY(unsigned short)
INSTANTIZE_DUMMY(unsigned int)
INSTANTIZE_DUMMY(unsigned long)
INSTANTIZE_DUMMY(unsigned long long)
INSTANTIZE_DUMMY(complex<char>)
INSTANTIZE_DUMMY(complex<short>)
INSTANTIZE_DUMMY(complex<int>)
INSTANTIZE_DUMMY(complex<long>)
INSTANTIZE_DUMMY(complex<long long>)
INSTANTIZE_DUMMY(complex<unsigned char>)
INSTANTIZE_DUMMY(complex<unsigned short>)
INSTANTIZE_DUMMY(complex<unsigned int>)
INSTANTIZE_DUMMY(complex<unsigned long>)
INSTANTIZE_DUMMY(complex<unsigned long long>)
INSTANTIZE_DUMMY(complex<complex<double> >)
INSTANTIZE_DUMMY(complex<complex<float> >)
INSTANTIZE_DUMMY(std::complex<char>)
INSTANTIZE_DUMMY(std::complex<short>)
INSTANTIZE_DUMMY(std::complex<int>)
INSTANTIZE_DUMMY(std::complex<long>)
INSTANTIZE_DUMMY(std::complex<long long>)
INSTANTIZE_DUMMY(std::complex<unsigned char>)
INSTANTIZE_DUMMY(std::complex<unsigned short>)
INSTANTIZE_DUMMY(std::complex<unsigned int>)
INSTANTIZE_DUMMY(std::complex<unsigned long>)
INSTANTIZE_DUMMY(std::complex<unsigned long long>)
INSTANTIZE_DUMMY(std::complex<std::complex<double> >)
INSTANTIZE_DUMMY(std::complex<std::complex<float> >)
template class NRVec<double>;
template class NRVec<complex<double> >;
template class NRVec<std::complex<double> >;
template class NRVec<char>;
template class NRVec<short>;
template class NRVec<int>;

53
vec.h
View File

@ -33,7 +33,7 @@ template <typename T> void lawritemat(FILE *file, const T *a, int r, int c,
/***************************************************************************//**
* static constants used in several cblas-routines
******************************************************************************/
const static complex<double> CONE = 1.0, CMONE = -1.0, CZERO = 0.0;
const static std::complex<double> CONE = 1.0, CMONE = -1.0, CZERO = 0.0;
#ifdef CUDALA
const static cuDoubleComplex CUONE = {1.,0.}, CUMONE = {-1.,0.}, CUZERO = {0.,0.};
#endif
@ -73,7 +73,7 @@ protected:
public:
friend class NRSMat<T>;
friend class NRMat<T>;
template <typename U> friend NRVec<complex<U> > complexify(const NRVec<U>&);
template <typename U> friend NRVec<std::complex<U> > complexify(const NRVec<U>&);
typedef T ROWTYPE;
@ -272,6 +272,7 @@ public:
//! get the pointer to the underlying data structure
inline operator T*();
//! get the constant pointer to the underlying data structure
inline operator const T*() const;
@ -963,14 +964,14 @@ NRVec<T> & NRVec<T>::operator|=(const NRVec<T> &rhs) {
* @see NRVec<T>::copyonwrite()
******************************************************************************/
template<typename T>
NRVec<complex<T> > complexify(const NRVec<T> &rhs) {
NRVec<std::complex<T> > complexify(const NRVec<T> &rhs) {
NOT_GPU(rhs);
NRVec<complex<T> > r(rhs.size(), rhs.getlocation());
NRVec<std::complex<T> > r(rhs.size(), rhs.getlocation());
for(register int i=0; i<rhs.size(); ++i) r[i] = rhs[i];
return r;
}
template<> NRVec<complex<double> > complexify<double>(const NRVec<double> &rhs);
template<> NRVec<std::complex<double> > complexify<double>(const NRVec<double> &rhs);
/***************************************************************************//**
* routine for moving vector data between CPU and GPU memory
@ -1039,7 +1040,7 @@ inline NRVec<double>& NRVec<double>::operator+=(const double &a) {
* @return reference to the modified vector
******************************************************************************/
template<>
inline NRVec<complex<double> >& NRVec<complex<double> >::operator+=(const complex<double> &a) {
inline NRVec<std::complex<double> >& NRVec<std::complex<double> >::operator+=(const std::complex<double> &a) {
copyonwrite();
#ifdef CUDALA
if(location == cpu){
@ -1047,7 +1048,7 @@ inline NRVec<complex<double> >& NRVec<complex<double> >::operator+=(const comple
cblas_zaxpy(nn, &CONE, &a, 0, v, 1);
#ifdef CUDALA
}else{
complex<double> *d = gpuputcomplex(a);
std::complex<double> *d = gpuputcomplex(a);
cublasZaxpy(nn, CUONE, (cuDoubleComplex *)d, 0, (cuDoubleComplex *)v, 1);
TEST_CUBLAS("cublasZaxpy");
gpufree(d);
@ -1087,7 +1088,7 @@ inline NRVec<double>& NRVec<double>::operator-=(const double &a) {
* @return reference to the modified vector
******************************************************************************/
template<>
inline NRVec<complex<double> >& NRVec<complex<double> >::operator-=(const complex<double> &a) {
inline NRVec<std::complex<double> >& NRVec<std::complex<double> >::operator-=(const std::complex<double> &a) {
copyonwrite();
#ifdef CUDALA
if(location == cpu){
@ -1095,7 +1096,7 @@ inline NRVec<complex<double> >& NRVec<complex<double> >::operator-=(const comple
cblas_zaxpy(nn, &CMONE, &a, 0, v, 1);
#ifdef CUDALA
}else{
complex<double> *d = gpuputcomplex(a);
std::complex<double> *d = gpuputcomplex(a);
cublasZaxpy(nn, CUMONE, (cuDoubleComplex *)d, 0, (cuDoubleComplex *)v, 1);
TEST_CUBLAS("cublasZaxpy");
gpufree(d);
@ -1137,7 +1138,7 @@ inline NRVec<double>& NRVec<double>::operator+=(const NRVec<double> &rhs) {
* @return reference to the modified vector
******************************************************************************/
template<>
inline NRVec<complex<double> >& NRVec<complex<double> >::operator+=(const NRVec<complex<double> > &rhs) {
inline NRVec<std::complex<double> >& NRVec<std::complex<double> >::operator+=(const NRVec<std::complex<double> > &rhs) {
#ifdef DEBUG
if (nn != rhs.nn) laerror("incompatible dimensions");
#endif
@ -1189,7 +1190,7 @@ inline NRVec<double> & NRVec<double>::operator-=(const NRVec<double> &rhs) {
* @return reference to the modified vector
******************************************************************************/
template<>
inline NRVec<complex<double> >& NRVec<complex<double> >::operator-=(const NRVec<complex<double> > &rhs) {
inline NRVec<std::complex<double> >& NRVec<std::complex<double> >::operator-=(const NRVec<std::complex<double> > &rhs) {
#ifdef DEBUG
if (nn != rhs.nn) laerror("incompatible dimensions");
#endif
@ -1237,7 +1238,7 @@ inline NRVec<double>& NRVec<double>::operator*=(const double &a) {
* @return reference to the modified vector
******************************************************************************/
template<>
inline NRVec<complex<double> >& NRVec<complex<double> >::operator*=(const complex<double> &a) {
inline NRVec<std::complex<double> >& NRVec<std::complex<double> >::operator*=(const std::complex<double> &a) {
copyonwrite();
#ifdef CUDALA
if(location == cpu){
@ -1285,11 +1286,11 @@ inline const double NRVec<double>::operator*(const NRVec<double> &rhs) const {
* @return \f$\sum_{i=1}^N\overbar{\vec{x}_i}\cdot\vec{y}_i\f$
******************************************************************************/
template<>
inline const complex<double> NRVec<complex<double> >::operator*(const NRVec< complex<double> > &rhs) const {
inline const std::complex<double> NRVec<std::complex<double> >::operator*(const NRVec< std::complex<double> > &rhs) const {
#ifdef DEBUG
if(nn != rhs.nn) laerror("incompatible dimensions");
#endif
complex<double> dot;
std::complex<double> dot;
SAME_LOC(*this, rhs);
#ifdef CUDALA
if(location == cpu){
@ -1299,7 +1300,7 @@ inline const complex<double> NRVec<complex<double> >::operator*(const NRVec< com
}else{
const cuDoubleComplex val = cublasZdotc(nn, (cuDoubleComplex*)v, 1, (cuDoubleComplex*)rhs.v, 1);
TEST_CUBLAS("cublasZdotc");
dot = complex<double>(cuCreal(val), cuCimag(val));
dot = std::complex<double>(cuCreal(val), cuCimag(val));
}
#endif
return dot;
@ -1324,8 +1325,8 @@ inline const double NRVec<double>::dot(const double *y, const int stride) const
* @return \f$\sum_{i=1}^N\vec{x}_{i}\cdot \overbar{y_{\mathrm{stride}\cdot(i-1) + 1}}\f$
******************************************************************************/
template<>
inline const complex<double> NRVec<complex<double> >::dot(const complex<double> *y, const int stride) const {
complex<double> dot;
inline const std::complex<double> NRVec<std::complex<double> >::dot(const std::complex<double> *y, const int stride) const {
std::complex<double> dot;
NOT_GPU(*this);
cblas_zdotc_sub(nn, y, stride, v, 1, &dot);
return dot;
@ -1358,7 +1359,7 @@ inline const double NRVec<double>::asum() const {
* @return the value of this sum
******************************************************************************/
template<>
inline const double NRVec<complex<double> >::asum() const {
inline const double NRVec<std::complex<double> >::asum() const {
double ret(0.0);
#ifdef CUDALA
if(location == cpu){
@ -1398,7 +1399,7 @@ inline const double NRVec<double>::norm() const {
* @return \f$\sum_{i=1}^N\left|\vec{x}_i\right|^2\f$
******************************************************************************/
template<>
inline const double NRVec< complex<double> >::norm() const {
inline const double NRVec< std::complex<double> >::norm() const {
double ret(0.);
#ifdef CUDALA
if(location == cpu){
@ -1469,8 +1470,8 @@ inline const double NRVec<double>::amin() const {
* @return \f$\vec{v}_{j}\f$ which maximizes \f$\left\{\left|\Re{}\vec{v}_{i}\right|+\left|\Im{}\vec{v}_{i}\right|\right}\f$
******************************************************************************/
template<>
inline const complex<double> NRVec<complex<double> >::amax() const {
complex<double> ret(0., 0.);
inline const std::complex<double> NRVec<std::complex<double> >::amax() const {
std::complex<double> ret(0., 0.);
#ifdef CUDALA
if(location == cpu){
#endif
@ -1479,7 +1480,7 @@ inline const complex<double> NRVec<complex<double> >::amax() const {
}else{
const int pozice = cublasIzamax(nn, (cuDoubleComplex*)v, 1) - 1;
TEST_CUBLAS("cublasIzamax");
gpuget(1, sizeof(complex<double>), v + pozice, &ret);
gpuget(1, sizeof(std::complex<double>), v + pozice, &ret);
}
#endif
return ret;
@ -1491,15 +1492,15 @@ inline const complex<double> NRVec<complex<double> >::amax() const {
* @return \f$\vec{v}_{j}\f$ which minimizes \f$\left\{\left|\Re{}\vec{v}_{i}\right|+\left|\Im{}\vec{v}_{i}\right|\right}\f$
******************************************************************************/
template<>
inline const complex<double> NRVec<complex<double> >::amin() const {
complex<double> ret(0., 0.);
inline const std::complex<double> NRVec<std::complex<double> >::amin() const {
std::complex<double> ret(0., 0.);
#ifdef CUDALA
if(location == cpu){
#endif
// izamin seems not to be supported
int index(0);
double val(0.0), min_val(std::numeric_limits<double>::max());
complex<double> z_val(0.0, 0.0);
std::complex<double> z_val(0.0, 0.0);
for(register int i=0; i < nn; i++){
z_val = v[i];
@ -1511,7 +1512,7 @@ inline const complex<double> NRVec<complex<double> >::amin() const {
}else{
const int pozice = cublasIzamin(nn, (cuDoubleComplex*)v, 1) - 1;
TEST_CUBLAS("cublasIzamin");
gpuget(1, sizeof(complex<double>), v + pozice, &ret);
gpuget(1, sizeof(std::complex<double>), v + pozice, &ret);
}
#endif
return ret;

View File

@ -82,8 +82,8 @@ public:
Vec3& fast_normalize(void);
const Vec3 operator*(const Mat3<T> &rhs) const;
//C-style IO
void fprintf(FILE *f, const char *format) const {::fprintf(f,format,q[0],q[1],q[2]);};
void sprintf(char *f, const char *format) const {::sprintf(f,format,q[0],q[1],q[2]);};
int fprintf(FILE *f, const char *format) const {return ::fprintf(f,format,q[0],q[1],q[2]);};
int sprintf(char *f, const char *format) const {return ::sprintf(f,format,q[0],q[1],q[2]);};
int fscanf(FILE *f, const char *format) const {return ::fscanf(f,format,q[0],q[1],q[2]);};
int sscanf(char *f, const char *format) const {return ::sscanf(f,format,q[0],q[1],q[2]);};
};
@ -141,7 +141,7 @@ public:
const Mat3 transpose() const {Mat3 r(*this); r.transposeme(); return r;};
const Mat3 inverse() const;
//C-style IO
void fprintf(FILE *f, const char *format) const {::fprintf(f,format,q[0][0],q[0][1],q[0][2]); ::fprintf(f,format,q[1][0],q[1][1],q[1][2]); ::fprintf(f,format,q[2][0],q[2][1],q[2][2]);};
int fprintf(FILE *f, const char *format) const {int n= ::fprintf(f,format,q[0][0],q[0][1],q[0][2]); n+=::fprintf(f,format,q[1][0],q[1][1],q[1][2]); n+=::fprintf(f,format,q[2][0],q[2][1],q[2][2]); return n;};
int fscanf(FILE *f, const char *format) const {return ::fscanf(f,format,q[0][0],q[0][1],q[0][2]) + ::fscanf(f,format,q[1][0],q[1][1],q[1][2]) + ::fscanf(f,format,q[2][0],q[2][1],q[2][2]);};
};