aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/plugins/ArrayCwiseBinaryOps.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-12-04 23:17:14 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-12-04 23:17:14 +0100
commit8e05f9cfa1538d76a9d3e01e08ba565bd581806a (patch)
treee3ba56b1c37c00ce1da70277e8ef2a86a48c6173 /Eigen/src/plugins/ArrayCwiseBinaryOps.h
parent80ebeae48d7b56500d9ebc8abd2789061af145e1 (diff)
add a DenseBase class for MAtrixBase and ArrayBase and more code factorisation
Diffstat (limited to 'Eigen/src/plugins/ArrayCwiseBinaryOps.h')
-rw-r--r--Eigen/src/plugins/ArrayCwiseBinaryOps.h243
1 files changed, 243 insertions, 0 deletions
diff --git a/Eigen/src/plugins/ArrayCwiseBinaryOps.h b/Eigen/src/plugins/ArrayCwiseBinaryOps.h
new file mode 100644
index 000000000..f2a329461
--- /dev/null
+++ b/Eigen/src/plugins/ArrayCwiseBinaryOps.h
@@ -0,0 +1,243 @@
+
+/** \returns an expression of the coefficient-wise \< operator of *this and \a other
+ *
+ * Example: \include Cwise_less.cpp
+ * Output: \verbinclude Cwise_less.out
+ *
+ * \sa all(), any(), operator>(), operator<=()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(operator<,std::less)
+
+/** \returns an expression of the coefficient-wise \<= operator of *this and \a other
+ *
+ * Example: \include Cwise_less_equal.cpp
+ * Output: \verbinclude Cwise_less_equal.out
+ *
+ * \sa all(), any(), operator>=(), operator<()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal)
+// template<typename ExpressionType>
+// template<typename OtherDerived>
+// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
+// operator<=(const MatrixBase<OtherDerived> &other) const
+// {
+// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)(_expression(), other.derived());
+// }
+
+/** \returns an expression of the coefficient-wise \> operator of *this and \a other
+ *
+ * Example: \include Cwise_greater.cpp
+ * Output: \verbinclude Cwise_greater.out
+ *
+ * \sa all(), any(), operator>=(), operator<()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater)
+// template<typename ExpressionType>
+// template<typename OtherDerived>
+// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
+// operator>(const MatrixBase<OtherDerived> &other) const
+// {
+// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)(_expression(), other.derived());
+// }
+
+/** \returns an expression of the coefficient-wise \>= operator of *this and \a other
+ *
+ * Example: \include Cwise_greater_equal.cpp
+ * Output: \verbinclude Cwise_greater_equal.out
+ *
+ * \sa all(), any(), operator>(), operator<=()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal)
+// template<typename ExpressionType>
+// template<typename OtherDerived>
+// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
+// operator>=(const MatrixBase<OtherDerived> &other) const
+// {
+// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)(_expression(), other.derived());
+// }
+
+/** \returns an expression of the coefficient-wise == operator of *this and \a other
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * Example: \include Cwise_equal_equal.cpp
+ * Output: \verbinclude Cwise_equal_equal.out
+ *
+ * \sa all(), any(), isApprox(), isMuchSmallerThan()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to)
+// template<typename ExpressionType>
+// template<typename OtherDerived>
+// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
+// operator==(const MatrixBase<OtherDerived> &other) const
+// {
+// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)(_expression(), other.derived());
+// }
+
+/** \returns an expression of the coefficient-wise != operator of *this and \a other
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * Example: \include Cwise_not_equal.cpp
+ * Output: \verbinclude Cwise_not_equal.out
+ *
+ * \sa all(), any(), isApprox(), isMuchSmallerThan()
+ */
+EIGEN_MAKE_CWISE_BINARY_OP(operator!=,std::not_equal_to)
+// template<typename ExpressionType>
+// template<typename OtherDerived>
+// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
+// operator!=(const MatrixBase<OtherDerived> &other) const
+// {
+// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)(_expression(), other.derived());
+// }
+
+// comparisons to scalar value
+
+#if 0
+
+/** \returns an expression of the coefficient-wise \< operator of *this and a scalar \a s
+ *
+ * \sa operator<(const MatrixBase<OtherDerived> &) const
+ */
+template<typename ExpressionType>
+inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
+operator<(Scalar s) const
+{
+ return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)(_expression(),
+ typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
+}
+
+/** \returns an expression of the coefficient-wise \<= operator of *this and a scalar \a s
+ *
+ * \sa operator<=(const MatrixBase<OtherDerived> &) const
+ */
+template<typename ExpressionType>
+inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
+operator<=(Scalar s) const
+{
+ return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)(_expression(),
+ typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
+}
+
+/** \returns an expression of the coefficient-wise \> operator of *this and a scalar \a s
+ *
+ * \sa operator>(const MatrixBase<OtherDerived> &) const
+ */
+template<typename ExpressionType>
+inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
+operator>(Scalar s) const
+{
+ return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)(_expression(),
+ typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
+}
+
+/** \returns an expression of the coefficient-wise \>= operator of *this and a scalar \a s
+ *
+ * \sa operator>=(const MatrixBase<OtherDerived> &) const
+ */
+template<typename ExpressionType>
+inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
+operator>=(Scalar s) const
+{
+ return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)(_expression(),
+ typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
+}
+
+/** \returns an expression of the coefficient-wise == operator of *this and a scalar \a s
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * \sa operator==(const MatrixBase<OtherDerived> &) const
+ */
+template<typename ExpressionType>
+inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
+operator==(Scalar s) const
+{
+ return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)(_expression(),
+ typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
+}
+
+/** \returns an expression of the coefficient-wise != operator of *this and a scalar \a s
+ *
+ * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
+ * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
+ * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
+ * isMuchSmallerThan().
+ *
+ * \sa operator!=(const MatrixBase<OtherDerived> &) const
+ */
+template<typename ExpressionType>
+inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
+operator!=(Scalar s) const
+{
+ return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)(_expression(),
+ typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
+}
+
+#endif
+
+// scalar addition
+
+/** \returns an expression of \c *this with each coeff incremented by the constant \a scalar
+ *
+ * Example: \include Cwise_plus.cpp
+ * Output: \verbinclude Cwise_plus.out
+ *
+ * \sa operator+=(), operator-()
+ */
+inline const CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>
+operator+(const Scalar& scalar) const
+{
+ return CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>(derived(), ei_scalar_add_op<Scalar>(scalar));
+}
+
+/** Adds the given \a scalar to each coeff of this expression.
+ *
+ * Example: \include Cwise_plus_equal.cpp
+ * Output: \verbinclude Cwise_plus_equal.out
+ *
+ * \sa operator+(), operator-=()
+ */
+// template<typename ExpressionType>
+// inline ExpressionType& operator+=(const Scalar& scalar)
+// {
+// return m_matrix.const_cast_derived() = *this + scalar;
+// }
+
+/** \returns an expression of \c *this with each coeff decremented by the constant \a scalar
+ *
+ * Example: \include Cwise_minus.cpp
+ * Output: \verbinclude Cwise_minus.out
+ *
+ * \sa operator+(), operator-=()
+ */
+// template<typename ExpressionType>
+// inline const typename ScalarAddReturnType
+// operator-(const Scalar& scalar) const
+// {
+// return *this + (-scalar);
+// }
+
+/** Substracts the given \a scalar from each coeff of this expression.
+ *
+ * Example: \include Cwise_minus_equal.cpp
+ * Output: \verbinclude Cwise_minus_equal.out
+ *
+ * \sa operator+=(), operator-()
+ */
+
+// template<typename ExpressionType>
+// inline ExpressionType& operator-=(const Scalar& scalar)
+// {
+// return m_matrix.const_cast_derived() = *this - scalar;
+// }