mat: rowset() and columnset()

This commit is contained in:
2026-01-27 17:29:50 +01:00
parent 18d8fd8d9b
commit 1580891639
3 changed files with 37 additions and 4 deletions

View File

@@ -296,7 +296,7 @@ static void multiput(size_t n, int fd, const std::complex<C> *x, bool dimensions
} }
while(total < n); while(total < n);
} }
static void copy(std::complex<C> *dest, std::complex<C> *src, size_t n) {memcpy(dest,src,n*sizeof(std::complex<C>));} static void copy(std::complex<C> *dest, const std::complex<C> *src, size_t n) {memcpy(dest,src,n*sizeof(std::complex<C>));}
static void clear(std::complex<C> *dest, size_t n) {memset(dest,0,n*sizeof(std::complex<C>));} static void clear(std::complex<C> *dest, size_t n) {memset(dest,0,n*sizeof(std::complex<C>));}
static void copyonwrite(std::complex<C> &x) {}; static void copyonwrite(std::complex<C> &x) {};
static bool is_plaindata() {return true;} static bool is_plaindata() {return true;}
@@ -356,7 +356,7 @@ static void multiput(size_t n, int fd, const C *x, bool dimensions=0)
} }
while(total < n); while(total < n);
} }
static void copy(C *dest, C *src, size_t n) {memcpy(dest,src,n*sizeof(C));} static void copy(C *dest, const C *src, size_t n) {memcpy(dest,src,n*sizeof(C));}
static void clear(C *dest, size_t n) {memset(dest,0,n*sizeof(C));} static void clear(C *dest, size_t n) {memset(dest,0,n*sizeof(C));}
static void copyonwrite(C &x) {}; static void copyonwrite(C &x) {};
static bool is_plaindata() {return true;} static bool is_plaindata() {return true;}
@@ -396,7 +396,7 @@ static void put(int fd, const X<C> &x, bool dimensions=1, bool transp=0, bool or
static void get(int fd, X<C> &x, bool dimensions=1, bool transp=0, bool orcaformat=false) {x.get(fd,dimensions,transp,orcaformat);} \ static void get(int fd, X<C> &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<C> *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i<n; ++i) x[i].put(fd,dimensions,false,orcaformat);} \ static void multiput(size_t n,int fd, const X<C> *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i<n; ++i) x[i].put(fd,dimensions,false,orcaformat);} \
static void multiget(size_t n,int fd, X<C> *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i<n; ++i) x[i].get(fd,dimensions,false,orcaformat);} \ static void multiget(size_t n,int fd, X<C> *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i<n; ++i) x[i].get(fd,dimensions,false,orcaformat);} \
static void copy(X<C> *dest, X<C> *src, size_t n) {for(size_t i=0; i<n; ++i) dest[i]=src[i];} \ static void copy(X<C> *dest, const X<C> *src, size_t n) {for(size_t i=0; i<n; ++i) dest[i]=src[i];} \
static void clear(X<C> *dest, size_t n) {for(size_t i=0; i<n; ++i) dest[i].clear();}\ static void clear(X<C> *dest, size_t n) {for(size_t i=0; i<n; ++i) dest[i].clear();}\
static void copyonwrite(X<C> &x) {x.copyonwrite();}\ static void copyonwrite(X<C> &x) {x.copyonwrite();}\
static bool is_plaindata() {return false;}\ static bool is_plaindata() {return false;}\
@@ -439,7 +439,7 @@ static void put(int fd, const X<C> &x, bool dimensions=1, bool transp=0, bool or
static void get(int fd, X<C> &x, bool dimensions=1, bool transp=0, bool orcaformat=false) {x.get(fd,dimensions,false,orcaformat);} \ static void get(int fd, X<C> &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<C> *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i<n; ++i) x[i].put(fd,dimensions,false,orcaformat);} \ static void multiput(size_t n,int fd, const X<C> *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i<n; ++i) x[i].put(fd,dimensions,false,orcaformat);} \
static void multiget(size_t n,int fd, X<C> *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i<n; ++i) x[i].get(fd,dimensions,false,orcaformat);} \ static void multiget(size_t n,int fd, X<C> *x, bool dimensions=1, bool orcaformat=false) {for(size_t i=0; i<n; ++i) x[i].get(fd,dimensions,false,orcaformat);} \
static void copy(C *dest, C *src, size_t n) {for(size_t i=0; i<n; ++i) dest[i]=src[i];} \ static void copy(C *dest, const C *src, size_t n) {for(size_t i=0; i<n; ++i) dest[i]=src[i];} \
static void clear(C *dest, size_t n) {for(size_t i=0; i<n; ++i) dest[i].clear();} \ static void clear(C *dest, size_t n) {for(size_t i=0; i<n; ++i) dest[i].clear();} \
static void copyonwrite(X<C> &x) {x.copyonwrite();} \ static void copyonwrite(X<C> &x) {x.copyonwrite();} \
static bool is_plaindata() {return false;}\ static bool is_plaindata() {return false;}\

23
mat.cc
View File

@@ -113,6 +113,29 @@ const NRVec<T> NRMat<T>::row(const int i, int l) const {
return r; return r;
} }
/***************************************************************************//**
* store given row of this matrix of general type <code>T</code>
* @param[in] i row index starting from zero
* @param[in] l consider this value as the count of columns
******************************************************************************/
template <typename T>
void NRMat<T>::rowset(const NRVec<T> &r, const int i, int l) {
#ifdef DEBUG
if(i < 0 || i >= nn) laerror("illegal index");
#endif
if(l < 0) l = mm;
LA_traits<T>::copy(
#ifdef MATPTR
v[i]
#else
v + i*(size_t)l
#endif
, &r[0], l);
}
/***************************************************************************//** /***************************************************************************//**
* routine for raw output * routine for raw output
* @param[in] fd file descriptor for output * @param[in] fd file descriptor for output

10
mat.h
View File

@@ -266,6 +266,9 @@ public:
//! get the i<sup>th</sup> row //! get the i<sup>th</sup> row
const NRVec<T> row(const int i, int l = -1) const; const NRVec<T> row(const int i, int l = -1) const;
//! set the i<sup>th</sup> row
void rowset(const NRVec<T> &r, const int i, int l = -1);
//! get the j<sup>th</sup> column //! get the j<sup>th</sup> column
const NRVec<T> column(const int j, int l = -1) const { const NRVec<T> column(const int j, int l = -1) const {
NOT_GPU(*this); NOT_GPU(*this);
@@ -275,6 +278,13 @@ public:
return r; return r;
}; };
//! set the j<sup>th</sup> column
void columnset(const NRVec<T> &r, const int j, int l = -1) {
NOT_GPU(*this);
if(l < 0) l = nn;
for(register int i=0; i<l; ++i) (*this)(i,j) = r[i];
};
//! extract the digonal elements of this matrix and store them into a vector //! extract the digonal elements of this matrix and store them into a vector
const T* diagonalof(NRVec<T> &, const bool divide = 0, bool cache = false) const; const T* diagonalof(NRVec<T> &, const bool divide = 0, bool cache = false) const;
//! set diagonal elements //! set diagonal elements