Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
Eigen  3.4.0
 
Loading...
Searching...
No Matches
BooleanRedux.h
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
13namespace Eigen {
14
15namespace internal {
16
17template<typename Derived, int UnrollCount, int Rows>
18struct all_unroller
19{
20 enum {
21 col = (UnrollCount-1) / Rows,
22 row = (UnrollCount-1) % Rows
23 };
24
25 EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat)
26 {
27 return all_unroller<Derived, UnrollCount-1, Rows>::run(mat) && mat.coeff(row, col);
28 }
29};
30
31template<typename Derived, int Rows>
32struct all_unroller<Derived, 0, Rows>
33{
34 EIGEN_DEVICE_FUNC static inline bool run(const Derived &/*mat*/) { return true; }
35};
36
37template<typename Derived, int Rows>
38struct all_unroller<Derived, Dynamic, Rows>
39{
40 EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; }
41};
42
43template<typename Derived, int UnrollCount, int Rows>
44struct any_unroller
45{
46 enum {
47 col = (UnrollCount-1) / Rows,
48 row = (UnrollCount-1) % Rows
49 };
50
51 EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat)
52 {
53 return any_unroller<Derived, UnrollCount-1, Rows>::run(mat) || mat.coeff(row, col);
54 }
55};
56
57template<typename Derived, int Rows>
58struct any_unroller<Derived, 0, Rows>
59{
60 EIGEN_DEVICE_FUNC static inline bool run(const Derived & /*mat*/) { return false; }
61};
62
63template<typename Derived, int Rows>
64struct any_unroller<Derived, Dynamic, Rows>
65{
66 EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; }
67};
68
69} // end namespace internal
70
78template<typename Derived>
79EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::all() const
80{
81 typedef internal::evaluator<Derived> Evaluator;
82 enum {
83 unroll = SizeAtCompileTime != Dynamic
84 && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits<Scalar>::AddCost)) <= EIGEN_UNROLLING_LIMIT
85 };
86 Evaluator evaluator(derived());
87 if(unroll)
88 return internal::all_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, internal::traits<Derived>::RowsAtCompileTime>::run(evaluator);
89 else
90 {
91 for(Index j = 0; j < cols(); ++j)
92 for(Index i = 0; i < rows(); ++i)
93 if (!evaluator.coeff(i, j)) return false;
94 return true;
95 }
96}
97
102template<typename Derived>
103EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::any() const
104{
105 typedef internal::evaluator<Derived> Evaluator;
106 enum {
107 unroll = SizeAtCompileTime != Dynamic
108 && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits<Scalar>::AddCost)) <= EIGEN_UNROLLING_LIMIT
109 };
110 Evaluator evaluator(derived());
111 if(unroll)
112 return internal::any_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, internal::traits<Derived>::RowsAtCompileTime>::run(evaluator);
113 else
114 {
115 for(Index j = 0; j < cols(); ++j)
116 for(Index i = 0; i < rows(); ++i)
117 if (evaluator.coeff(i, j)) return true;
118 return false;
119 }
120}
121
126template<typename Derived>
127EIGEN_DEVICE_FUNC inline Eigen::Index DenseBase<Derived>::count() const
128{
129 return derived().template cast<bool>().template cast<Index>().sum();
130}
131
136template<typename Derived>
137inline bool DenseBase<Derived>::hasNaN() const
138{
139#if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
140 return derived().array().isNaN().any();
141#else
142 return !((derived().array()==derived().array()).all());
143#endif
144}
145
150template<typename Derived>
152{
153#if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
154 return derived().array().isFinite().all();
155#else
156 return !((derived()-derived()).hasNaN());
157#endif
158}
159
160} // end namespace Eigen
161
162#endif // EIGEN_ALLANDANY_H
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:47
bool any() const
Definition: BooleanRedux.h:103
Scalar sum() const
Definition: Redux.h:459
bool all() const
Definition: BooleanRedux.h:79
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
const int Dynamic
Definition: Constants.h:22
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:233