2008-05-31 18:11:48 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-05-31 18:11:48 +00:00
|
|
|
//
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2008-05-31 18:11:48 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// 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/.
|
2008-05-31 18:11:48 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_ALLANDANY_H
|
|
|
|
|
#define EIGEN_ALLANDANY_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
|
|
|
|
|
2008-05-31 18:11:48 +00:00
|
|
|
template<typename Derived, int UnrollCount>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct all_unroller
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2014-02-18 14:26:25 +01:00
|
|
|
typedef typename Derived::ExpressionTraits Traits;
|
|
|
|
|
enum {
|
|
|
|
|
col = (UnrollCount-1) / Traits::RowsAtCompileTime,
|
|
|
|
|
row = (UnrollCount-1) % Traits::RowsAtCompileTime
|
|
|
|
|
};
|
2008-05-31 18:11:48 +00:00
|
|
|
|
2012-01-31 12:58:52 +01:00
|
|
|
static inline bool run(const Derived &mat)
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
return all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col);
|
2008-05-31 18:11:48 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename Derived>
|
2013-11-13 16:47:02 +01:00
|
|
|
struct all_unroller<Derived, 0>
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2013-11-13 16:47:02 +01:00
|
|
|
static inline bool run(const Derived &/*mat*/) { return true; }
|
2008-05-31 18:11:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct all_unroller<Derived, Dynamic>
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2012-01-31 12:58:52 +01:00
|
|
|
static inline bool run(const Derived &) { return false; }
|
2008-05-31 18:11:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename Derived, int UnrollCount>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct any_unroller
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2014-02-18 14:26:25 +01:00
|
|
|
typedef typename Derived::ExpressionTraits Traits;
|
|
|
|
|
enum {
|
|
|
|
|
col = (UnrollCount-1) / Traits::RowsAtCompileTime,
|
|
|
|
|
row = (UnrollCount-1) % Traits::RowsAtCompileTime
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-31 12:58:52 +01:00
|
|
|
static inline bool run(const Derived &mat)
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
return any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
|
2008-05-31 18:11:48 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename Derived>
|
2013-11-13 16:47:02 +01:00
|
|
|
struct any_unroller<Derived, 0>
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2013-11-13 16:47:02 +01:00
|
|
|
static inline bool run(const Derived & /*mat*/) { return false; }
|
2008-05-31 18:11:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename Derived>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct any_unroller<Derived, Dynamic>
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2012-01-31 12:58:52 +01:00
|
|
|
static inline bool run(const Derived &) { return false; }
|
2008-05-31 18:11:48 +00:00
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
} // end namespace internal
|
|
|
|
|
|
2010-06-19 23:00:22 +02:00
|
|
|
/** \returns true if all coefficients are true
|
2008-07-22 10:54:42 +00:00
|
|
|
*
|
|
|
|
|
* Example: \include MatrixBase_all.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_all.out
|
|
|
|
|
*
|
2009-12-04 23:17:14 +01:00
|
|
|
* \sa any(), Cwise::operator<()
|
2008-05-31 18:11:48 +00:00
|
|
|
*/
|
|
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline bool DenseBase<Derived>::all() const
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2015-09-02 21:38:40 +02:00
|
|
|
typedef internal::evaluator<Derived> Evaluator;
|
2010-06-17 17:25:18 +02:00
|
|
|
enum {
|
|
|
|
|
unroll = SizeAtCompileTime != Dynamic
|
2014-03-10 23:24:40 +01:00
|
|
|
&& SizeAtCompileTime * (Evaluator::CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
|
2010-06-17 17:25:18 +02:00
|
|
|
};
|
2014-02-18 14:26:25 +01:00
|
|
|
Evaluator evaluator(derived());
|
|
|
|
|
if(unroll)
|
|
|
|
|
return internal::all_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(evaluator);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(Index j = 0; j < cols(); ++j)
|
|
|
|
|
for(Index i = 0; i < rows(); ++i)
|
|
|
|
|
if (!evaluator.coeff(i, j)) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-05-31 18:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-19 23:00:22 +02:00
|
|
|
/** \returns true if at least one coefficient is true
|
2008-05-31 18:11:48 +00:00
|
|
|
*
|
2009-12-04 23:17:14 +01:00
|
|
|
* \sa all()
|
2008-05-31 18:11:48 +00:00
|
|
|
*/
|
|
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline bool DenseBase<Derived>::any() const
|
2008-05-31 18:11:48 +00:00
|
|
|
{
|
2015-09-02 21:38:40 +02:00
|
|
|
typedef internal::evaluator<Derived> Evaluator;
|
2010-06-17 17:25:18 +02:00
|
|
|
enum {
|
|
|
|
|
unroll = SizeAtCompileTime != Dynamic
|
2014-03-10 23:24:40 +01:00
|
|
|
&& SizeAtCompileTime * (Evaluator::CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
|
2010-06-17 17:25:18 +02:00
|
|
|
};
|
2014-02-18 14:26:25 +01:00
|
|
|
Evaluator evaluator(derived());
|
|
|
|
|
if(unroll)
|
|
|
|
|
return internal::any_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(evaluator);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(Index j = 0; j < cols(); ++j)
|
|
|
|
|
for(Index i = 0; i < rows(); ++i)
|
|
|
|
|
if (evaluator.coeff(i, j)) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-05-31 18:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-19 23:00:22 +02:00
|
|
|
/** \returns the number of coefficients which evaluate to true
|
2009-01-20 16:37:52 +00:00
|
|
|
*
|
2009-12-04 23:17:14 +01:00
|
|
|
* \sa all(), any()
|
2009-01-20 16:37:52 +00:00
|
|
|
*/
|
|
|
|
|
template<typename Derived>
|
2015-02-13 18:57:41 +01:00
|
|
|
inline Eigen::Index DenseBase<Derived>::count() const
|
2009-01-20 16:37:52 +00:00
|
|
|
{
|
2010-05-30 16:00:58 -04:00
|
|
|
return derived().template cast<bool>().template cast<Index>().sum();
|
2009-01-20 16:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-16 15:10:40 +02:00
|
|
|
/** \returns true is \c *this contains at least one Not A Number (NaN).
|
|
|
|
|
*
|
2013-07-18 11:27:04 +02:00
|
|
|
* \sa allFinite()
|
2013-04-16 15:10:40 +02:00
|
|
|
*/
|
|
|
|
|
template<typename Derived>
|
|
|
|
|
inline bool DenseBase<Derived>::hasNaN() const
|
|
|
|
|
{
|
2015-10-27 15:39:50 +01:00
|
|
|
#if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
|
|
|
|
|
return derived().array().isNaN().any();
|
|
|
|
|
#else
|
2013-04-16 15:10:40 +02:00
|
|
|
return !((derived().array()==derived().array()).all());
|
2015-10-27 15:39:50 +01:00
|
|
|
#endif
|
2013-04-16 15:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values.
|
|
|
|
|
*
|
|
|
|
|
* \sa hasNaN()
|
|
|
|
|
*/
|
|
|
|
|
template<typename Derived>
|
2013-07-18 11:27:04 +02:00
|
|
|
inline bool DenseBase<Derived>::allFinite() const
|
2013-04-16 15:10:40 +02:00
|
|
|
{
|
2015-10-27 15:39:50 +01:00
|
|
|
#if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
|
|
|
|
|
return derived().array().isFinite().all();
|
|
|
|
|
#else
|
2013-04-16 15:10:40 +02:00
|
|
|
return !((derived()-derived()).hasNaN());
|
2015-10-27 15:39:50 +01:00
|
|
|
#endif
|
2013-04-16 15:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2008-05-31 18:11:48 +00:00
|
|
|
#endif // EIGEN_ALLANDANY_H
|