diff --git a/la_traits.h b/la_traits.h index 22e76c2..054f4e3 100644 --- a/la_traits.h +++ b/la_traits.h @@ -392,10 +392,10 @@ static inline bool bigger(const X &x, const X &y) {return x>y;} \ static inline bool smaller(const X &x, const X &y) {return 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(size_t n,int fd, const X *x, bool dimensions=1) {for(size_t i=0; i *x, bool dimensions=1) {for(size_t i=0; i &x, bool dimensions=1, bool transp=0, bool orcaformat=false) {x.put(fd,dimensions,transp,orcaformat);} \ +static void get(int fd, X &x, bool dimensions=1, bool transp=0, bool orcaformat=false) {x.get(fd,dimensions,transp,orcaformat);} \ +static void multiput(size_t n,int fd, const X *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i *dest, X *src, size_t n) {for(size_t i=0; i *dest, size_t n) {for(size_t i=0; i &x) {x.copyonwrite();}\ @@ -435,10 +435,10 @@ static inline bool bigger(const C &x, const C &y) {return x>y;} \ static inline bool smaller(const C &x, const C &y) {return 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(size_t n,int fd, const X *x, bool dimensions=1) {for(size_t i=0; i *x, bool dimensions=1) {for(size_t i=0; i &x, bool dimensions=1, bool transp=0, bool orcaformat=false) {x.put(fd,dimensions,false,orcaformat);} \ +static void get(int fd, X &x, bool dimensions=1, bool transp=0, bool orcaformat=false) {x.get(fd,dimensions,false,orcaformat);} \ +static void multiput(size_t n,int fd, const X *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i &x) {x.copyonwrite();} \ diff --git a/mat.cc b/mat.cc index 05cb918..df373e9 100644 --- a/mat.cc +++ b/mat.cc @@ -121,12 +121,12 @@ const NRVec NRMat::row(const int i, int l) const { * @see NRVec::put() ******************************************************************************/ template -void NRMat::put(int fd, bool dim, bool transp) const { +void NRMat::put(int fd, bool dim, bool transp, bool orcaformat) const { #ifdef CUDALA if(location != cpu) { NRMat tmp = *this; tmp.moveto(cpu); - tmp.put(fd, dim, transp); + tmp.put(fd, dim, transp, orcaformat); return; } #endif @@ -134,6 +134,11 @@ void NRMat::put(int fd, bool dim, bool transp) const { if(dim){ if(sizeof(int) != write(fd,&(transp?mm:nn),sizeof(int))) laerror("write failed"); if(sizeof(int) != write(fd,&(transp?nn:mm),sizeof(int))) laerror("write failed"); + if(orcaformat) + { + int tmp=sizeof(T); + if(sizeof(int) != write(fd,&tmp,sizeof(int))) laerror("write failed"); + } } if(transp){ //not particularly efficient @@ -167,12 +172,12 @@ void NRMat::put(int fd, bool dim, bool transp) const { * @see NRVec::get(), copyonwrite() ******************************************************************************/ template -void NRMat::get(int fd, bool dim, bool transp){ +void NRMat::get(int fd, bool dim, bool transp, bool orcaformat){ #ifdef CUDALA if(location != cpu){ NRMat tmp; tmp.moveto(cpu); - tmp.get(fd, dim, transp); + tmp.get(fd, dim, transp,orcaformat); tmp.moveto(getlocation()); *this = tmp; return; @@ -183,6 +188,12 @@ void NRMat::get(int fd, bool dim, bool transp){ if(dim){ if(sizeof(int) != read(fd, &nn0, sizeof(int))) laerror("read failed"); if(sizeof(int) != read(fd, &mm0, sizeof(int))) laerror("read failed"); + if(orcaformat) + { + int tmp; + if(sizeof(int) != read(fd, &tmp, sizeof(int))) laerror("read failed"); + if(tmp!=sizeof(T)) laerror("mismatch in orca format"); + } if(transp) resize(mm0, nn0); else resize(nn0, mm0); }else{ copyonwrite(); diff --git a/mat.h b/mat.h index c3e8561..eba5a8e 100644 --- a/mat.h +++ b/mat.h @@ -305,9 +305,9 @@ public: inline size_t size() const; //! unformatted input - void get(int fd, bool dimensions = 1, bool transposed = false); + void get(int fd, bool dimensions = 1, bool transposed = false, bool orcaformat=false); //! unformatted output - void put(int fd, bool dimensions = 1, bool transposed = false) const; + void put(int fd, bool dimensions = 1, bool transposed = false, bool orcaformat=false) const; //! formatted output void fprintf(FILE *f, const char *format, const int modulo) const; //! formatted input diff --git a/smat.cc b/smat.cc index aaceec8..7b93aa2 100644 --- a/smat.cc +++ b/smat.cc @@ -41,12 +41,12 @@ namespace LA { * @see NRMat::get(), NRSMat::copyonwrite() ******************************************************************************/ template -void NRSMat::put(int fd, bool dim, bool transp) const { +void NRSMat::put(int fd, bool dim, bool transp, bool orcaformat) const { #ifdef CUDALA if(location != cpu){ NRSMat tmp= *this; tmp.moveto(cpu); - tmp.put(fd,dim,transp); + tmp.put(fd,dim,transp,orcaformat); return; } #endif @@ -54,6 +54,11 @@ void NRSMat::put(int fd, bool dim, bool transp) const { if(dim){ if(sizeof(int) != write(fd,&nn,sizeof(int))) laerror("cannot write"); if(sizeof(int) != write(fd,&nn,sizeof(int))) laerror("cannot write"); + if(orcaformat) + { + int tmp=sizeof(T); + if(sizeof(int) != write(fd,&tmp,sizeof(int))) laerror("cannot write"); + } } LA_traits::multiput((size_t)nn*(nn+1)/2,fd,v,dim); } @@ -66,12 +71,12 @@ void NRSMat::put(int fd, bool dim, bool transp) const { * @see NRSMat::put(), NRSMat::copyonwrite() ******************************************************************************/ template -void NRSMat::get(int fd, bool dim, bool transp) { +void NRSMat::get(int fd, bool dim, bool transp, bool orcaformat) { #ifdef CUDALA if(location != cpu){ NRSMat tmp; tmp.moveto(cpu); - tmp.get(fd,dim,transp); + tmp.get(fd,dim,transp,orcaformat); tmp.moveto(location); *this = tmp; return; @@ -82,6 +87,12 @@ void NRSMat::get(int fd, bool dim, bool transp) { errno = 0; if(dim){ if(2*sizeof(int) != read(fd,&nn0,2*sizeof(int))) laerror("cannot read"); + if(orcaformat) + { + int tmp; + if(sizeof(int) != read(fd,&tmp,sizeof(int))) laerror("cannot read"); + if(tmp!=sizeof(T)) laerror("mismatch in orca format"); + } resize(nn0[0]); }else{ copyonwrite(); diff --git a/smat.h b/smat.h index 96eb517..e795119 100644 --- a/smat.h +++ b/smat.h @@ -183,8 +183,8 @@ public: const T trace() const; - void get(int fd, bool dimensions = 1, bool transp = 0); - void put(int fd, bool dimensions = 1, bool transp = 0) const; + void get(int fd, bool dimensions = 1, bool transp = 0, bool orcaformat=false); + void put(int fd, bool dimensions = 1, bool transp = 0, bool orcaformat=false) const; void copyonwrite(bool detachonly=false, bool deep=true); diff --git a/vec.h b/vec.h index 3b8ebbe..2623a29 100644 --- a/vec.h +++ b/vec.h @@ -455,12 +455,12 @@ public: //! routine for formatted output void fprintf(FILE *f, const char *format, const int modulo) const; //! routine for unformatted output - void put(int fd, bool dimensions=1, bool transp=0) const; + void put(int fd, bool dimensions=1, bool transp=0, bool orca_format=false) const; //! routine for formatted input void fscanf(FILE *f, const char *format); //! routine for unformatted input - void get(int fd, bool dimensions=1, bool transp=0); + void get(int fd, bool dimensions=1, bool transp=0, bool orca_format=false); //! constructor creating vector from sparse matrix explicit NRVec(const SparseMat &rhs); @@ -2015,12 +2015,12 @@ inline const std::complex NRVec >::amin() const { * @see NRMat::put() ******************************************************************************/ template -void NRVec::put(int fd, bool dim, bool transp) const { +void NRVec::put(int fd, bool dim, bool transp, bool orcaformat) const { #ifdef CUDALA if(location != cpu){ NRVec tmp = *this; tmp.moveto(cpu); - tmp.put(fd,dim,transp); + tmp.put(fd,dim,transp,orcaformat); return; } #endif @@ -2028,7 +2028,15 @@ void NRVec::put(int fd, bool dim, bool transp) const { int pad(1); //align at least 8-byte if(dim){ if(sizeof(int) != write(fd,&nn,sizeof(int))) laerror("write failed"); - if(sizeof(int) != write(fd,&pad,sizeof(int))) laerror("write failed"); + if(!orcaformat) + { + if(sizeof(int) != write(fd,&pad,sizeof(int))) laerror("write failed"); + } + if(orcaformat) + { + int tmp=sizeof(T); + if(sizeof(int) != write(fd,&tmp,sizeof(int))) laerror("write failed"); + } } LA_traits::multiput(nn,fd,v,dim); } @@ -2041,12 +2049,12 @@ void NRVec::put(int fd, bool dim, bool transp) const { * @see NRMat::get(), copyonwrite() ******************************************************************************/ template -void NRVec::get(int fd, bool dim, bool transp) { +void NRVec::get(int fd, bool dim, bool transp, bool orcaformat) { #ifdef CUDALA if(location != cpu){ NRVec tmp; tmp.moveto(cpu); - tmp.get(fd,dim,transp); + tmp.get(fd,dim,transp,orcaformat); tmp.moveto(location); *this = tmp; return; @@ -2055,7 +2063,14 @@ void NRVec::get(int fd, bool dim, bool transp) { int nn0[2]; //align at least 8-byte errno = 0; if(dim){ - if(2*sizeof(int) != read(fd,&nn0,2*sizeof(int))) laerror("read failed"); + int ndims=orcaformat?1:2; + if(ndims*sizeof(int) != read(fd,&nn0,ndims*sizeof(int))) laerror("read failed"); + if(orcaformat) + { + int tmp; + if(sizeof(int) != read(fd,&tmp,sizeof(int))) laerror("read failed"); + if(tmp!=sizeof(T)) laerror("mismatch in orca format"); + } resize(nn0[0]); }else{ copyonwrite();