diff --git a/la_traits.h b/la_traits.h index f64e9ff..90beb60 100644 --- a/la_traits.h +++ b/la_traits.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,7 @@ template class NRSMat; template class NRSMat_from1; template class SparseMat; template class SparseSMat; +template class CSRMat; typedef class {} Dummy_type; @@ -218,12 +220,13 @@ static inline normtype norm (const complex &x) {return std::abs(x);} static inline void axpy (complex &s, const complex &x, const complex &c) {s+=x*c;} static inline void get(int fd, complex &x, bool dimensions=0, bool transp=0) {if(sizeof(complex)!=read(fd,&x,sizeof(complex))) laerror("read error");} static inline void put(int fd, const complex &x, bool dimensions=0, bool transp=0) {if(sizeof(complex)!=write(fd,&x,sizeof(complex))) laerror("write error");} -static void multiget(unsigned int n,int fd, complex *x, bool dimensions=0){if((ssize_t)(n*sizeof(complex))!=read(fd,x,n*sizeof(complex))) laerror("read error");} -static void multiput(unsigned int n, int fd, const complex *x, bool dimensions=0) {if((ssize_t)(n*sizeof(complex))!=write(fd,x,n*sizeof(complex))) laerror("write error");} +static void multiget(size_t n,int fd, complex *x, bool dimensions=0){ssize_t r=read(fd,x,n*sizeof(complex)); if((ssize_t)(n*sizeof(complex))!=r) {std::cout<<"read returned "< *x, bool dimensions=0) {ssize_t r=write(fd,x,n*sizeof(complex)); if((ssize_t)(n*sizeof(complex))!=r) {std::cout<<"write returned "< *dest, complex *src, unsigned int n) {memcpy(dest,src,n*sizeof(complex));} static void clear(complex *dest, unsigned int n) {memset(dest,0,n*sizeof(complex));} static void copyonwrite(complex &x) {}; static void clearme(complex &x) {x=0;}; +static void deallocate(complex &x) {}; static inline complex conjugate(const complex &x) {return complex(x.real(),-x.imag());}; static inline C realpart(const complex &x) {return x.real();} static inline C imagpart(const complex &x) {return x.imag();} @@ -245,12 +248,13 @@ static inline normtype norm (const C &x) {return std::abs(x);} static inline void axpy (C &s, const C &x, const C &c) {s+=x*c;} static inline void put(int fd, const C &x, bool dimensions=0, bool transp=0) {if(sizeof(C)!=write(fd,&x,sizeof(C))) laerror("write error");} static inline void get(int fd, C &x, bool dimensions=0, bool transp=0) {if(sizeof(C)!=read(fd,&x,sizeof(C))) laerror("read error");} -static void multiput(unsigned int n,int fd, const C *x, bool dimensions=0){if((ssize_t)(n*sizeof(C))!=write(fd,x,n*sizeof(C))) laerror("write error");} -static void multiget(unsigned int n, int fd, C *x, bool dimensions=0) {if((ssize_t)(n*sizeof(C))!=read(fd,x,n*sizeof(C))) laerror("read error");} +static void multiget(size_t n,int fd, C *x, bool dimensions=0){ssize_t r=read(fd,x,n*sizeof(C)); if((ssize_t)(n*sizeof(C))!=r) {std::cout<<"read returned "< &x) {x=0;}; +static void clearme(C &x) {x=0;}; +static void deallocate(C &x) {}; static inline C conjugate(const C &x) {return x;}; static inline C realpart(const C &x) {return x;} static inline C imagpart(const C &x) {return 0;} @@ -277,12 +281,13 @@ static inline normtype norm (const X &x) {return x.norm();} \ static inline void axpy (X&s, const X &x, const C c) {s.axpy(c,x);} \ static void put(int fd, const X &x, bool dimensions=1, bool transp=0) {x.put(fd,dimensions,transp);} \ static void get(int fd, X &x, bool dimensions=1, bool transp=0) {x.get(fd,dimensions,transp);} \ -static void multiput(unsigned int n,int fd, const X *x, bool dimensions=1) {for(unsigned int i=0; i *x, bool dimensions=1) {for(unsigned int i=0; i *x, bool dimensions=1) {for(size_t i=0; i *x, bool dimensions=1) {for(size_t i=0; i &x) {x.copyonwrite();}\ static void clearme(X &x) {x.clear();}\ +static void deallocate(X &x) {x.dealloc();}\ }; @@ -292,6 +297,7 @@ generate_traits(NRMat_from1) generate_traits(NRVec) generate_traits(SparseMat) generate_traits(SparseSMat) //product leading to non-symmetric result not implemented +generate_traits(CSRMat) #undef generate_traits @@ -311,12 +317,13 @@ static inline normtype norm (const X &x) {return x.norm();} \ static inline void axpy (X&s, const X &x, const C c) {s.axpy(c,x);} \ static void put(int fd, const X &x, bool dimensions=1, bool transp=0) {x.put(fd,dimensions);} \ static void get(int fd, X &x, bool dimensions=1, bool transp=0) {x.get(fd,dimensions);} \ -static void multiput(unsigned int n,int fd, const X *x, bool dimensions=1) {for(unsigned int i=0; i *x, bool dimensions=1) {for(unsigned int i=0; i *x, bool dimensions=1) {for(size_t i=0; i *x, bool dimensions=1) {for(size_t i=0; i &x) {x.copyonwrite();} \ static void clearme(X &x) {x.clear();} \ +static void deallocate(X &x) {x.dealloc();} \ }; generate_traits_smat(NRSMat)