diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2007-12-11 10:06:43 +0000 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2007-12-11 10:06:43 +0000 |
commit | d50ce24dd9631f6bb53b4f19667500efe6e23cca (patch) | |
tree | ee2cb9ab6680d6bdfe877fbf35858a8ba8c33c36 /src/Core/MatrixBase.h | |
parent | effaee9bc7bf48a8703c75c8279279e2f1055766 (diff) |
rework asserts system so as to minimize the impact of debugging code on performance
Diffstat (limited to 'src/Core/MatrixBase.h')
-rw-r--r-- | src/Core/MatrixBase.h | 58 |
1 files changed, 22 insertions, 36 deletions
diff --git a/src/Core/MatrixBase.h b/src/Core/MatrixBase.h index 665229766..1fd6e3971 100644 --- a/src/Core/MatrixBase.h +++ b/src/Core/MatrixBase.h @@ -42,7 +42,7 @@ template<typename Scalar, typename Derived> class MatrixBase typedef typename ForwardDecl<Derived>::Ref Ref; typedef typename NumTraits<Scalar>::Real RealScalar; - + int rows() const { return static_cast<const Derived *>(this)->_rows(); } int cols() const { return static_cast<const Derived *>(this)->_cols(); } int size() const { return rows() * cols(); } @@ -50,24 +50,6 @@ template<typename Scalar, typename Derived> class MatrixBase Ref ref() const { return static_cast<const Derived *>(this)->_ref(); } - Scalar& write(int row, int col) - { - // from this single point, we can check all writes to all matrix/expression - // types. We only want this however for internal testing, as this is very slow. - eigen_internal_assert(row >= 0 && row < rows() - && col >= 0 && col < cols()); - return static_cast<Derived *>(this)->_write(row, col); - } - - Scalar read(int row, int col) const - { - // from this single point, we can check all reads to all matrix/expression - // types. We only want this however for internal testing, as this is very slow. - eigen_internal_assert(row >= 0 && row < rows() - && col >= 0 && col < cols()); - return static_cast<const Derived *>(this)->_read(row, col); - } - template<typename OtherDerived> Derived& operator=(const MatrixBase<Scalar, OtherDerived>& other) { @@ -132,7 +114,7 @@ template<typename Scalar, typename Derived> class MatrixBase ) const; template<typename OtherDerived> - Product<Derived, OtherDerived> + const Product<Derived, OtherDerived> lazyProduct(const MatrixBase<Scalar, OtherDerived>& other) const EIGEN_ALWAYS_INLINE; Opposite<Derived> operator-() const; @@ -156,49 +138,53 @@ template<typename Scalar, typename Derived> class MatrixBase Derived& operator/=(const std::complex<float>& other); Derived& operator/=(const std::complex<double>& other); - Scalar operator()(int row, int col) const + Scalar read(int row, int col, AssertLevel assertLevel = InternalDebugging) const { - assert(row >= 0 && row < rows() - && col >= 0 && col < cols()); - return read(row, col); + eigen_assert(assertLevel, row >= 0 && row < rows() + && col >= 0 && col < cols()); + return static_cast<const Derived *>(this)->_read(row, col); } + Scalar operator()(int row, int col) const { return read(row, col, UserDebugging); } - Scalar& operator()(int row, int col) + Scalar& write(int row, int col, AssertLevel assertLevel = InternalDebugging) { - assert(row >= 0 && row < rows() - && col >= 0 && col < cols()); - return write(row, col); + eigen_assert(assertLevel, row >= 0 && row < rows() + && col >= 0 && col < cols()); + return static_cast<Derived *>(this)->_write(row, col); } + Scalar& operator()(int row, int col) { return write(row, col, UserDebugging); } - Scalar operator[](int index) const + Scalar read(int index, AssertLevel assertLevel = InternalDebugging) const { - assert(IsVector); + eigen_assert(assertLevel, IsVector); if(RowsAtCompileTime == 1) { - assert(index >= 0 && index < cols()); + eigen_assert(assertLevel, index >= 0 && index < cols()); return read(0, index); } else { - assert(index >= 0 && index < rows()); + eigen_assert(assertLevel, index >= 0 && index < rows()); return read(index, 0); } } + Scalar operator[](int index) const { return read(index, UserDebugging); } - Scalar& operator[](int index) + Scalar& write(int index, AssertLevel assertLevel = InternalDebugging) { - assert(IsVector); + eigen_assert(assertLevel, IsVector); if(RowsAtCompileTime == 1) { - assert(index >= 0 && index < cols()); + eigen_assert(assertLevel, index >= 0 && index < cols()); return write(0, index); } else { - assert(index >= 0 && index < rows()); + eigen_assert(assertLevel, index >= 0 && index < rows()); return write(index, 0); } } + Scalar& operator[](int index) { return write(index, UserDebugging); } Eval<Derived> eval() const EIGEN_ALWAYS_INLINE; }; |