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  enum {
21  col = (UnrollCount-1) / Derived::RowsAtCompileTime,
22  row = (UnrollCount-1) % Derived::RowsAtCompileTime
23  };
24 
25  static inline bool run(const Derived &mat)
26  {
27  return all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col);
28  }
29 };
30 
31 template<typename Derived>
32 struct all_unroller<Derived, 1>
33 {
34  static inline bool run(const Derived &mat) { return mat.coeff(0, 0); }
35 };
36 
37 template<typename Derived>
38 struct all_unroller<Derived, Dynamic>
39 {
40  static inline bool run(const Derived &) { return false; }
41 };
42 
43 template<typename Derived, int UnrollCount>
45 {
46  enum {
47  col = (UnrollCount-1) / Derived::RowsAtCompileTime,
48  row = (UnrollCount-1) % Derived::RowsAtCompileTime
49  };
50 
51  static inline bool run(const Derived &mat)
52  {
53  return any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
54  }
55 };
56 
57 template<typename Derived>
58 struct any_unroller<Derived, 1>
59 {
60  static inline bool run(const Derived &mat) { return mat.coeff(0, 0); }
61 };
62 
63 template<typename Derived>
64 struct any_unroller<Derived, Dynamic>
65 {
66  static inline bool run(const Derived &) { return false; }
67 };
68 
69 } // end namespace internal
70 
78 template<typename Derived>
79 inline bool DenseBase<Derived>::all() const
80 {
81  enum {
82  unroll = SizeAtCompileTime != Dynamic
83  && CoeffReadCost != Dynamic
85  && SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
86  };
87  if(unroll)
89  else
90  {
91  for(Index j = 0; j < cols(); ++j)
92  for(Index i = 0; i < rows(); ++i)
93  if (!coeff(i, j)) return false;
94  return true;
95  }
96 }
97 
102 template<typename Derived>
103 inline bool DenseBase<Derived>::any() const
104 {
105  enum {
106  unroll = SizeAtCompileTime != Dynamic
107  && CoeffReadCost != Dynamic
109  && SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
110  };
111  if(unroll)
113  else
114  {
115  for(Index j = 0; j < cols(); ++j)
116  for(Index i = 0; i < rows(); ++i)
117  if (coeff(i, j)) return true;
118  return false;
119  }
120 }
121 
126 template<typename Derived>
128 {
129  return derived().template cast<bool>().template cast<Index>().sum();
130 }
131 
136 template<typename Derived>
137 inline bool DenseBase<Derived>::hasNaN() const
138 {
139  return !((derived().array()==derived().array()).all());
140 }
141 
146 template<typename Derived>
147 inline bool DenseBase<Derived>::allFinite() const
148 {
149  return !((derived()-derived()).hasNaN());
150 }
151 
152 } // end namespace Eigen
153 
154 #endif // EIGEN_ALLANDANY_H
static bool run(const Derived &mat)
Definition: BooleanRedux.h:25
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:61
bool allFinite() const
Definition: BooleanRedux.h:147
Definition: LDLT.h:16
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
static bool run(const Derived &mat)
Definition: BooleanRedux.h:34
static bool run(const Derived &mat)
Definition: BooleanRedux.h:60
bool hasNaN() const
Definition: BooleanRedux.h:137
Index count() const
Definition: BooleanRedux.h:127
bool all(void) const
Definition: BooleanRedux.h:79
const int Dynamic
Definition: Constants.h:21
static bool run(const Derived &mat)
Definition: BooleanRedux.h:51
#define EIGEN_UNROLLING_LIMIT
Definition: Settings.h:24
bool any(void) const
Definition: BooleanRedux.h:103


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:46