From 9474153736760d870f28b5335cce755233f4e5d2 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 8 Aug 2014 22:13:51 -0700 Subject: [PATCH] Move Zero() and Identity() definitions to the right place --- src/basics/matrix.hh | 64 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/src/basics/matrix.hh b/src/basics/matrix.hh index 14c37ec..127afcb 100644 --- a/src/basics/matrix.hh +++ b/src/basics/matrix.hh @@ -70,6 +70,36 @@ template Matrix operator*(const Double& lhs, const Matrix& rhs); +/* + * charles::basics::Matrix<>::Zero -- + */ +template +/* static */ Matrix +Matrix::Zero() +{ + Matrix m; + bzero(m.mData, sizeof(Double) * N * M); + return m; +} + + +/* + * charles::basics::Matrix<>::Identity -- + */ +template +/* static */ Matrix +Matrix::Identity() +{ + static_assert(N == M, "Identity matrices must be square."); + + auto m = Matrix::Zero(); + for (size_t i = 0; i < N; i++) { + m(i,i) = 1.0; + } + return m; +} + + /* * charles::basics::Matrix<>::Matrix -- */ @@ -140,40 +170,6 @@ Matrix::operator!=(const Matrix& rhs) } -/* - * charles::basics::Matrix<>::Zero -- - */ -template -Matrix -Matrix::Zero() -{ - Matrix m; - bzero(m.mData, sizeof(Double) * N * M); - return m; -} - - -/* - * charles::basics::Matrix<>::Identity -- - */ -template -Matrix -Matrix::Identity() -{ - static_assert(N == M, "Identity matrices must be square."); - - auto m = Matrix::Zero(); - for (int i = 0; i < N; i++) { - for (int j = 0; j < M; j++) { - if (i == j) { - m(i,j) = 1.0; - } - } - } - return m; -} - - /* * charles::basics::Matrix<>::operator() -- */