BooleanRedux.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_ALLANDANY_H
11 #define EIGEN_ALLANDANY_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 template<typename Derived, int UnrollCount>
19 {
20  typedef typename Derived::ExpressionTraits Traits;
21  enum {
22  col = (UnrollCount-1) / Traits::RowsAtCompileTime,
23  row = (UnrollCount-1) % Traits::RowsAtCompileTime
24  };
25 
26  static inline bool run(const Derived &mat)
27  {
28  return all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col);
29  }
30 };
31 
32 template<typename Derived>
33 struct all_unroller<Derived, 0>
34 {
35  static inline bool run(const Derived &/*mat*/) { return true; }
36 };
37 
38 template<typename Derived>
39 struct all_unroller<Derived, Dynamic>
40 {
41  static inline bool run(const Derived &) { return false; }
42 };
43 
44 template<typename Derived, int UnrollCount>
46 {
47  typedef typename Derived::ExpressionTraits Traits;
48  enum {
49  col = (UnrollCount-1) / Traits::RowsAtCompileTime,
50  row = (UnrollCount-1) % Traits::RowsAtCompileTime
51  };
52 
53  static inline bool run(const Derived &mat)
54  {
55  return any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
56  }
57 };
58 
59 template<typename Derived>
60 struct any_unroller<Derived, 0>
61 {
62  static inline bool run(const Derived & /*mat*/) { return false; }
63 };
64 
65 template<typename Derived>
66 struct any_unroller<Derived, Dynamic>
67 {
68  static inline bool run(const Derived &) { return false; }
69 };
70 
71 } // end namespace internal
72 
80 template<typename Derived>
81 inline bool DenseBase<Derived>::all() const
82 {
83  typedef internal::evaluator<Derived> Evaluator;
84  enum {
85  unroll = SizeAtCompileTime != Dynamic
86  && SizeAtCompileTime * (Evaluator::CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
87  };
88  Evaluator evaluator(derived());
89  if(unroll)
91  else
92  {
93  for(Index j = 0; j < cols(); ++j)
94  for(Index i = 0; i < rows(); ++i)
95  if (!evaluator.coeff(i, j)) return false;
96  return true;
97  }
98 }
99 
104 template<typename Derived>
105 inline bool DenseBase<Derived>::any() const
106 {
107  typedef internal::evaluator<Derived> Evaluator;
108  enum {
109  unroll = SizeAtCompileTime != Dynamic
110  && SizeAtCompileTime * (Evaluator::CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
111  };
112  Evaluator evaluator(derived());
113  if(unroll)
115  else
116  {
117  for(Index j = 0; j < cols(); ++j)
118  for(Index i = 0; i < rows(); ++i)
119  if (evaluator.coeff(i, j)) return true;
120  return false;
121  }
122 }
123 
128 template<typename Derived>
130 {
131  return derived().template cast<bool>().template cast<Index>().sum();
132 }
133 
138 template<typename Derived>
139 inline bool DenseBase<Derived>::hasNaN() const
140 {
141 #if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
142  return derived().array().isNaN().any();
143 #else
144  return !((derived().array()==derived().array()).all());
145 #endif
146 }
147 
152 template<typename Derived>
153 inline bool DenseBase<Derived>::allFinite() const
154 {
155 #if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
156  return derived().array().isFinite().all();
157 #else
158  return !((derived()-derived()).hasNaN());
159 #endif
160 }
161 
162 } // end namespace Eigen
163 
164 #endif // EIGEN_ALLANDANY_H
static bool run(const Derived &mat)
Definition: BooleanRedux.h:26
EIGEN_DEVICE_FUNC bool any() const
Definition: BooleanRedux.h:105
bool allFinite() const
Definition: BooleanRedux.h:153
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
EIGEN_DEVICE_FUNC bool all() const
Definition: BooleanRedux.h:81
bool hasNaN() const
Definition: BooleanRedux.h:139
static bool run(const Derived &)
Definition: BooleanRedux.h:62
Derived::ExpressionTraits Traits
Definition: BooleanRedux.h:47
EIGEN_DEVICE_FUNC Index count() const
Definition: BooleanRedux.h:129
const int Dynamic
Definition: Constants.h:21
static bool run(const Derived &mat)
Definition: BooleanRedux.h:53
static bool run(const Derived &)
Definition: BooleanRedux.h:35
std::ptrdiff_t j
Derived::ExpressionTraits Traits
Definition: BooleanRedux.h:20
#define EIGEN_UNROLLING_LIMIT
Definition: Settings.h:24


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:43