diff options
Diffstat (limited to 'Eigen/Core/Coeffs.h')
-rw-r--r-- | Eigen/Core/Coeffs.h | 174 |
1 files changed, 147 insertions, 27 deletions
diff --git a/Eigen/Core/Coeffs.h b/Eigen/Core/Coeffs.h index d20da2a27..fa8f44935 100644 --- a/Eigen/Core/Coeffs.h +++ b/Eigen/Core/Coeffs.h @@ -26,105 +26,225 @@ #ifndef EIGEN_COEFFS_H #define EIGEN_COEFFS_H +/** Short version: don't use this function, use + * \link operator()(int,int) const \endlink instead. + * + * Long version: this function is similar to + * \link operator()(int,int) const \endlink, but without the assertion. + * Use this for limiting the performance cost of debugging code when doing + * repeated coefficient access. Only use this when it is guaranteed that the + * parameters \a row and \a col are in range. + * + * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this + * function equivalent to \link operator()(int,int) const \endlink. + * + * \sa operator()(int,int) const, coeffRef(int,int), coeff(int) const + */ template<typename Scalar, typename Derived> Scalar MatrixBase<Scalar, Derived> - ::coeff(int row, int col, AssertLevel assertLevel = InternalDebugging) const + ::coeff(int row, int col) const { - eigen_assert(assertLevel, row >= 0 && row < rows() - && col >= 0 && col < cols()); + eigen_internal_assert(row >= 0 && row < rows() + && col >= 0 && col < cols()); return static_cast<const Derived *>(this)->_coeff(row, col); } +/** \returns the coefficient at given the given row and column. + * + * \sa operator()(int,int), operator[](int) const + */ template<typename Scalar, typename Derived> Scalar MatrixBase<Scalar, Derived> - ::operator()(int row, int col) const { return coeff(row, col, UserDebugging); } + ::operator()(int row, int col) const +{ + assert(row >= 0 && row < rows() + && col >= 0 && col < cols()); + return static_cast<const Derived *>(this)->_coeff(row, col); +} +/** Short version: don't use this function, use + * \link operator()(int,int) \endlink instead. + * + * Long version: this function is similar to + * \link operator()(int,int) \endlink, but without the assertion. + * Use this for limiting the performance cost of debugging code when doing + * repeated coefficient access. Only use this when it is guaranteed that the + * parameters \a row and \a col are in range. + * + * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this + * function equivalent to \link operator()(int,int) \endlink. + * + * \sa operator()(int,int), coeff(int, int) const, coeffRef(int) + */ template<typename Scalar, typename Derived> Scalar& MatrixBase<Scalar, Derived> - ::coeffRef(int row, int col, AssertLevel assertLevel = InternalDebugging) + ::coeffRef(int row, int col) { - eigen_assert(assertLevel, row >= 0 && row < rows() - && col >= 0 && col < cols()); + eigen_internal_assert(row >= 0 && row < rows() + && col >= 0 && col < cols()); return static_cast<Derived *>(this)->_coeffRef(row, col); } +/** \returns a reference to the coefficient at given the given row and column. + * + * \sa operator()(int,int) const, operator[](int) + */ template<typename Scalar, typename Derived> Scalar& MatrixBase<Scalar, Derived> - ::operator()(int row, int col) { return coeffRef(row, col, UserDebugging); } + ::operator()(int row, int col) +{ + assert(row >= 0 && row < rows() + && col >= 0 && col < cols()); + return static_cast<Derived *>(this)->_coeffRef(row, col); +} +/** Short version: don't use this function, use + * \link operator[](int) const \endlink instead. + * + * Long version: this function is similar to + * \link operator[](int) const \endlink, but without the assertion. + * Use this for limiting the performance cost of debugging code when doing + * repeated coefficient access. Only use this when it is guaranteed that the + * parameters \a row and \a col are in range. + * + * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this + * function equivalent to \link operator[](int) const \endlink. + * + * \sa operator[](int) const, coeffRef(int), coeff(int,int) const + */ template<typename Scalar, typename Derived> Scalar MatrixBase<Scalar, Derived> - ::coeff(int index, AssertLevel assertLevel = InternalDebugging) const + ::coeff(int index) const { - eigen_assert(assertLevel, IsVector); + eigen_internal_assert(IsVector); if(RowsAtCompileTime == 1) { - eigen_assert(assertLevel, index >= 0 && index < cols()); + eigen_internal_assert(index >= 0 && index < cols()); return coeff(0, index); } else { - eigen_assert(assertLevel, index >= 0 && index < rows()); + eigen_internal_assert(index >= 0 && index < rows()); return coeff(index, 0); } } +/** \returns the coefficient at given index. + * + * \only_for_vectors + * + * \sa operator[](int), operator()(int,int) const, x() const, y() const, + * z() const, w() const + */ template<typename Scalar, typename Derived> Scalar MatrixBase<Scalar, Derived> - ::operator[](int index) const { return coeff(index, UserDebugging); } + ::operator[](int index) const +{ + assert(IsVector); + if(RowsAtCompileTime == 1) + { + assert(index >= 0 && index < cols()); + return coeff(0, index); + } + else + { + assert(index >= 0 && index < rows()); + return coeff(index, 0); + } +} +/** Short version: don't use this function, use + * \link operator[](int) \endlink instead. + * + * Long version: this function is similar to + * \link operator[](int) \endlink, but without the assertion. + * Use this for limiting the performance cost of debugging code when doing + * repeated coefficient access. Only use this when it is guaranteed that the + * parameters \a row and \a col are in range. + * + * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this + * function equivalent to \link operator[](int) \endlink. + * + * \sa operator[](int), coeff(int) const, coeffRef(int,int) + */ template<typename Scalar, typename Derived> Scalar& MatrixBase<Scalar, Derived> - ::coeffRef(int index, AssertLevel assertLevel = InternalDebugging) + ::coeffRef(int index) { - eigen_assert(assertLevel, IsVector); + eigen_internal_assert(IsVector); if(RowsAtCompileTime == 1) { - eigen_assert(assertLevel, index >= 0 && index < cols()); + eigen_internal_assert(index >= 0 && index < cols()); return coeffRef(0, index); } else { - eigen_assert(assertLevel, index >= 0 && index < rows()); + eigen_internal_assert(index >= 0 && index < rows()); return coeffRef(index, 0); } } +/** \returns a reference to the coefficient at given index. + * + * \only_for_vectors + * + * \sa operator[](int) const, operator()(int,int), x(), y(), z(), w() + */ template<typename Scalar, typename Derived> Scalar& MatrixBase<Scalar, Derived> - ::operator[](int index) { return coeffRef(index, UserDebugging); } + ::operator[](int index) +{ + assert(IsVector); + if(RowsAtCompileTime == 1) + { + assert(index >= 0 && index < cols()); + return coeffRef(0, index); + } + else + { + assert(index >= 0 && index < rows()); + return coeffRef(index, 0); + } +} +/** equivalent to operator[](0). \only_for_vectors */ template<typename Scalar, typename Derived> Scalar MatrixBase<Scalar, Derived> - ::x() const { return coeff(0, UserDebugging); } + ::x() const { return (*this)[0]; } +/** equivalent to operator[](1). \only_for_vectors */ template<typename Scalar, typename Derived> Scalar MatrixBase<Scalar, Derived> - ::y() const { return coeff(1, UserDebugging); } + ::y() const { return (*this)[1]; } +/** equivalent to operator[](2). \only_for_vectors */ template<typename Scalar, typename Derived> Scalar MatrixBase<Scalar, Derived> - ::z() const { return coeff(2, UserDebugging); } + ::z() const { return (*this)[2]; } +/** equivalent to operator[](3). \only_for_vectors */ template<typename Scalar, typename Derived> Scalar MatrixBase<Scalar, Derived> - ::w() const { return coeff(3, UserDebugging); } + ::w() const { return (*this)[3]; } +/** equivalent to operator[](0). \only_for_vectors */ template<typename Scalar, typename Derived> Scalar& MatrixBase<Scalar, Derived> - ::x() { return coeffRef(0, UserDebugging); } + ::x() { return (*this)[0]; } +/** equivalent to operator[](1). \only_for_vectors */ template<typename Scalar, typename Derived> Scalar& MatrixBase<Scalar, Derived> - ::y() { return coeffRef(1, UserDebugging); } + ::y() { return (*this)[1]; } +/** equivalent to operator[](2). \only_for_vectors */ template<typename Scalar, typename Derived> Scalar& MatrixBase<Scalar, Derived> - ::z() { return coeffRef(2, UserDebugging); } + ::z() { return (*this)[2]; } +/** equivalent to operator[](3). \only_for_vectors */ template<typename Scalar, typename Derived> Scalar& MatrixBase<Scalar, Derived> - ::w() { return coeffRef(3, UserDebugging); } - + ::w() { return (*this)[3]; } #endif // EIGEN_COEFFS_H |