From 96cb9ab14638b5dba974b06eaad2d7b2e906465a Mon Sep 17 00:00:00 2001 From: TSC21 Date: Sun, 17 Feb 2019 16:54:25 +0000 Subject: [PATCH] add NaN value set for Matrix; add return of URT of a matrix --- matrix/Matrix.hpp | 12 ++++++++++++ matrix/SquareMatrix.hpp | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index f097301611..7cbc5ea753 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -412,6 +412,11 @@ public: setAll(1); } + inline void setNaN() + { + setAll(NAN); + } + void setIdentity() { setZero(); @@ -512,6 +517,13 @@ Matrix ones() { return m; } +template +Matrix nans() { + Matrix m; + m.setNaN(); + return m; +} + template Matrix operator*(Type scalar, const Matrix &other) { diff --git a/matrix/SquareMatrix.hpp b/matrix/SquareMatrix.hpp index 5421dbab20..21cf40cf96 100644 --- a/matrix/SquareMatrix.hpp +++ b/matrix/SquareMatrix.hpp @@ -48,7 +48,6 @@ public: } } - // inverse alias inline bool I(SquareMatrix &i) const { @@ -67,6 +66,23 @@ public: return res; } + // get matrix upper right triangle + Vector urt() const + { + Vector res; + const SquareMatrix &self = *this; + + unsigned idx = 0; + for (size_t x = 0; x < M; x++) { + for (size_t y = x; y < M; y++) { + res(idx) = self(x, y); + ++idx; + } + } + + return res; + } + Type trace() const { Type res = 0;