diff options
Diffstat (limited to 'extern/Eigen2/Eigen/src/Array')
-rw-r--r-- | extern/Eigen2/Eigen/src/Array/BooleanRedux.h | 145 | ||||
-rw-r--r-- | extern/Eigen2/Eigen/src/Array/CwiseOperators.h | 453 | ||||
-rw-r--r-- | extern/Eigen2/Eigen/src/Array/Functors.h | 305 | ||||
-rw-r--r-- | extern/Eigen2/Eigen/src/Array/Norms.h | 80 | ||||
-rw-r--r-- | extern/Eigen2/Eigen/src/Array/PartialRedux.h | 342 | ||||
-rw-r--r-- | extern/Eigen2/Eigen/src/Array/Random.h | 156 | ||||
-rw-r--r-- | extern/Eigen2/Eigen/src/Array/Select.h | 159 |
7 files changed, 1640 insertions, 0 deletions
diff --git a/extern/Eigen2/Eigen/src/Array/BooleanRedux.h b/extern/Eigen2/Eigen/src/Array/BooleanRedux.h new file mode 100644 index 00000000000..4e8218327eb --- /dev/null +++ b/extern/Eigen2/Eigen/src/Array/BooleanRedux.h @@ -0,0 +1,145 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_ALLANDANY_H +#define EIGEN_ALLANDANY_H + +template<typename Derived, int UnrollCount> +struct ei_all_unroller +{ + enum { + col = (UnrollCount-1) / Derived::RowsAtCompileTime, + row = (UnrollCount-1) % Derived::RowsAtCompileTime + }; + + inline static bool run(const Derived &mat) + { + return ei_all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col); + } +}; + +template<typename Derived> +struct ei_all_unroller<Derived, 1> +{ + inline static bool run(const Derived &mat) { return mat.coeff(0, 0); } +}; + +template<typename Derived> +struct ei_all_unroller<Derived, Dynamic> +{ + inline static bool run(const Derived &) { return false; } +}; + +template<typename Derived, int UnrollCount> +struct ei_any_unroller +{ + enum { + col = (UnrollCount-1) / Derived::RowsAtCompileTime, + row = (UnrollCount-1) % Derived::RowsAtCompileTime + }; + + inline static bool run(const Derived &mat) + { + return ei_any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col); + } +}; + +template<typename Derived> +struct ei_any_unroller<Derived, 1> +{ + inline static bool run(const Derived &mat) { return mat.coeff(0, 0); } +}; + +template<typename Derived> +struct ei_any_unroller<Derived, Dynamic> +{ + inline static bool run(const Derived &) { return false; } +}; + +/** \array_module + * + * \returns true if all coefficients are true + * + * \addexample CwiseAll \label How to check whether a point is inside a box (using operator< and all()) + * + * Example: \include MatrixBase_all.cpp + * Output: \verbinclude MatrixBase_all.out + * + * \sa MatrixBase::any(), Cwise::operator<() + */ +template<typename Derived> +inline bool MatrixBase<Derived>::all() const +{ + const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) + <= EIGEN_UNROLLING_LIMIT; + if(unroll) + return ei_all_unroller<Derived, + unroll ? int(SizeAtCompileTime) : Dynamic + >::run(derived()); + else + { + for(int j = 0; j < cols(); ++j) + for(int i = 0; i < rows(); ++i) + if (!coeff(i, j)) return false; + return true; + } +} + +/** \array_module + * + * \returns true if at least one coefficient is true + * + * \sa MatrixBase::all() + */ +template<typename Derived> +inline bool MatrixBase<Derived>::any() const +{ + const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) + <= EIGEN_UNROLLING_LIMIT; + if(unroll) + return ei_any_unroller<Derived, + unroll ? int(SizeAtCompileTime) : Dynamic + >::run(derived()); + else + { + for(int j = 0; j < cols(); ++j) + for(int i = 0; i < rows(); ++i) + if (coeff(i, j)) return true; + return false; + } +} + +/** \array_module + * + * \returns the number of coefficients which evaluate to true + * + * \sa MatrixBase::all(), MatrixBase::any() + */ +template<typename Derived> +inline int MatrixBase<Derived>::count() const +{ + return this->cast<bool>().cast<int>().sum(); +} + +#endif // EIGEN_ALLANDANY_H diff --git a/extern/Eigen2/Eigen/src/Array/CwiseOperators.h b/extern/Eigen2/Eigen/src/Array/CwiseOperators.h new file mode 100644 index 00000000000..4b6346daa51 --- /dev/null +++ b/extern/Eigen2/Eigen/src/Array/CwiseOperators.h @@ -0,0 +1,453 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_ARRAY_CWISE_OPERATORS_H +#define EIGEN_ARRAY_CWISE_OPERATORS_H + +// -- unary operators -- + +/** \array_module + * + * \returns an expression of the coefficient-wise square root of *this. + * + * Example: \include Cwise_sqrt.cpp + * Output: \verbinclude Cwise_sqrt.out + * + * \sa pow(), square() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_sqrt_op) +Cwise<ExpressionType>::sqrt() const +{ + return _expression(); +} + +/** \array_module + * + * \returns an expression of the coefficient-wise exponential of *this. + * + * Example: \include Cwise_exp.cpp + * Output: \verbinclude Cwise_exp.out + * + * \sa pow(), log(), sin(), cos() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_exp_op) +Cwise<ExpressionType>::exp() const +{ + return _expression(); +} + +/** \array_module + * + * \returns an expression of the coefficient-wise logarithm of *this. + * + * Example: \include Cwise_log.cpp + * Output: \verbinclude Cwise_log.out + * + * \sa exp() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_log_op) +Cwise<ExpressionType>::log() const +{ + return _expression(); +} + +/** \array_module + * + * \returns an expression of the coefficient-wise cosine of *this. + * + * Example: \include Cwise_cos.cpp + * Output: \verbinclude Cwise_cos.out + * + * \sa sin(), exp() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_cos_op) +Cwise<ExpressionType>::cos() const +{ + return _expression(); +} + + +/** \array_module + * + * \returns an expression of the coefficient-wise sine of *this. + * + * Example: \include Cwise_sin.cpp + * Output: \verbinclude Cwise_sin.out + * + * \sa cos(), exp() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_sin_op) +Cwise<ExpressionType>::sin() const +{ + return _expression(); +} + + +/** \array_module + * + * \returns an expression of the coefficient-wise power of *this to the given exponent. + * + * Example: \include Cwise_pow.cpp + * Output: \verbinclude Cwise_pow.out + * + * \sa exp(), log() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op) +Cwise<ExpressionType>::pow(const Scalar& exponent) const +{ + return EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op)(_expression(), ei_scalar_pow_op<Scalar>(exponent)); +} + + +/** \array_module + * + * \returns an expression of the coefficient-wise inverse of *this. + * + * Example: \include Cwise_inverse.cpp + * Output: \verbinclude Cwise_inverse.out + * + * \sa operator/(), operator*() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_inverse_op) +Cwise<ExpressionType>::inverse() const +{ + return _expression(); +} + +/** \array_module + * + * \returns an expression of the coefficient-wise square of *this. + * + * Example: \include Cwise_square.cpp + * Output: \verbinclude Cwise_square.out + * + * \sa operator/(), operator*(), abs2() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_square_op) +Cwise<ExpressionType>::square() const +{ + return _expression(); +} + +/** \array_module + * + * \returns an expression of the coefficient-wise cube of *this. + * + * Example: \include Cwise_cube.cpp + * Output: \verbinclude Cwise_cube.out + * + * \sa square(), pow() + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_cube_op) +Cwise<ExpressionType>::cube() const +{ + return _expression(); +} + + +// -- binary operators -- + +/** \array_module + * + * \returns an expression of the coefficient-wise \< operator of *this and \a other + * + * Example: \include Cwise_less.cpp + * Output: \verbinclude Cwise_less.out + * + * \sa MatrixBase::all(), MatrixBase::any(), operator>(), operator<=() + */ +template<typename ExpressionType> +template<typename OtherDerived> +inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less) +Cwise<ExpressionType>::operator<(const MatrixBase<OtherDerived> &other) const +{ + return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)(_expression(), other.derived()); +} + +/** \array_module + * + * \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 MatrixBase::all(), MatrixBase::any(), operator>=(), operator<() + */ +template<typename ExpressionType> +template<typename OtherDerived> +inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal) +Cwise<ExpressionType>::operator<=(const MatrixBase<OtherDerived> &other) const +{ + return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)(_expression(), other.derived()); +} + +/** \array_module + * + * \returns an expression of the coefficient-wise \> operator of *this and \a other + * + * Example: \include Cwise_greater.cpp + * Output: \verbinclude Cwise_greater.out + * + * \sa MatrixBase::all(), MatrixBase::any(), operator>=(), operator<() + */ +template<typename ExpressionType> +template<typename OtherDerived> +inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater) +Cwise<ExpressionType>::operator>(const MatrixBase<OtherDerived> &other) const +{ + return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)(_expression(), other.derived()); +} + +/** \array_module + * + * \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 MatrixBase::all(), MatrixBase::any(), operator>(), operator<=() + */ +template<typename ExpressionType> +template<typename OtherDerived> +inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal) +Cwise<ExpressionType>::operator>=(const MatrixBase<OtherDerived> &other) const +{ + return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)(_expression(), other.derived()); +} + +/** \array_module + * + * \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 MatrixBase::isApprox() and + * MatrixBase::isMuchSmallerThan(). + * + * Example: \include Cwise_equal_equal.cpp + * Output: \verbinclude Cwise_equal_equal.out + * + * \sa MatrixBase::all(), MatrixBase::any(), MatrixBase::isApprox(), MatrixBase::isMuchSmallerThan() + */ +template<typename ExpressionType> +template<typename OtherDerived> +inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to) +Cwise<ExpressionType>::operator==(const MatrixBase<OtherDerived> &other) const +{ + return EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)(_expression(), other.derived()); +} + +/** \array_module + * + * \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 MatrixBase::isApprox() and + * MatrixBase::isMuchSmallerThan(). + * + * Example: \include Cwise_not_equal.cpp + * Output: \verbinclude Cwise_not_equal.out + * + * \sa MatrixBase::all(), MatrixBase::any(), MatrixBase::isApprox(), MatrixBase::isMuchSmallerThan() + */ +template<typename ExpressionType> +template<typename OtherDerived> +inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to) +Cwise<ExpressionType>::operator!=(const MatrixBase<OtherDerived> &other) const +{ + return EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)(_expression(), other.derived()); +} + +// comparisons to scalar value + +/** \array_module + * + * \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) +Cwise<ExpressionType>::operator<(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \array_module + * + * \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) +Cwise<ExpressionType>::operator<=(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \array_module + * + * \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) +Cwise<ExpressionType>::operator>(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \array_module + * + * \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) +Cwise<ExpressionType>::operator>=(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \array_module + * + * \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 MatrixBase::isApprox() and + * MatrixBase::isMuchSmallerThan(). + * + * \sa operator==(const MatrixBase<OtherDerived> &) const + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to) +Cwise<ExpressionType>::operator==(Scalar s) const +{ + return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)(_expression(), + typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s)); +} + +/** \array_module + * + * \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 MatrixBase::isApprox() and + * MatrixBase::isMuchSmallerThan(). + * + * \sa operator!=(const MatrixBase<OtherDerived> &) const + */ +template<typename ExpressionType> +inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to) +Cwise<ExpressionType>::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)); +} + +// scalar addition + +/** \array_module + * + * \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-() + */ +template<typename ExpressionType> +inline const typename Cwise<ExpressionType>::ScalarAddReturnType +Cwise<ExpressionType>::operator+(const Scalar& scalar) const +{ + return typename Cwise<ExpressionType>::ScalarAddReturnType(m_matrix, ei_scalar_add_op<Scalar>(scalar)); +} + +/** \array_module + * + * 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& Cwise<ExpressionType>::operator+=(const Scalar& scalar) +{ + return m_matrix.const_cast_derived() = *this + scalar; +} + +/** \array_module + * + * \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 Cwise<ExpressionType>::ScalarAddReturnType +Cwise<ExpressionType>::operator-(const Scalar& scalar) const +{ + return *this + (-scalar); +} + +/** \array_module + * + * 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& Cwise<ExpressionType>::operator-=(const Scalar& scalar) +{ + return m_matrix.const_cast_derived() = *this - scalar; +} + +#endif // EIGEN_ARRAY_CWISE_OPERATORS_H diff --git a/extern/Eigen2/Eigen/src/Array/Functors.h b/extern/Eigen2/Eigen/src/Array/Functors.h new file mode 100644 index 00000000000..0aae7fd2c40 --- /dev/null +++ b/extern/Eigen2/Eigen/src/Array/Functors.h @@ -0,0 +1,305 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_ARRAY_FUNCTORS_H +#define EIGEN_ARRAY_FUNCTORS_H + +/** \internal + * \array_module + * + * \brief Template functor to add a scalar to a fixed other one + * + * \sa class CwiseUnaryOp, Array::operator+ + */ +/* If you wonder why doing the ei_pset1() in packetOp() is an optimization check ei_scalar_multiple_op */ +template<typename Scalar> +struct ei_scalar_add_op { + typedef typename ei_packet_traits<Scalar>::type PacketScalar; + // FIXME default copy constructors seems bugged with std::complex<> + inline ei_scalar_add_op(const ei_scalar_add_op& other) : m_other(other.m_other) { } + inline ei_scalar_add_op(const Scalar& other) : m_other(other) { } + inline Scalar operator() (const Scalar& a) const { return a + m_other; } + inline const PacketScalar packetOp(const PacketScalar& a) const + { return ei_padd(a, ei_pset1(m_other)); } + const Scalar m_other; +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_add_op<Scalar> > +{ enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = ei_packet_traits<Scalar>::size>1 }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to compute the square root of a scalar + * + * \sa class CwiseUnaryOp, Cwise::sqrt() + */ +template<typename Scalar> struct ei_scalar_sqrt_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_sqrt(a); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_sqrt_op<Scalar> > +{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to compute the exponential of a scalar + * + * \sa class CwiseUnaryOp, Cwise::exp() + */ +template<typename Scalar> struct ei_scalar_exp_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_exp(a); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_exp_op<Scalar> > +{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to compute the logarithm of a scalar + * + * \sa class CwiseUnaryOp, Cwise::log() + */ +template<typename Scalar> struct ei_scalar_log_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_log(a); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_log_op<Scalar> > +{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to compute the cosine of a scalar + * + * \sa class CwiseUnaryOp, Cwise::cos() + */ +template<typename Scalar> struct ei_scalar_cos_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_cos(a); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_cos_op<Scalar> > +{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to compute the sine of a scalar + * + * \sa class CwiseUnaryOp, Cwise::sin() + */ +template<typename Scalar> struct ei_scalar_sin_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_sin(a); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_sin_op<Scalar> > +{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to raise a scalar to a power + * + * \sa class CwiseUnaryOp, Cwise::pow + */ +template<typename Scalar> +struct ei_scalar_pow_op { + // FIXME default copy constructors seems bugged with std::complex<> + inline ei_scalar_pow_op(const ei_scalar_pow_op& other) : m_exponent(other.m_exponent) { } + inline ei_scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {} + inline Scalar operator() (const Scalar& a) const { return ei_pow(a, m_exponent); } + const Scalar m_exponent; +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_pow_op<Scalar> > +{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to compute the inverse of a scalar + * + * \sa class CwiseUnaryOp, Cwise::inverse() + */ +template<typename Scalar> +struct ei_scalar_inverse_op { + inline Scalar operator() (const Scalar& a) const { return Scalar(1)/a; } + template<typename PacketScalar> + inline const PacketScalar packetOp(const PacketScalar& a) const + { return ei_pdiv(ei_pset1(Scalar(1)),a); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_inverse_op<Scalar> > +{ enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = int(ei_packet_traits<Scalar>::size)>1 }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to compute the square of a scalar + * + * \sa class CwiseUnaryOp, Cwise::square() + */ +template<typename Scalar> +struct ei_scalar_square_op { + inline Scalar operator() (const Scalar& a) const { return a*a; } + template<typename PacketScalar> + inline const PacketScalar packetOp(const PacketScalar& a) const + { return ei_pmul(a,a); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_square_op<Scalar> > +{ enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = int(ei_packet_traits<Scalar>::size)>1 }; }; + +/** \internal + * + * \array_module + * + * \brief Template functor to compute the cube of a scalar + * + * \sa class CwiseUnaryOp, Cwise::cube() + */ +template<typename Scalar> +struct ei_scalar_cube_op { + inline Scalar operator() (const Scalar& a) const { return a*a*a; } + template<typename PacketScalar> + inline const PacketScalar packetOp(const PacketScalar& a) const + { return ei_pmul(a,ei_pmul(a,a)); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_cube_op<Scalar> > +{ enum { Cost = 2*NumTraits<Scalar>::MulCost, PacketAccess = int(ei_packet_traits<Scalar>::size)>1 }; }; + +// default ei_functor_traits for STL functors: + +template<typename T> +struct ei_functor_traits<std::multiplies<T> > +{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::divides<T> > +{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::plus<T> > +{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::minus<T> > +{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::negate<T> > +{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::logical_or<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::logical_and<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::logical_not<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::greater<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::less<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::greater_equal<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::less_equal<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::equal_to<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::not_equal_to<T> > +{ enum { Cost = 1, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::binder2nd<T> > +{ enum { Cost = ei_functor_traits<T>::Cost, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::binder1st<T> > +{ enum { Cost = ei_functor_traits<T>::Cost, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::unary_negate<T> > +{ enum { Cost = 1 + ei_functor_traits<T>::Cost, PacketAccess = false }; }; + +template<typename T> +struct ei_functor_traits<std::binary_negate<T> > +{ enum { Cost = 1 + ei_functor_traits<T>::Cost, PacketAccess = false }; }; + +#ifdef EIGEN_STDEXT_SUPPORT + +template<typename T0,typename T1> +struct ei_functor_traits<std::project1st<T0,T1> > +{ enum { Cost = 0, PacketAccess = false }; }; + +template<typename T0,typename T1> +struct ei_functor_traits<std::project2nd<T0,T1> > +{ enum { Cost = 0, PacketAccess = false }; }; + +template<typename T0,typename T1> +struct ei_functor_traits<std::select2nd<std::pair<T0,T1> > > +{ enum { Cost = 0, PacketAccess = false }; }; + +template<typename T0,typename T1> +struct ei_functor_traits<std::select1st<std::pair<T0,T1> > > +{ enum { Cost = 0, PacketAccess = false }; }; + +template<typename T0,typename T1> +struct ei_functor_traits<std::unary_compose<T0,T1> > +{ enum { Cost = ei_functor_traits<T0>::Cost + ei_functor_traits<T1>::Cost, PacketAccess = false }; }; + +template<typename T0,typename T1,typename T2> +struct ei_functor_traits<std::binary_compose<T0,T1,T2> > +{ enum { Cost = ei_functor_traits<T0>::Cost + ei_functor_traits<T1>::Cost + ei_functor_traits<T2>::Cost, PacketAccess = false }; }; + +#endif // EIGEN_STDEXT_SUPPORT + +#endif // EIGEN_ARRAY_FUNCTORS_H diff --git a/extern/Eigen2/Eigen/src/Array/Norms.h b/extern/Eigen2/Eigen/src/Array/Norms.h new file mode 100644 index 00000000000..6b92e6a099d --- /dev/null +++ b/extern/Eigen2/Eigen/src/Array/Norms.h @@ -0,0 +1,80 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_ARRAY_NORMS_H +#define EIGEN_ARRAY_NORMS_H + +template<typename Derived, int p> +struct ei_lpNorm_selector +{ + typedef typename NumTraits<typename ei_traits<Derived>::Scalar>::Real RealScalar; + inline static RealScalar run(const MatrixBase<Derived>& m) + { + return ei_pow(m.cwise().abs().cwise().pow(p).sum(), RealScalar(1)/p); + } +}; + +template<typename Derived> +struct ei_lpNorm_selector<Derived, 1> +{ + inline static typename NumTraits<typename ei_traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m) + { + return m.cwise().abs().sum(); + } +}; + +template<typename Derived> +struct ei_lpNorm_selector<Derived, 2> +{ + inline static typename NumTraits<typename ei_traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m) + { + return m.norm(); + } +}; + +template<typename Derived> +struct ei_lpNorm_selector<Derived, Infinity> +{ + inline static typename NumTraits<typename ei_traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m) + { + return m.cwise().abs().maxCoeff(); + } +}; + +/** \array_module + * + * \returns the \f$ \ell^p \f$ norm of *this, that is, returns the p-th root of the sum of the p-th powers of the absolute values + * of the coefficients of *this. If \a p is the special value \a Eigen::Infinity, this function returns the \f$ \ell^p\infty \f$ + * norm, that is the maximum of the absolute values of the coefficients of *this. + * + * \sa norm() + */ +template<typename Derived> +template<int p> +inline typename NumTraits<typename ei_traits<Derived>::Scalar>::Real MatrixBase<Derived>::lpNorm() const +{ + return ei_lpNorm_selector<Derived, p>::run(*this); +} + +#endif // EIGEN_ARRAY_NORMS_H diff --git a/extern/Eigen2/Eigen/src/Array/PartialRedux.h b/extern/Eigen2/Eigen/src/Array/PartialRedux.h new file mode 100644 index 00000000000..b1e8fd4babd --- /dev/null +++ b/extern/Eigen2/Eigen/src/Array/PartialRedux.h @@ -0,0 +1,342 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_PARTIAL_REDUX_H +#define EIGEN_PARTIAL_REDUX_H + +/** \array_module \ingroup Array + * + * \class PartialReduxExpr + * + * \brief Generic expression of a partially reduxed matrix + * + * \param MatrixType the type of the matrix we are applying the redux operation + * \param MemberOp type of the member functor + * \param Direction indicates the direction of the redux (Vertical or Horizontal) + * + * This class represents an expression of a partial redux operator of a matrix. + * It is the return type of PartialRedux functions, + * and most of the time this is the only way it is used. + * + * \sa class PartialRedux + */ + +template< typename MatrixType, typename MemberOp, int Direction> +class PartialReduxExpr; + +template<typename MatrixType, typename MemberOp, int Direction> +struct ei_traits<PartialReduxExpr<MatrixType, MemberOp, Direction> > +{ + typedef typename MemberOp::result_type Scalar; + typedef typename MatrixType::Scalar InputScalar; + typedef typename ei_nested<MatrixType>::type MatrixTypeNested; + typedef typename ei_cleantype<MatrixTypeNested>::type _MatrixTypeNested; + enum { + RowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::RowsAtCompileTime, + ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime, + Flags = (unsigned int)_MatrixTypeNested::Flags & HereditaryBits, + TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime + }; + #if EIGEN_GNUC_AT_LEAST(3,4) + typedef typename MemberOp::template Cost<InputScalar,int(TraversalSize)> CostOpType; + #else + typedef typename MemberOp::template Cost<InputScalar,TraversalSize> CostOpType; + #endif + enum { + CoeffReadCost = TraversalSize * ei_traits<_MatrixTypeNested>::CoeffReadCost + int(CostOpType::value) + }; +}; + +template< typename MatrixType, typename MemberOp, int Direction> +class PartialReduxExpr : ei_no_assignment_operator, + public MatrixBase<PartialReduxExpr<MatrixType, MemberOp, Direction> > +{ + public: + + EIGEN_GENERIC_PUBLIC_INTERFACE(PartialReduxExpr) + typedef typename ei_traits<PartialReduxExpr>::MatrixTypeNested MatrixTypeNested; + typedef typename ei_traits<PartialReduxExpr>::_MatrixTypeNested _MatrixTypeNested; + + PartialReduxExpr(const MatrixType& mat, const MemberOp& func = MemberOp()) + : m_matrix(mat), m_functor(func) {} + + int rows() const { return (Direction==Vertical ? 1 : m_matrix.rows()); } + int cols() const { return (Direction==Horizontal ? 1 : m_matrix.cols()); } + + const Scalar coeff(int i, int j) const + { + if (Direction==Vertical) + return m_functor(m_matrix.col(j)); + else + return m_functor(m_matrix.row(i)); + } + + protected: + const MatrixTypeNested m_matrix; + const MemberOp m_functor; +}; + +#define EIGEN_MEMBER_FUNCTOR(MEMBER,COST) \ + template <typename ResultType> \ + struct ei_member_##MEMBER EIGEN_EMPTY_STRUCT { \ + typedef ResultType result_type; \ + template<typename Scalar, int Size> struct Cost \ + { enum { value = COST }; }; \ + template<typename Derived> \ + inline ResultType operator()(const MatrixBase<Derived>& mat) const \ + { return mat.MEMBER(); } \ + } + +EIGEN_MEMBER_FUNCTOR(squaredNorm, Size * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(norm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(sum, (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(minCoeff, (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(maxCoeff, (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(all, (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(any, (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(count, (Size-1)*NumTraits<Scalar>::AddCost); + +/** \internal */ +template <typename BinaryOp, typename Scalar> +struct ei_member_redux { + typedef typename ei_result_of< + BinaryOp(Scalar) + >::type result_type; + template<typename _Scalar, int Size> struct Cost + { enum { value = (Size-1) * ei_functor_traits<BinaryOp>::Cost }; }; + ei_member_redux(const BinaryOp func) : m_functor(func) {} + template<typename Derived> + inline result_type operator()(const MatrixBase<Derived>& mat) const + { return mat.redux(m_functor); } + const BinaryOp m_functor; +}; + +/** \array_module \ingroup Array + * + * \class PartialRedux + * + * \brief Pseudo expression providing partial reduction operations + * + * \param ExpressionType the type of the object on which to do partial reductions + * \param Direction indicates the direction of the redux (Vertical or Horizontal) + * + * This class represents a pseudo expression with partial reduction features. + * It is the return type of MatrixBase::colwise() and MatrixBase::rowwise() + * and most of the time this is the only way it is used. + * + * Example: \include MatrixBase_colwise.cpp + * Output: \verbinclude MatrixBase_colwise.out + * + * \sa MatrixBase::colwise(), MatrixBase::rowwise(), class PartialReduxExpr + */ +template<typename ExpressionType, int Direction> class PartialRedux +{ + public: + + typedef typename ei_traits<ExpressionType>::Scalar Scalar; + typedef typename ei_meta_if<ei_must_nest_by_value<ExpressionType>::ret, + ExpressionType, const ExpressionType&>::ret ExpressionTypeNested; + + template<template<typename _Scalar> class Functor> struct ReturnType + { + typedef PartialReduxExpr<ExpressionType, + Functor<typename ei_traits<ExpressionType>::Scalar>, + Direction + > Type; + }; + + template<typename BinaryOp> struct ReduxReturnType + { + typedef PartialReduxExpr<ExpressionType, + ei_member_redux<BinaryOp,typename ei_traits<ExpressionType>::Scalar>, + Direction + > Type; + }; + + typedef typename ExpressionType::PlainMatrixType CrossReturnType; + + inline PartialRedux(const ExpressionType& matrix) : m_matrix(matrix) {} + + /** \internal */ + inline const ExpressionType& _expression() const { return m_matrix; } + + template<typename BinaryOp> + const typename ReduxReturnType<BinaryOp>::Type + redux(const BinaryOp& func = BinaryOp()) const; + + /** \returns a row (or column) vector expression of the smallest coefficient + * of each column (or row) of the referenced expression. + * + * Example: \include PartialRedux_minCoeff.cpp + * Output: \verbinclude PartialRedux_minCoeff.out + * + * \sa MatrixBase::minCoeff() */ + const typename ReturnType<ei_member_minCoeff>::Type minCoeff() const + { return _expression(); } + + /** \returns a row (or column) vector expression of the largest coefficient + * of each column (or row) of the referenced expression. + * + * Example: \include PartialRedux_maxCoeff.cpp + * Output: \verbinclude PartialRedux_maxCoeff.out + * + * \sa MatrixBase::maxCoeff() */ + const typename ReturnType<ei_member_maxCoeff>::Type maxCoeff() const + { return _expression(); } + + /** \returns a row (or column) vector expression of the squared norm + * of each column (or row) of the referenced expression. + * + * Example: \include PartialRedux_squaredNorm.cpp + * Output: \verbinclude PartialRedux_squaredNorm.out + * + * \sa MatrixBase::squaredNorm() */ + const typename ReturnType<ei_member_squaredNorm>::Type squaredNorm() const + { return _expression(); } + + /** \returns a row (or column) vector expression of the norm + * of each column (or row) of the referenced expression. + * + * Example: \include PartialRedux_norm.cpp + * Output: \verbinclude PartialRedux_norm.out + * + * \sa MatrixBase::norm() */ + const typename ReturnType<ei_member_norm>::Type norm() const + { return _expression(); } + + /** \returns a row (or column) vector expression of the sum + * of each column (or row) of the referenced expression. + * + * Example: \include PartialRedux_sum.cpp + * Output: \verbinclude PartialRedux_sum.out + * + * \sa MatrixBase::sum() */ + const typename ReturnType<ei_member_sum>::Type sum() const + { return _expression(); } + + /** \returns a row (or column) vector expression representing + * whether \b all coefficients of each respective column (or row) are \c true. + * + * \sa MatrixBase::all() */ + const typename ReturnType<ei_member_all>::Type all() const + { return _expression(); } + + /** \returns a row (or column) vector expression representing + * whether \b at \b least one coefficient of each respective column (or row) is \c true. + * + * \sa MatrixBase::any() */ + const typename ReturnType<ei_member_any>::Type any() const + { return _expression(); } + + /** \returns a row (or column) vector expression representing + * the number of \c true coefficients of each respective column (or row). + * + * Example: \include PartialRedux_count.cpp + * Output: \verbinclude PartialRedux_count.out + * + * \sa MatrixBase::count() */ + const PartialReduxExpr<ExpressionType, ei_member_count<int>, Direction> count() const + { return _expression(); } + + /** \returns a 3x3 matrix expression of the cross product + * of each column or row of the referenced expression with the \a other vector. + * + * \geometry_module + * + * \sa MatrixBase::cross() */ + template<typename OtherDerived> + const CrossReturnType cross(const MatrixBase<OtherDerived>& other) const + { + EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(CrossReturnType,3,3) + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3) + EIGEN_STATIC_ASSERT((ei_is_same_type<Scalar, typename OtherDerived::Scalar>::ret), + YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) + + if(Direction==Vertical) + return (CrossReturnType() + << _expression().col(0).cross(other), + _expression().col(1).cross(other), + _expression().col(2).cross(other)).finished(); + else + return (CrossReturnType() + << _expression().row(0).cross(other), + _expression().row(1).cross(other), + _expression().row(2).cross(other)).finished(); + } + + protected: + ExpressionTypeNested m_matrix; +}; + +/** \array_module + * + * \returns a PartialRedux wrapper of *this providing additional partial reduction operations + * + * Example: \include MatrixBase_colwise.cpp + * Output: \verbinclude MatrixBase_colwise.out + * + * \sa rowwise(), class PartialRedux + */ +template<typename Derived> +inline const PartialRedux<Derived,Vertical> +MatrixBase<Derived>::colwise() const +{ + return derived(); +} + +/** \array_module + * + * \returns a PartialRedux wrapper of *this providing additional partial reduction operations + * + * Example: \include MatrixBase_rowwise.cpp + * Output: \verbinclude MatrixBase_rowwise.out + * + * \sa colwise(), class PartialRedux + */ +template<typename Derived> +inline const PartialRedux<Derived,Horizontal> +MatrixBase<Derived>::rowwise() const +{ + return derived(); +} + +/** \returns a row or column vector expression of \c *this reduxed by \a func + * + * The template parameter \a BinaryOp is the type of the functor + * of the custom redux operator. Note that func must be an associative operator. + * + * \sa class PartialRedux, MatrixBase::colwise(), MatrixBase::rowwise() + */ +template<typename ExpressionType, int Direction> +template<typename BinaryOp> +const typename PartialRedux<ExpressionType,Direction>::template ReduxReturnType<BinaryOp>::Type +PartialRedux<ExpressionType,Direction>::redux(const BinaryOp& func) const +{ + return typename ReduxReturnType<BinaryOp>::Type(_expression(), func); +} + +#endif // EIGEN_PARTIAL_REDUX_H diff --git a/extern/Eigen2/Eigen/src/Array/Random.h b/extern/Eigen2/Eigen/src/Array/Random.h new file mode 100644 index 00000000000..9185fe4a7d3 --- /dev/null +++ b/extern/Eigen2/Eigen/src/Array/Random.h @@ -0,0 +1,156 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_RANDOM_H +#define EIGEN_RANDOM_H + +template<typename Scalar> struct ei_scalar_random_op EIGEN_EMPTY_STRUCT { + inline ei_scalar_random_op(void) {} + inline const Scalar operator() (int, int) const { return ei_random<Scalar>(); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_random_op<Scalar> > +{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; }; + +/** \array_module + * + * \returns a random matrix (not an expression, the matrix is immediately evaluated). + * + * The parameters \a rows and \a cols are the number of rows and of columns of + * the returned matrix. Must be compatible with this MatrixBase type. + * + * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, + * it is redundant to pass \a rows and \a cols as arguments, so ei_random() should be used + * instead. + * + * \addexample RandomExample \label How to create a matrix with random coefficients + * + * Example: \include MatrixBase_random_int_int.cpp + * Output: \verbinclude MatrixBase_random_int_int.out + * + * \sa MatrixBase::setRandom(), MatrixBase::Random(int), MatrixBase::Random() + */ +template<typename Derived> +inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived> +MatrixBase<Derived>::Random(int rows, int cols) +{ + return NullaryExpr(rows, cols, ei_scalar_random_op<Scalar>()); +} + +/** \array_module + * + * \returns a random vector (not an expression, the vector is immediately evaluated). + * + * The parameter \a size is the size of the returned vector. + * Must be compatible with this MatrixBase type. + * + * \only_for_vectors + * + * This variant is meant to be used for dynamic-size vector types. For fixed-size types, + * it is redundant to pass \a size as argument, so ei_random() should be used + * instead. + * + * Example: \include MatrixBase_random_int.cpp + * Output: \verbinclude MatrixBase_random_int.out + * + * \sa MatrixBase::setRandom(), MatrixBase::Random(int,int), MatrixBase::Random() + */ +template<typename Derived> +inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived> +MatrixBase<Derived>::Random(int size) +{ + return NullaryExpr(size, ei_scalar_random_op<Scalar>()); +} + +/** \array_module + * + * \returns a fixed-size random matrix or vector + * (not an expression, the matrix is immediately evaluated). + * + * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you + * need to use the variants taking size arguments. + * + * Example: \include MatrixBase_random.cpp + * Output: \verbinclude MatrixBase_random.out + * + * \sa MatrixBase::setRandom(), MatrixBase::Random(int,int), MatrixBase::Random(int) + */ +template<typename Derived> +inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived> +MatrixBase<Derived>::Random() +{ + return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op<Scalar>()); +} + +/** \array_module + * + * Sets all coefficients in this expression to random values. + * + * Example: \include MatrixBase_setRandom.cpp + * Output: \verbinclude MatrixBase_setRandom.out + * + * \sa class CwiseNullaryOp, setRandom(int), setRandom(int,int) + */ +template<typename Derived> +inline Derived& MatrixBase<Derived>::setRandom() +{ + return *this = Random(rows(), cols()); +} + +/** Resizes to the given \a size, and sets all coefficients in this expression to random values. + * + * \only_for_vectors + * + * Example: \include Matrix_setRandom_int.cpp + * Output: \verbinclude Matrix_setRandom_int.out + * + * \sa MatrixBase::setRandom(), setRandom(int,int), class CwiseNullaryOp, MatrixBase::Random() + */ +template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> +EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& +Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setRandom(int size) +{ + resize(size); + return setRandom(); +} + +/** Resizes to the given size, and sets all coefficients in this expression to random values. + * + * \param rows the new number of rows + * \param cols the new number of columns + * + * Example: \include Matrix_setRandom_int_int.cpp + * Output: \verbinclude Matrix_setRandom_int_int.out + * + * \sa MatrixBase::setRandom(), setRandom(int), class CwiseNullaryOp, MatrixBase::Random() + */ +template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> +EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& +Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setRandom(int rows, int cols) +{ + resize(rows, cols); + return setRandom(); +} + +#endif // EIGEN_RANDOM_H diff --git a/extern/Eigen2/Eigen/src/Array/Select.h b/extern/Eigen2/Eigen/src/Array/Select.h new file mode 100644 index 00000000000..9dc3fb1b27a --- /dev/null +++ b/extern/Eigen2/Eigen/src/Array/Select.h @@ -0,0 +1,159 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_SELECT_H +#define EIGEN_SELECT_H + +/** \array_module \ingroup Array + * + * \class Select + * + * \brief Expression of a coefficient wise version of the C++ ternary operator ?: + * + * \param ConditionMatrixType the type of the \em condition expression which must be a boolean matrix + * \param ThenMatrixType the type of the \em then expression + * \param ElseMatrixType the type of the \em else expression + * + * This class represents an expression of a coefficient wise version of the C++ ternary operator ?:. + * It is the return type of MatrixBase::select() and most of the time this is the only way it is used. + * + * \sa MatrixBase::select(const MatrixBase<ThenDerived>&, const MatrixBase<ElseDerived>&) const + */ + +template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType> +struct ei_traits<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> > +{ + typedef typename ei_traits<ThenMatrixType>::Scalar Scalar; + typedef typename ConditionMatrixType::Nested ConditionMatrixNested; + typedef typename ThenMatrixType::Nested ThenMatrixNested; + typedef typename ElseMatrixType::Nested ElseMatrixNested; + enum { + RowsAtCompileTime = ConditionMatrixType::RowsAtCompileTime, + ColsAtCompileTime = ConditionMatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = ConditionMatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = ConditionMatrixType::MaxColsAtCompileTime, + Flags = (unsigned int)ThenMatrixType::Flags & ElseMatrixType::Flags & HereditaryBits, + CoeffReadCost = ei_traits<typename ei_cleantype<ConditionMatrixNested>::type>::CoeffReadCost + + EIGEN_ENUM_MAX(ei_traits<typename ei_cleantype<ThenMatrixNested>::type>::CoeffReadCost, + ei_traits<typename ei_cleantype<ElseMatrixNested>::type>::CoeffReadCost) + }; +}; + +template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType> +class Select : ei_no_assignment_operator, + public MatrixBase<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> > +{ + public: + + EIGEN_GENERIC_PUBLIC_INTERFACE(Select) + + Select(const ConditionMatrixType& conditionMatrix, + const ThenMatrixType& thenMatrix, + const ElseMatrixType& elseMatrix) + : m_condition(conditionMatrix), m_then(thenMatrix), m_else(elseMatrix) + { + ei_assert(m_condition.rows() == m_then.rows() && m_condition.rows() == m_else.rows()); + ei_assert(m_condition.cols() == m_then.cols() && m_condition.cols() == m_else.cols()); + } + + int rows() const { return m_condition.rows(); } + int cols() const { return m_condition.cols(); } + + const Scalar coeff(int i, int j) const + { + if (m_condition.coeff(i,j)) + return m_then.coeff(i,j); + else + return m_else.coeff(i,j); + } + + const Scalar coeff(int i) const + { + if (m_condition.coeff(i)) + return m_then.coeff(i); + else + return m_else.coeff(i); + } + + protected: + const typename ConditionMatrixType::Nested m_condition; + const typename ThenMatrixType::Nested m_then; + const typename ElseMatrixType::Nested m_else; +}; + + +/** \array_module + * + * \returns a matrix where each coefficient (i,j) is equal to \a thenMatrix(i,j) + * if \c *this(i,j), and \a elseMatrix(i,j) otherwise. + * + * Example: \include MatrixBase_select.cpp + * Output: \verbinclude MatrixBase_select.out + * + * \sa class Select + */ +template<typename Derived> +template<typename ThenDerived,typename ElseDerived> +inline const Select<Derived,ThenDerived,ElseDerived> +MatrixBase<Derived>::select(const MatrixBase<ThenDerived>& thenMatrix, + const MatrixBase<ElseDerived>& elseMatrix) const +{ + return Select<Derived,ThenDerived,ElseDerived>(derived(), thenMatrix.derived(), elseMatrix.derived()); +} + +/** \array_module + * + * Version of MatrixBase::select(const MatrixBase&, const MatrixBase&) with + * the \em else expression being a scalar value. + * + * \sa MatrixBase::select(const MatrixBase<ThenDerived>&, const MatrixBase<ElseDerived>&) const, class Select + */ +template<typename Derived> +template<typename ThenDerived> +inline const Select<Derived,ThenDerived, NestByValue<typename ThenDerived::ConstantReturnType> > +MatrixBase<Derived>::select(const MatrixBase<ThenDerived>& thenMatrix, + typename ThenDerived::Scalar elseScalar) const +{ + return Select<Derived,ThenDerived,NestByValue<typename ThenDerived::ConstantReturnType> >( + derived(), thenMatrix.derived(), ThenDerived::Constant(rows(),cols(),elseScalar)); +} + +/** \array_module + * + * Version of MatrixBase::select(const MatrixBase&, const MatrixBase&) with + * the \em then expression being a scalar value. + * + * \sa MatrixBase::select(const MatrixBase<ThenDerived>&, const MatrixBase<ElseDerived>&) const, class Select + */ +template<typename Derived> +template<typename ElseDerived> +inline const Select<Derived, NestByValue<typename ElseDerived::ConstantReturnType>, ElseDerived > +MatrixBase<Derived>::select(typename ElseDerived::Scalar thenScalar, + const MatrixBase<ElseDerived>& elseMatrix) const +{ + return Select<Derived,NestByValue<typename ElseDerived::ConstantReturnType>,ElseDerived>( + derived(), ElseDerived::Constant(rows(),cols(),thenScalar), elseMatrix.derived()); +} + +#endif // EIGEN_SELECT_H |