diff --git a/mat.cc b/mat.cc index aa1e482..0c0fae2 100644 --- a/mat.cc +++ b/mat.cc @@ -755,7 +755,7 @@ void NRMat::diagmultr(const NRVec &rhs) if (mm != rhs.size()) laerror("incompatible matrix dimension in diagmultr"); #endif copyonwrite(); - for (int i=0; i >::diagmultr(const NRVec< complex > &rhs) if (mm != rhs.size()) laerror("incompatible matrix dimension in diagmultl"); #endif copyonwrite(); - for (int i=0; i &x); \ -template istream & operator>>(istream &s, NRMat< T > &x); \ - -INSTANTIZE(double) -INSTANTIZE(complex) -INSTANTIZE(int) -INSTANTIZE(short) -INSTANTIZE(char) -INSTANTIZE(unsigned char) -INSTANTIZE(unsigned long) -INSTANTIZE(unsigned int) - - -export template -ostream& operator<<(ostream &s, const NRMat &x) - { - int i,j,n,m; - n=x.nrows(); - m=x.ncols(); - s << n << ' ' << m << '\n'; - for(i=0;i::IOtype) x[i][j] << (j==m-1 ? '\n' : ' '); // endl cannot be used in the conditional expression, since it is an overloaded function - } - return s; - } - -export template -istream& operator>>(istream &s, NRMat &x) - { - int i,j,n,m; - s >> n >> m; - x.resize(n,m); - typename LA_traits_io::IOtype tmp; - for(i=0;i>tmp; x[i][j]=tmp;} - return s; - } //direct sum and product (oplus, otimes) to be done - - - - - - - - - - - ////////////////////////////////////////////////////////////////////////////// //// forced instantization in the corresponding object file template class NRMat; diff --git a/mat.h b/mat.h index 93209c0..85e4b0c 100644 --- a/mat.h +++ b/mat.h @@ -548,8 +548,31 @@ return r; // I/O -template extern ostream& operator<<(ostream &s, const NRMat &x); -template extern istream& operator>>(istream &s, NRMat &x); +template +ostream& operator<<(ostream &s, const NRMat &x) + { + int i,j,n,m; + n=x.nrows(); + m=x.ncols(); + s << n << ' ' << m << '\n'; + for(i=0;i::IOtype) x[i][j] << (j==m-1 ? '\n' : ' '); // endl cannot be used in the conditional expression, since it is an overloaded function + } + return s; + } + +template +istream& operator>>(istream &s, NRMat &x) + { + int i,j,n,m; + s >> n >> m; + x.resize(n,m); + typename LA_traits_io::IOtype tmp; + for(i=0;i>tmp; x[i][j]=tmp;} + return s; + } + //optional indexing from 1 //all possible constructors have to be given explicitly, other stuff is inherited diff --git a/smat.cc b/smat.cc index 1d27661..ab4c9dc 100644 --- a/smat.cc +++ b/smat.cc @@ -358,50 +358,6 @@ void NRSMat< complex >::axpy(const complex alpha, } -export template -ostream& operator<<(ostream &s, const NRSMat &x) - { - int i,j,n; - n=x.nrows(); - s << n << ' ' << n << '\n'; - for(i=0;i::IOtype)x(i,j) << (j==n-1 ? '\n' : ' '); - } - return s; - } - - -export template -istream& operator>>(istream &s, NRSMat &x) - { - int i,j,n,m; - s >> n >> m; - if(n!=m) laerror("input symmetric matrix not square"); - x.resize(n); - typename LA_traits_io::IOtype tmp; - for(i=0;i>tmp; x(i,j)=tmp;} - return s; - } - - - - -////////////////////////////////////////////////////////////////////////////// -//// forced instantization in the corespoding object file -#define INSTANTIZE(T) \ -template ostream & operator<<(ostream &s, const NRSMat< T > &x); \ -template istream & operator>>(istream &s, NRSMat< T > &x); \ - -INSTANTIZE(double) -INSTANTIZE(complex) -INSTANTIZE(int) -INSTANTIZE(short) -INSTANTIZE(char) -INSTANTIZE(unsigned int) -INSTANTIZE(unsigned long) - - ////////////////////////////////////////////////////////////////////////////// ////// forced instantization in the corresponding object file diff --git a/smat.h b/smat.h index f13cf5d..d642936 100644 --- a/smat.h +++ b/smat.h @@ -514,8 +514,32 @@ return r; } // I/O -template extern ostream& operator<<(ostream &s, const NRSMat &x); -template extern istream& operator>>(istream &s, NRSMat &x); +template +ostream& operator<<(ostream &s, const NRSMat &x) + { + int i,j,n; + n=x.nrows(); + s << n << ' ' << n << '\n'; + for(i=0;i::IOtype)x(i,j) << (j==n-1 ? '\n' : ' '); + } + return s; + } + + +template +istream& operator>>(istream &s, NRSMat &x) + { + int i,j,n,m; + s >> n >> m; + if(n!=m) laerror("input symmetric matrix not square"); + x.resize(n); + typename LA_traits_io::IOtype tmp; + for(i=0;i>tmp; x(i,j)=tmp;} + return s; + } + // generate operators: SMat + a, a + SMat, SMat * a NRVECMAT_OPER(SMat,+) diff --git a/sparsemat.cc b/sparsemat.cc index e9ab6b6..dfba048 100644 --- a/sparsemat.cc +++ b/sparsemat.cc @@ -19,48 +19,6 @@ static inline void SWAP(T &a, T &b) -export template -ostream& operator<<(ostream &s, const SparseMat &x) - { - SPMatindex n,m; - n=x.nrows(); - m=x.ncols(); - s << (int)n << ' ' << (int)m << '\n'; - matel *list=x.getlist(); - while(list) - { - s << (int)list->row << ' ' << (int)list->col << ' ' << (typename LA_traits_io::IOtype)list->elem << '\n'; - list=list->next; - } - s << "-1 -1\n"; - return s; - } - -export template -istream& operator>>(istream &s, SparseMat &x) - { - int i,j; - int n,m; - matel *l=NULL; - s >> n >> m; - x.resize(n,m); - s >> i >> j; - while(i>=0 && j>=0) - { - matel *ll = l; - l= new matel; - l->next= ll; - l->row=i; - l->col=j; - typename LA_traits_io::IOtype tmp; - s >> tmp; - l->elem=tmp; - s >> i >> j; - } - x.setlist(l); - return s; - } - extern "C" { extern ssize_t read(int, void *, size_t); extern ssize_t write(int, const void *, size_t); @@ -1309,8 +1267,6 @@ return *this; template SparseMat & SparseMat::oplusequal(const SparseMat &rhs);\ template SparseMat & SparseMat::oplusequal(const NRMat &rhs);\ template SparseMat & SparseMat::oplusequal(const NRSMat &rhs);\ -template ostream& operator<<(ostream &s, const SparseMat &x); \ -template istream& operator>>(istream &s, SparseMat &x); \ template void SparseMat::get(int fd, bool dimen, bool transp); \ template void SparseMat::put(int fd, bool dimen, bool transp) const; \ template void SparseMat::copyonwrite(); \ diff --git a/sparsemat.h b/sparsemat.h index 256c258..1cf9ad2 100644 --- a/sparsemat.h +++ b/sparsemat.h @@ -137,11 +137,48 @@ template inline const NRMat SparseMat::operator*(const NRMat &rhs) const {NRMat result(nn,rhs.ncols()); result.gemm((T)0,*this,'n',rhs,'n',(T)1); return result;}; -template - extern istream& operator>>(istream &s, SparseMat &x); +template +ostream& operator<<(ostream &s, const SparseMat &x) + { + SPMatindex n,m; + n=x.nrows(); + m=x.ncols(); + s << (int)n << ' ' << (int)m << '\n'; + matel *list=x.getlist(); + while(list) + { + s << (int)list->row << ' ' << (int)list->col << ' ' << (typename LA_traits_io::IOtype)list->elem << '\n'; + list=list->next; + } + s << "-1 -1\n"; + return s; + } + +template +istream& operator>>(istream &s, SparseMat &x) + { + int i,j; + int n,m; + matel *l=NULL; + s >> n >> m; + x.resize(n,m); + s >> i >> j; + while(i>=0 && j>=0) + { + matel *ll = l; + l= new matel; + l->next= ll; + l->row=i; + l->col=j; + typename LA_traits_io::IOtype tmp; + s >> tmp; + l->elem=tmp; + s >> i >> j; + } + x.setlist(l); + return s; + } -template - extern ostream& operator<<(ostream &s, const SparseMat &x); //destructor template diff --git a/vec.cc b/vec.cc index 9891398..7fe10e9 100644 --- a/vec.cc +++ b/vec.cc @@ -15,8 +15,6 @@ extern ssize_t write(int, const void *, size_t); ////////////////////////////////////////////////////////////////////////////// //// forced instantization in the corespoding object file #define INSTANTIZE(T) \ -template ostream & operator<<(ostream &s, const NRVec< T > &x); \ -template istream & operator>>(istream &s, NRVec< T > &x); \ template void NRVec::put(int fd, bool dim, bool transp) const; \ template void NRVec::get(int fd, bool dim, bool transp); \ @@ -54,30 +52,6 @@ NRVec::NRVec(const NRMat &rhs) -// formatted I/O -template -ostream & operator<<(ostream &s, const NRVec &x) -{ - int i, n; - - n = x.size(); - s << n << endl; - for(i=0; i::IOtype)x[i] << (i == n-1 ? '\n' : ' '); - return s; -} - -template -istream & operator>>(istream &s, NRVec &x) -{ - int i,n; - - s >> n; - x.resize(n); - typename LA_traits_io::IOtype tmp; - for(i=0; i> tmp; x[i]=tmp;} - return s; -} - //raw I/O template diff --git a/vec.h b/vec.h index e01fb7b..a8c40c5 100644 --- a/vec.h +++ b/vec.h @@ -119,8 +119,30 @@ public: #include "smat.h" #include "sparsemat.h" -template ostream & operator<<(ostream &s, const NRVec &x); -template istream & operator>>(istream &s, NRVec &x); +// formatted I/O +template +ostream & operator<<(ostream &s, const NRVec &x) +{ + int i, n; + + n = x.size(); + s << n << endl; + for(i=0; i::IOtype)x[i] << (i == n-1 ? '\n' : ' '); + return s; +} + +template +istream & operator>>(istream &s, NRVec &x) +{ + int i,n; + + s >> n; + x.resize(n); + typename LA_traits_io::IOtype tmp; + for(i=0; i> tmp; x[i]=tmp;} + return s; +} + // INLINES