From: Mikko Rasa Date: Thu, 9 Nov 2017 10:45:59 +0000 (+0200) Subject: Add row and column accessors to Matrix X-Git-Url: http://git.tdb.fi/?p=libs%2Fmath.git;a=commitdiff_plain;h=2feea51b078cc53663e411bf80e35044c1ef4a07 Add row and column accessors to Matrix --- diff --git a/source/linal/matrix.h b/source/linal/matrix.h index 1c831be..daf9cb8 100644 --- a/source/linal/matrix.h +++ b/source/linal/matrix.h @@ -36,6 +36,9 @@ public: T &operator()(unsigned i, unsigned j) { return element(i, j); } const T &operator()(unsigned i, unsigned j) const { return element(i, j); } + Vector column(unsigned i) const { return Vector(data+M*i); } + Vector row(unsigned i) const { return Vector(data+i, M); } + template Matrix select(const Vector &, const Vector &) const; diff --git a/source/linal/vector.h b/source/linal/vector.h index 152c26e..9a9d028 100644 --- a/source/linal/vector.h +++ b/source/linal/vector.h @@ -78,6 +78,11 @@ public: Vector(); Vector(const T *); + + /** Constructs a vector from an array of interleaved values. Intended for + use by Matrix row accessor. */ + Vector(const T *, unsigned); + Vector(T, T); Vector(T, T, T); Vector(T, T, T, T); @@ -113,6 +118,13 @@ inline Vector::Vector(const T *d) (*this)[i] = d[i]; } +template +inline Vector::Vector(const T *d, unsigned stride) +{ + for(unsigned i=0; i