From 2feea51b078cc53663e411bf80e35044c1ef4a07 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 9 Nov 2017 12:45:59 +0200 Subject: [PATCH] Add row and column accessors to Matrix --- source/linal/matrix.h | 3 +++ source/linal/vector.h | 12 ++++++++++++ 2 files changed, 15 insertions(+) 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 -- 2.43.0