diff --git a/doc/concepts.tex b/doc/concepts.tex index 65fd616..f24b425 100644 --- a/doc/concepts.tex +++ b/doc/concepts.tex @@ -287,7 +287,8 @@ void get(int fd, bool dimensions=1, bool transp=0, bool orca_format=false); \item \code{NRVec}: header $n$ and a padding \code{int} 1 (8-byte alignment), then the $n$ elements; \code{transp} is ignored. \item \code{NRMat}: header \code{nrows}, \code{ncols}, then the elements by rows. With \code{transp} the transposed matrix is written (dimensions swapped, elements column by column); \code{get} with \code{transp} reads such data back into the - original orientation, i.e.\ it reads a file stored by columns. + original orientation, i.e.\ it reads a file stored by columns. For elements of plain types this is done by one + write or read of a temporary transposed copy of the matrix (elements of class type are processed one by one). \item \code{NRSMat}: header $n$, $n$, then the packed lower triangle; \code{transp} is ignored. \item \code{SparseMat}: header \code{nrows}, \code{ncols} (\code{SPMatindex}) and the \code{int} flags \code{symmetric} and \code{nonzero}, then triples (row, column, element) and a terminating pair of indices $-1$; \code{SparseSMat}: header diff --git a/mat.cc b/mat.cc index 28560e9..27439bf 100644 --- a/mat.cc +++ b/mat.cc @@ -167,7 +167,18 @@ void NRMat::put(int fd, bool dim, bool transp, bool orcaformat) const { } } - if(transp){ //not particularly efficient + if(transp){ + if(LA_traits::is_plaindata()){ //transpose in memory and write at once + NRMat tmp(mm,nn); + for(int i=0; i::multiput((size_t)nn*(size_t)mm,fd, + #ifdef MATPTR + tmp.v[0] + #else + tmp.v + #endif + ,dim); + }else //element by element, not particularly efficient for(int j=0; j::put(fd, @@ -226,6 +237,17 @@ void NRMat::get(int fd, bool dim, bool transp, bool orcaformat){ } if(transp){ + if(LA_traits::is_plaindata()){ //read at once and transpose in memory + NRMat tmp(mm,nn); + LA_traits::multiget((size_t)nn*(size_t)mm,fd, + #ifdef MATPTR + tmp.v[0] + #else + tmp.v + #endif + ,dim); + for(int i=0; i::get(fd, diff --git a/t.cc b/t.cc index 054cf02..964b675 100644 --- a/t.cc +++ b/t.cc @@ -4867,6 +4867,31 @@ cout <<"Error of the inverse block = "<<(b*r.submatrix(rows,cols)-one).norm()<k&&m>k) cout <<"Error of the Schur complement = "<<(r.submatrix(orows,ocols)-a.submatrix(orows,ocols)+a.submatrix(orows,cols)*calcinverse(b)*a.submatrix(rows,ocols)).norm()<>n>>m; +NRMat a(n,m),b,c; +a.randomize(1.); +NRMat ia(n,m),ib,ic; +for(int i=0; i