From 3f979187600897221c7e807373eb267af4db1ada Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 14 Oct 2007 10:01:25 +0000 Subject: [PATCH] restrict identity() to square matrices; small change helping g++ optimize. --- src/Core/Identity.h | 15 ++++++++------- src/Core/Object.h | 2 +- test/basicstuff.cpp | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Core/Identity.h b/src/Core/Identity.h index 78b380b04..4b437a844 100644 --- a/src/Core/Identity.h +++ b/src/Core/Identity.h @@ -36,30 +36,31 @@ template class Identity static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime; - Identity(int rows, int cols) : m_rows(rows), m_cols(cols) + Identity(int rows) : m_rows(rows) { - assert(rows > 0 && cols > 0); + assert(rows > 0); + assert(RowsAtCompileTime == ColsAtCompileTime); } private: Identity& _ref() { return *this; } const Identity& _constRef() const { return *this; } int _rows() const { return m_rows; } - int _cols() const { return m_cols; } + int _cols() const { return m_rows; } Scalar _read(int row, int col) const { - return static_cast(row == col); + return row == col ? static_cast(1) : static_cast(0); } protected: - int m_rows, m_cols; + int m_rows; }; template -Identity Object::identity(int rows, int cols) +Identity Object::identity(int rows) { - return Identity(rows, cols); + return Identity(rows); } #endif // EI_IDENTITY_H diff --git a/src/Core/Object.h b/src/Core/Object.h index 5b2e34f53..5792385e6 100644 --- a/src/Core/Object.h +++ b/src/Core/Object.h @@ -116,7 +116,7 @@ template class Object static Zero zero(int rows = RowsAtCompileTime, int cols = ColsAtCompileTime); static Identity - identity(int rows = RowsAtCompileTime, int cols = ColsAtCompileTime); + identity(int rows = RowsAtCompileTime); template bool isApprox( diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index c21a58979..3e734a498 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -37,7 +37,7 @@ template void basicStuff(const MatrixType& m) m3, mzero = MatrixType::zero(rows, cols), identity = Matrix - ::identity(rows, rows), + ::identity(rows), square = Matrix ::random(rows, rows); VectorType v1 = VectorType::random(rows),