*** empty log message ***
This commit is contained in:
parent
f4d3ad691e
commit
5633366c1f
55
mat.cc
55
mat.cc
@ -755,7 +755,7 @@ void NRMat<double>::diagmultr(const NRVec<double> &rhs)
|
|||||||
if (mm != rhs.size()) laerror("incompatible matrix dimension in diagmultr");
|
if (mm != rhs.size()) laerror("incompatible matrix dimension in diagmultr");
|
||||||
#endif
|
#endif
|
||||||
copyonwrite();
|
copyonwrite();
|
||||||
for (int i=0; i<mm; i++) cblas_dscal(nn, rhs[i], (*this)[i], mm);
|
for (int i=0; i<mm; i++) cblas_dscal(nn, rhs[i], &(*this)(0,i), mm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -767,7 +767,7 @@ void NRMat< complex<double> >::diagmultr(const NRVec< complex<double> > &rhs)
|
|||||||
if (mm != rhs.size()) laerror("incompatible matrix dimension in diagmultl");
|
if (mm != rhs.size()) laerror("incompatible matrix dimension in diagmultl");
|
||||||
#endif
|
#endif
|
||||||
copyonwrite();
|
copyonwrite();
|
||||||
for (int i=0; i<mm; i++) cblas_zscal(nn, &rhs[i], (*this)[i], mm);
|
for (int i=0; i<mm; i++) cblas_zscal(nn, &rhs[i], &(*this)(0,i), mm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1049,62 +1049,11 @@ return divide?NULL:&r[0];
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//// forced instantization in the corespoding object file
|
|
||||||
#define INSTANTIZE(T) \
|
|
||||||
template ostream & operator<<(ostream &s, const NRMat< T > &x); \
|
|
||||||
template istream & operator>>(istream &s, NRMat< T > &x); \
|
|
||||||
|
|
||||||
INSTANTIZE(double)
|
|
||||||
INSTANTIZE(complex<double>)
|
|
||||||
INSTANTIZE(int)
|
|
||||||
INSTANTIZE(short)
|
|
||||||
INSTANTIZE(char)
|
|
||||||
INSTANTIZE(unsigned char)
|
|
||||||
INSTANTIZE(unsigned long)
|
|
||||||
INSTANTIZE(unsigned int)
|
|
||||||
|
|
||||||
|
|
||||||
export template <typename T>
|
|
||||||
ostream& operator<<(ostream &s, const NRMat<T> &x)
|
|
||||||
{
|
|
||||||
int i,j,n,m;
|
|
||||||
n=x.nrows();
|
|
||||||
m=x.ncols();
|
|
||||||
s << n << ' ' << m << '\n';
|
|
||||||
for(i=0;i<n;i++)
|
|
||||||
{
|
|
||||||
for(j=0; j<m;j++) s << (typename LA_traits_io<T>::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 <typename T>
|
|
||||||
istream& operator>>(istream &s, NRMat<T> &x)
|
|
||||||
{
|
|
||||||
int i,j,n,m;
|
|
||||||
s >> n >> m;
|
|
||||||
x.resize(n,m);
|
|
||||||
typename LA_traits_io<T>::IOtype tmp;
|
|
||||||
for(i=0;i<n;i++) for(j=0; j<m;j++) { s>>tmp; x[i][j]=tmp;}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
//direct sum and product (oplus, otimes) to be done
|
//direct sum and product (oplus, otimes) to be done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//// forced instantization in the corresponding object file
|
//// forced instantization in the corresponding object file
|
||||||
template class NRMat<double>;
|
template class NRMat<double>;
|
||||||
|
27
mat.h
27
mat.h
@ -548,8 +548,31 @@ return r;
|
|||||||
|
|
||||||
|
|
||||||
// I/O
|
// I/O
|
||||||
template <typename T> extern ostream& operator<<(ostream &s, const NRMat<T> &x);
|
template <typename T>
|
||||||
template <typename T> extern istream& operator>>(istream &s, NRMat<T> &x);
|
ostream& operator<<(ostream &s, const NRMat<T> &x)
|
||||||
|
{
|
||||||
|
int i,j,n,m;
|
||||||
|
n=x.nrows();
|
||||||
|
m=x.ncols();
|
||||||
|
s << n << ' ' << m << '\n';
|
||||||
|
for(i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
for(j=0; j<m;j++) s << (typename LA_traits_io<T>::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 <typename T>
|
||||||
|
istream& operator>>(istream &s, NRMat<T> &x)
|
||||||
|
{
|
||||||
|
int i,j,n,m;
|
||||||
|
s >> n >> m;
|
||||||
|
x.resize(n,m);
|
||||||
|
typename LA_traits_io<T>::IOtype tmp;
|
||||||
|
for(i=0;i<n;i++) for(j=0; j<m;j++) { s>>tmp; x[i][j]=tmp;}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//optional indexing from 1
|
//optional indexing from 1
|
||||||
//all possible constructors have to be given explicitly, other stuff is inherited
|
//all possible constructors have to be given explicitly, other stuff is inherited
|
||||||
|
44
smat.cc
44
smat.cc
@ -358,50 +358,6 @@ void NRSMat< complex<double> >::axpy(const complex<double> alpha,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export template <typename T>
|
|
||||||
ostream& operator<<(ostream &s, const NRSMat<T> &x)
|
|
||||||
{
|
|
||||||
int i,j,n;
|
|
||||||
n=x.nrows();
|
|
||||||
s << n << ' ' << n << '\n';
|
|
||||||
for(i=0;i<n;i++)
|
|
||||||
{
|
|
||||||
for(j=0; j<n;j++) s << (typename LA_traits_io<T>::IOtype)x(i,j) << (j==n-1 ? '\n' : ' ');
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export template <typename T>
|
|
||||||
istream& operator>>(istream &s, NRSMat<T> &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<T>::IOtype tmp;
|
|
||||||
for(i=0;i<n;i++) for(j=0; j<m;j++) {s>>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<double>)
|
|
||||||
INSTANTIZE(int)
|
|
||||||
INSTANTIZE(short)
|
|
||||||
INSTANTIZE(char)
|
|
||||||
INSTANTIZE(unsigned int)
|
|
||||||
INSTANTIZE(unsigned long)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
////// forced instantization in the corresponding object file
|
////// forced instantization in the corresponding object file
|
||||||
|
28
smat.h
28
smat.h
@ -514,8 +514,32 @@ return r;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// I/O
|
// I/O
|
||||||
template <typename T> extern ostream& operator<<(ostream &s, const NRSMat<T> &x);
|
template <typename T>
|
||||||
template <typename T> extern istream& operator>>(istream &s, NRSMat<T> &x);
|
ostream& operator<<(ostream &s, const NRSMat<T> &x)
|
||||||
|
{
|
||||||
|
int i,j,n;
|
||||||
|
n=x.nrows();
|
||||||
|
s << n << ' ' << n << '\n';
|
||||||
|
for(i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
for(j=0; j<n;j++) s << (typename LA_traits_io<T>::IOtype)x(i,j) << (j==n-1 ? '\n' : ' ');
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
istream& operator>>(istream &s, NRSMat<T> &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<T>::IOtype tmp;
|
||||||
|
for(i=0;i<n;i++) for(j=0; j<m;j++) {s>>tmp; x(i,j)=tmp;}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// generate operators: SMat + a, a + SMat, SMat * a
|
// generate operators: SMat + a, a + SMat, SMat * a
|
||||||
NRVECMAT_OPER(SMat,+)
|
NRVECMAT_OPER(SMat,+)
|
||||||
|
44
sparsemat.cc
44
sparsemat.cc
@ -19,48 +19,6 @@ static inline void SWAP(T &a, T &b)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
export template <class T>
|
|
||||||
ostream& operator<<(ostream &s, const SparseMat<T> &x)
|
|
||||||
{
|
|
||||||
SPMatindex n,m;
|
|
||||||
n=x.nrows();
|
|
||||||
m=x.ncols();
|
|
||||||
s << (int)n << ' ' << (int)m << '\n';
|
|
||||||
matel<T> *list=x.getlist();
|
|
||||||
while(list)
|
|
||||||
{
|
|
||||||
s << (int)list->row << ' ' << (int)list->col << ' ' << (typename LA_traits_io<T>::IOtype)list->elem << '\n';
|
|
||||||
list=list->next;
|
|
||||||
}
|
|
||||||
s << "-1 -1\n";
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
export template <class T>
|
|
||||||
istream& operator>>(istream &s, SparseMat<T> &x)
|
|
||||||
{
|
|
||||||
int i,j;
|
|
||||||
int n,m;
|
|
||||||
matel<T> *l=NULL;
|
|
||||||
s >> n >> m;
|
|
||||||
x.resize(n,m);
|
|
||||||
s >> i >> j;
|
|
||||||
while(i>=0 && j>=0)
|
|
||||||
{
|
|
||||||
matel<T> *ll = l;
|
|
||||||
l= new matel<T>;
|
|
||||||
l->next= ll;
|
|
||||||
l->row=i;
|
|
||||||
l->col=j;
|
|
||||||
typename LA_traits_io<T>::IOtype tmp;
|
|
||||||
s >> tmp;
|
|
||||||
l->elem=tmp;
|
|
||||||
s >> i >> j;
|
|
||||||
}
|
|
||||||
x.setlist(l);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern ssize_t read(int, void *, size_t);
|
extern ssize_t read(int, void *, size_t);
|
||||||
extern ssize_t write(int, const void *, size_t);
|
extern ssize_t write(int, const void *, size_t);
|
||||||
@ -1309,8 +1267,6 @@ return *this;
|
|||||||
template SparseMat<T> & SparseMat<T>::oplusequal(const SparseMat<T> &rhs);\
|
template SparseMat<T> & SparseMat<T>::oplusequal(const SparseMat<T> &rhs);\
|
||||||
template SparseMat<T> & SparseMat<T>::oplusequal(const NRMat<T> &rhs);\
|
template SparseMat<T> & SparseMat<T>::oplusequal(const NRMat<T> &rhs);\
|
||||||
template SparseMat<T> & SparseMat<T>::oplusequal(const NRSMat<T> &rhs);\
|
template SparseMat<T> & SparseMat<T>::oplusequal(const NRSMat<T> &rhs);\
|
||||||
template ostream& operator<<(ostream &s, const SparseMat<T> &x); \
|
|
||||||
template istream& operator>>(istream &s, SparseMat<T> &x); \
|
|
||||||
template void SparseMat<T>::get(int fd, bool dimen, bool transp); \
|
template void SparseMat<T>::get(int fd, bool dimen, bool transp); \
|
||||||
template void SparseMat<T>::put(int fd, bool dimen, bool transp) const; \
|
template void SparseMat<T>::put(int fd, bool dimen, bool transp) const; \
|
||||||
template void SparseMat<T>::copyonwrite(); \
|
template void SparseMat<T>::copyonwrite(); \
|
||||||
|
45
sparsemat.h
45
sparsemat.h
@ -137,11 +137,48 @@ template <typename T>
|
|||||||
inline const NRMat<T> SparseMat<T>::operator*(const NRMat<T> &rhs) const
|
inline const NRMat<T> SparseMat<T>::operator*(const NRMat<T> &rhs) const
|
||||||
{NRMat<T> result(nn,rhs.ncols()); result.gemm((T)0,*this,'n',rhs,'n',(T)1); return result;};
|
{NRMat<T> result(nn,rhs.ncols()); result.gemm((T)0,*this,'n',rhs,'n',(T)1); return result;};
|
||||||
|
|
||||||
template <typename T>
|
template <class T>
|
||||||
extern istream& operator>>(istream &s, SparseMat<T> &x);
|
ostream& operator<<(ostream &s, const SparseMat<T> &x)
|
||||||
|
{
|
||||||
|
SPMatindex n,m;
|
||||||
|
n=x.nrows();
|
||||||
|
m=x.ncols();
|
||||||
|
s << (int)n << ' ' << (int)m << '\n';
|
||||||
|
matel<T> *list=x.getlist();
|
||||||
|
while(list)
|
||||||
|
{
|
||||||
|
s << (int)list->row << ' ' << (int)list->col << ' ' << (typename LA_traits_io<T>::IOtype)list->elem << '\n';
|
||||||
|
list=list->next;
|
||||||
|
}
|
||||||
|
s << "-1 -1\n";
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
istream& operator>>(istream &s, SparseMat<T> &x)
|
||||||
|
{
|
||||||
|
int i,j;
|
||||||
|
int n,m;
|
||||||
|
matel<T> *l=NULL;
|
||||||
|
s >> n >> m;
|
||||||
|
x.resize(n,m);
|
||||||
|
s >> i >> j;
|
||||||
|
while(i>=0 && j>=0)
|
||||||
|
{
|
||||||
|
matel<T> *ll = l;
|
||||||
|
l= new matel<T>;
|
||||||
|
l->next= ll;
|
||||||
|
l->row=i;
|
||||||
|
l->col=j;
|
||||||
|
typename LA_traits_io<T>::IOtype tmp;
|
||||||
|
s >> tmp;
|
||||||
|
l->elem=tmp;
|
||||||
|
s >> i >> j;
|
||||||
|
}
|
||||||
|
x.setlist(l);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
extern ostream& operator<<(ostream &s, const SparseMat<T> &x);
|
|
||||||
|
|
||||||
//destructor
|
//destructor
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
26
vec.cc
26
vec.cc
@ -15,8 +15,6 @@ extern ssize_t write(int, const void *, size_t);
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//// forced instantization in the corespoding object file
|
//// forced instantization in the corespoding object file
|
||||||
#define INSTANTIZE(T) \
|
#define INSTANTIZE(T) \
|
||||||
template ostream & operator<<(ostream &s, const NRVec< T > &x); \
|
|
||||||
template istream & operator>>(istream &s, NRVec< T > &x); \
|
|
||||||
template void NRVec<T>::put(int fd, bool dim, bool transp) const; \
|
template void NRVec<T>::put(int fd, bool dim, bool transp) const; \
|
||||||
template void NRVec<T>::get(int fd, bool dim, bool transp); \
|
template void NRVec<T>::get(int fd, bool dim, bool transp); \
|
||||||
|
|
||||||
@ -54,30 +52,6 @@ NRVec<T>::NRVec(const NRMat<T> &rhs)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// formatted I/O
|
|
||||||
template <typename T>
|
|
||||||
ostream & operator<<(ostream &s, const NRVec<T> &x)
|
|
||||||
{
|
|
||||||
int i, n;
|
|
||||||
|
|
||||||
n = x.size();
|
|
||||||
s << n << endl;
|
|
||||||
for(i=0; i<n; i++) s << (typename LA_traits_io<T>::IOtype)x[i] << (i == n-1 ? '\n' : ' ');
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
istream & operator>>(istream &s, NRVec<T> &x)
|
|
||||||
{
|
|
||||||
int i,n;
|
|
||||||
|
|
||||||
s >> n;
|
|
||||||
x.resize(n);
|
|
||||||
typename LA_traits_io<T>::IOtype tmp;
|
|
||||||
for(i=0; i<n; i++) {s >> tmp; x[i]=tmp;}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//raw I/O
|
//raw I/O
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
26
vec.h
26
vec.h
@ -119,8 +119,30 @@ public:
|
|||||||
#include "smat.h"
|
#include "smat.h"
|
||||||
#include "sparsemat.h"
|
#include "sparsemat.h"
|
||||||
|
|
||||||
template <typename T> ostream & operator<<(ostream &s, const NRVec<T> &x);
|
// formatted I/O
|
||||||
template <typename T> istream & operator>>(istream &s, NRVec<T> &x);
|
template <typename T>
|
||||||
|
ostream & operator<<(ostream &s, const NRVec<T> &x)
|
||||||
|
{
|
||||||
|
int i, n;
|
||||||
|
|
||||||
|
n = x.size();
|
||||||
|
s << n << endl;
|
||||||
|
for(i=0; i<n; i++) s << (typename LA_traits_io<T>::IOtype)x[i] << (i == n-1 ? '\n' : ' ');
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
istream & operator>>(istream &s, NRVec<T> &x)
|
||||||
|
{
|
||||||
|
int i,n;
|
||||||
|
|
||||||
|
s >> n;
|
||||||
|
x.resize(n);
|
||||||
|
typename LA_traits_io<T>::IOtype tmp;
|
||||||
|
for(i=0; i<n; i++) {s >> tmp; x[i]=tmp;}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// INLINES
|
// INLINES
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user