NRMat::row() generalized - backward compatibly

This commit is contained in:
2026-01-29 14:05:05 +01:00
parent 0ab331d047
commit febb19d15f
2 changed files with 12 additions and 10 deletions

18
mat.cc
View File

@@ -97,17 +97,18 @@ const NRMat<T> NRMat<T>::otimes(const NRMat<T> &rhs, bool reversecolumns) const
* @return extracted elements as a NRVec<T> object * @return extracted elements as a NRVec<T> object
******************************************************************************/ ******************************************************************************/
template <typename T> template <typename T>
const NRVec<T> NRMat<T>::row(const int i, int l) const { const NRVec<T> NRMat<T>::row(const int i, int l, int offset) const {
if(l < 0) l = mm;
#ifdef DEBUG #ifdef DEBUG
if(i < 0 || i >= nn) laerror("illegal index"); if(i < 0 || i >= nn) laerror("illegal index");
if(offset<0||l+offset>mm) laerror("illegal len/offset");
#endif #endif
if(l < 0) l = mm;
NRVec<T> r(l); NRVec<T> r(l);
LA_traits<T>::copy(&r[0], LA_traits<T>::copy(&r[0],
#ifdef MATPTR #ifdef MATPTR
v[i] v[i]+offset
#else #else
v + i*(size_t)l v + i*(size_t)mm + offset
#endif #endif
, l); , l);
return r; return r;
@@ -120,16 +121,17 @@ const NRVec<T> NRMat<T>::row(const int i, int l) const {
* @param[in] l consider this value as the count of columns * @param[in] l consider this value as the count of columns
******************************************************************************/ ******************************************************************************/
template <typename T> template <typename T>
void NRMat<T>::rowset(const NRVec<T> &r, const int i, int l) { void NRMat<T>::rowset(const NRVec<T> &r, const int i, int l, int offset) {
if(l < 0) l = mm;
#ifdef DEBUG #ifdef DEBUG
if(i < 0 || i >= nn) laerror("illegal index"); if(i < 0 || i >= nn) laerror("illegal index");
if(offset<0||l+offset>mm) laerror("illegal len/offset");
#endif #endif
if(l < 0) l = mm;
LA_traits<T>::copy( LA_traits<T>::copy(
#ifdef MATPTR #ifdef MATPTR
v[i] v[i]+offset
#else #else
v + i*(size_t)l v + i*(size_t)mm + offset
#endif #endif
, &r[0], l); , &r[0], l);
} }

4
mat.h
View File

@@ -264,10 +264,10 @@ public:
void orthonormalize(const bool rowcol, const NRSMat<T> *metric = NULL); void orthonormalize(const bool rowcol, const NRSMat<T> *metric = NULL);
//! 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 len = -1, int offset=0) const;
//! set the i<sup>th</sup> row //! set the i<sup>th</sup> row
void rowset(const NRVec<T> &r, const int i, int l = -1); void rowset(const NRVec<T> &r, const int i, int len = -1, int offset=0);
//! 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 {