diff --git a/mat.cc b/mat.cc index 8d9c701..5087ddb 100644 --- a/mat.cc +++ b/mat.cc @@ -97,17 +97,18 @@ const NRMat NRMat::otimes(const NRMat &rhs, bool reversecolumns) const * @return extracted elements as a NRVec object ******************************************************************************/ template -const NRVec NRMat::row(const int i, int l) const { +const NRVec NRMat::row(const int i, int l, int offset) const { + if(l < 0) l = mm; #ifdef DEBUG if(i < 0 || i >= nn) laerror("illegal index"); + if(offset<0||l+offset>mm) laerror("illegal len/offset"); #endif - if(l < 0) l = mm; NRVec r(l); LA_traits::copy(&r[0], #ifdef MATPTR - v[i] + v[i]+offset #else - v + i*(size_t)l + v + i*(size_t)mm + offset #endif , l); return r; @@ -120,16 +121,17 @@ const NRVec NRMat::row(const int i, int l) const { * @param[in] l consider this value as the count of columns ******************************************************************************/ template -void NRMat::rowset(const NRVec &r, const int i, int l) { +void NRMat::rowset(const NRVec &r, const int i, int l, int offset) { + if(l < 0) l = mm; #ifdef DEBUG if(i < 0 || i >= nn) laerror("illegal index"); + if(offset<0||l+offset>mm) laerror("illegal len/offset"); #endif - if(l < 0) l = mm; LA_traits::copy( #ifdef MATPTR - v[i] + v[i]+offset #else - v + i*(size_t)l + v + i*(size_t)mm + offset #endif , &r[0], l); } diff --git a/mat.h b/mat.h index c12d61a..abf2f13 100644 --- a/mat.h +++ b/mat.h @@ -264,10 +264,10 @@ public: void orthonormalize(const bool rowcol, const NRSMat *metric = NULL); //! get the ith row - const NRVec row(const int i, int l = -1) const; + const NRVec row(const int i, int len = -1, int offset=0) const; //! set the ith row - void rowset(const NRVec &r, const int i, int l = -1); + void rowset(const NRVec &r, const int i, int len = -1, int offset=0); //! get the jth column const NRVec column(const int j, int l = -1) const {