From: Mikko Rasa Date: Thu, 13 Nov 2014 21:18:47 +0000 (+0200) Subject: Clearer API for slicing and dicing vectors, and also matrices X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ffb043ce670d733decc03c6e4240a4e6d980caec;p=libs%2Fmath.git Clearer API for slicing and dicing vectors, and also matrices --- diff --git a/source/linal/matrix.h b/source/linal/matrix.h index f18eb2f..929c482 100644 --- a/source/linal/matrix.h +++ b/source/linal/matrix.h @@ -30,6 +30,9 @@ public: T &operator()(unsigned i, unsigned j) { return element(i, j); } const T &operator()(unsigned i, unsigned j) const { return element(i, j); } + template + Matrix block(unsigned, unsigned) const; + Matrix &operator*=(T); Matrix &operator/=(T); Matrix &operator+=(const Matrix &); @@ -81,6 +84,17 @@ inline Matrix Matrix::from_rows(const Vector *v) return m; } +template +template +inline Matrix Matrix::block(unsigned y, unsigned x) const +{ + Matrix r; + for(unsigned j=0; j inline Matrix &Matrix::operator*=(T s) { diff --git a/source/linal/vector.h b/source/linal/vector.h index 9ef46fd..6dfe6ca 100644 --- a/source/linal/vector.h +++ b/source/linal/vector.h @@ -81,10 +81,9 @@ public: Vector(T, T, T, T); template Vector(const Vector &); - template - Vector(const Vector &, U); - template - explicit Vector(const Vector &); + + template + Vector slice(unsigned) const; Vector &operator*=(T); Vector &operator/=(T); @@ -145,20 +144,44 @@ inline Vector::Vector(const Vector &v) } template -template -inline Vector::Vector(const Vector &v, U s) +inline Vector compose(const Vector &v, T s) { - for(unsigned i=0; i r; + for(unsigned i=0; i -template -inline Vector::Vector(const Vector &v) +inline Vector compose(T s, const Vector &v) { + Vector r; for(unsigned i=0; i +inline Vector compose(const Vector &v1, const Vector &v2) +{ + Vector r; + for(unsigned i=0; i +template +inline Vector Vector::slice(unsigned j) const +{ + Vector r; + for(unsigned i=0; i