// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008 Gael Guennebaud <[email protected]> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifndef EIGEN_VISITOR_H #define EIGEN_VISITOR_H // IWYU pragma: private #include "./InternalHeaderCheck.h" namespace Eigen { namespace internal { template <typename Visitor, typename Derived, int UnrollCount, bool Vectorize = (Derived::PacketAccess && functor_traits<Visitor>::PacketAccess), bool LinearAccess = false, bool ShortCircuitEvaluation = false> struct visitor_impl; template <typename Visitor, bool ShortCircuitEvaluation = false> struct short_circuit_eval_impl { … }; short_circuit_eval_impl<Visitor, true>; // unrolled inner-outer traversal visitor_impl<Visitor, Derived, UnrollCount, Vectorize, false, ShortCircuitEvaluation>; // unrolled linear traversal visitor_impl<Visitor, Derived, UnrollCount, Vectorize, true, ShortCircuitEvaluation>; // dynamic scalar outer-inner traversal visitor_impl<Visitor, Derived, Dynamic, false, false, ShortCircuitEvaluation>; // dynamic vectorized outer-inner traversal visitor_impl<Visitor, Derived, Dynamic, true, false, ShortCircuitEvaluation>; // dynamic scalar linear traversal visitor_impl<Visitor, Derived, Dynamic, false, true, ShortCircuitEvaluation>; // dynamic vectorized linear traversal visitor_impl<Visitor, Derived, Dynamic, true, true, ShortCircuitEvaluation>; // evaluator adaptor template <typename XprType> class visitor_evaluator { … }; template <typename Derived, typename Visitor, bool ShortCircuitEvaulation> struct visit_impl { … }; } // end namespace internal /** Applies the visitor \a visitor to the whole coefficients of the matrix or vector. * * The template parameter \a Visitor is the type of the visitor and provides the following interface: * \code * struct MyVisitor { * // called for the first coefficient * void init(const Scalar& value, Index i, Index j); * // called for all other coefficients * void operator() (const Scalar& value, Index i, Index j); * }; * \endcode * * \note compared to one or two \em for \em loops, visitors offer automatic * unrolling for small fixed size matrix. * * \note if the matrix is empty, then the visitor is left unchanged. * * \sa minCoeff(Index*,Index*), maxCoeff(Index*,Index*), DenseBase::redux() */ template <typename Derived> template <typename Visitor> EIGEN_DEVICE_FUNC void DenseBase<Derived>::visit(Visitor& visitor) const { … } namespace internal { /** \internal * \brief Base class to implement min and max visitors */ template <typename Derived> struct coeff_visitor { … }; template <typename Scalar, int NaNPropagation, bool is_min = true> struct minmax_compare { … }; minmax_compare<Scalar, NaNPropagation, false>; // Default implementation used by non-floating types, where we do not // need special logic for NaN handling. template <typename Derived, bool is_min, int NaNPropagation, bool isInt = NumTraits<typename Derived::Scalar>::IsInteger> struct minmax_coeff_visitor : coeff_visitor<Derived> { … }; // Suppress NaN. The only case in which we return NaN is if the matrix is all NaN, // in which case, row=0, col=0 is returned for the location. minmax_coeff_visitor<Derived, is_min, PropagateNumbers, false>; // Propagate NaNs. If the matrix contains NaN, the location of the first NaN // will be returned in row and col. minmax_coeff_visitor<Derived, is_min, NaNPropagation, false>; functor_traits<minmax_coeff_visitor<Derived, is_min, NaNPropagation>>; template <typename Scalar> struct all_visitor { … }; functor_traits<all_visitor<Scalar>>; template <typename Scalar> struct any_visitor { … }; functor_traits<any_visitor<Scalar>>; template <typename Scalar> struct count_visitor { … }; functor_traits<count_visitor<Scalar>>; } // end namespace internal /** \fn DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const * \returns the minimum of all coefficients of *this and puts in *row and *col its location. * * In case \c *this contains NaN, NaNPropagation determines the behavior: * NaNPropagation == PropagateFast : undefined * NaNPropagation == PropagateNaN : result is NaN * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN * \warning the matrix must be not empty, otherwise an assertion is triggered. * * \sa DenseBase::minCoeff(Index*), DenseBase::maxCoeff(Index*,Index*), DenseBase::visit(), DenseBase::minCoeff() */ template <typename Derived> template <int NaNPropagation, typename IndexType> EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const { … } /** \returns the minimum of all coefficients of *this and puts in *index its location. * * In case \c *this contains NaN, NaNPropagation determines the behavior: * NaNPropagation == PropagateFast : undefined * NaNPropagation == PropagateNaN : result is NaN * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN * \warning the matrix must be not empty, otherwise an assertion is triggered. * * \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::visit(), * DenseBase::minCoeff() */ template <typename Derived> template <int NaNPropagation, typename IndexType> EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar DenseBase<Derived>::minCoeff(IndexType* index) const { … } /** \fn DenseBase<Derived>::maxCoeff(IndexType* rowId, IndexType* colId) const * \returns the maximum of all coefficients of *this and puts in *row and *col its location. * * In case \c *this contains NaN, NaNPropagation determines the behavior: * NaNPropagation == PropagateFast : undefined * NaNPropagation == PropagateNaN : result is NaN * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN * \warning the matrix must be not empty, otherwise an assertion is triggered. * * \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visit(), DenseBase::maxCoeff() */ template <typename Derived> template <int NaNPropagation, typename IndexType> EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar DenseBase<Derived>::maxCoeff(IndexType* rowPtr, IndexType* colPtr) const { … } /** \returns the maximum of all coefficients of *this and puts in *index its location. * * In case \c *this contains NaN, NaNPropagation determines the behavior: * NaNPropagation == PropagateFast : undefined * NaNPropagation == PropagateNaN : result is NaN * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN * \warning the matrix must be not empty, otherwise an assertion is triggered. * * \sa DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(), * DenseBase::maxCoeff() */ template <typename Derived> template <int NaNPropagation, typename IndexType> EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar DenseBase<Derived>::maxCoeff(IndexType* index) const { … } /** \returns true if all coefficients are true * * Example: \include MatrixBase_all.cpp * Output: \verbinclude MatrixBase_all.out * * \sa any(), Cwise::operator<() */ template <typename Derived> EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::all() const { … } /** \returns true if at least one coefficient is true * * \sa all() */ template <typename Derived> EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::any() const { … } /** \returns the number of coefficients which evaluate to true * * \sa all(), any() */ template <typename Derived> EIGEN_DEVICE_FUNC Index DenseBase<Derived>::count() const { … } template <typename Derived> EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::hasNaN() const { … } /** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values. * * \sa hasNaN() */ template <typename Derived> EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::allFinite() const { … } } // end namespace Eigen #endif // EIGEN_VISITOR_H