Select.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-2010 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_SELECT_H
11 #define EIGEN_SELECT_H
12 
13 namespace Eigen {
14 
30 namespace internal {
31 template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
32 struct traits<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
33  : traits<ThenMatrixType>
34 {
36  typedef Dense StorageKind;
38  typedef typename ConditionMatrixType::Nested ConditionMatrixNested;
39  typedef typename ThenMatrixType::Nested ThenMatrixNested;
40  typedef typename ElseMatrixType::Nested ElseMatrixNested;
41  enum {
42  RowsAtCompileTime = ConditionMatrixType::RowsAtCompileTime,
43  ColsAtCompileTime = ConditionMatrixType::ColsAtCompileTime,
44  MaxRowsAtCompileTime = ConditionMatrixType::MaxRowsAtCompileTime,
45  MaxColsAtCompileTime = ConditionMatrixType::MaxColsAtCompileTime,
46  Flags = (unsigned int)ThenMatrixType::Flags & ElseMatrixType::Flags & RowMajorBit
47  };
48 };
49 }
50 
51 template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
52 class Select : public internal::dense_xpr_base< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::type,
54 {
55  public:
56 
59 
60  inline EIGEN_DEVICE_FUNC
61  Select(const ConditionMatrixType& a_conditionMatrix,
62  const ThenMatrixType& a_thenMatrix,
63  const ElseMatrixType& a_elseMatrix)
64  : m_condition(a_conditionMatrix), m_then(a_thenMatrix), m_else(a_elseMatrix)
65  {
66  eigen_assert(m_condition.rows() == m_then.rows() && m_condition.rows() == m_else.rows());
67  eigen_assert(m_condition.cols() == m_then.cols() && m_condition.cols() == m_else.cols());
68  }
69 
71  Index rows() const EIGEN_NOEXCEPT { return m_condition.rows(); }
73  Index cols() const EIGEN_NOEXCEPT { return m_condition.cols(); }
74 
75  inline EIGEN_DEVICE_FUNC
76  const Scalar coeff(Index i, Index j) const
77  {
78  if (m_condition.coeff(i,j))
79  return m_then.coeff(i,j);
80  else
81  return m_else.coeff(i,j);
82  }
83 
84  inline EIGEN_DEVICE_FUNC
85  const Scalar coeff(Index i) const
86  {
87  if (m_condition.coeff(i))
88  return m_then.coeff(i);
89  else
90  return m_else.coeff(i);
91  }
92 
93  inline EIGEN_DEVICE_FUNC const ConditionMatrixType& conditionMatrix() const
94  {
95  return m_condition;
96  }
97 
98  inline EIGEN_DEVICE_FUNC const ThenMatrixType& thenMatrix() const
99  {
100  return m_then;
101  }
102 
103  inline EIGEN_DEVICE_FUNC const ElseMatrixType& elseMatrix() const
104  {
105  return m_else;
106  }
107 
108  protected:
109  typename ConditionMatrixType::Nested m_condition;
110  typename ThenMatrixType::Nested m_then;
111  typename ElseMatrixType::Nested m_else;
112 };
113 
114 
123 template<typename Derived>
124 template<typename ThenDerived,typename ElseDerived>
127  const DenseBase<ElseDerived>& elseMatrix) const
128 {
129  return Select<Derived,ThenDerived,ElseDerived>(derived(), thenMatrix.derived(), elseMatrix.derived());
130 }
131 
137 template<typename Derived>
138 template<typename ThenDerived>
141  const typename ThenDerived::Scalar& elseScalar) const
142 {
144  derived(), thenMatrix.derived(), ThenDerived::Constant(rows(),cols(),elseScalar));
145 }
146 
152 template<typename Derived>
153 template<typename ElseDerived>
156  const DenseBase<ElseDerived>& elseMatrix) const
157 {
159  derived(), ElseDerived::Constant(rows(),cols(),thenScalar), elseMatrix.derived());
160 }
161 
162 } // end namespace Eigen
163 
164 #endif // EIGEN_SELECT_H
Eigen::DenseBase::select
const EIGEN_DEVICE_FUNC Select< Derived, ThenDerived, ElseDerived > select(const DenseBase< ThenDerived > &thenMatrix, const DenseBase< ElseDerived > &elseMatrix) const
Definition: Select.h:126
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
Eigen::internal::traits< Select< ConditionMatrixType, ThenMatrixType, ElseMatrixType > >::Scalar
traits< ThenMatrixType >::Scalar Scalar
Definition: Select.h:35
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::traits< Select< ConditionMatrixType, ThenMatrixType, ElseMatrixType > >::ThenMatrixNested
ThenMatrixType::Nested ThenMatrixNested
Definition: Select.h:39
Eigen::internal::dense_xpr_base
Definition: XprHelper.h:483
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::Select::coeff
const EIGEN_DEVICE_FUNC Scalar coeff(Index i) const
Definition: Select.h:85
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
type
Definition: pytypes.h:1491
EIGEN_DENSE_PUBLIC_INTERFACE
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1283
Eigen::internal::traits< Select< ConditionMatrixType, ThenMatrixType, ElseMatrixType > >::ConditionMatrixNested
ConditionMatrixType::Nested ConditionMatrixNested
Definition: Select.h:38
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::Select::thenMatrix
const EIGEN_DEVICE_FUNC ThenMatrixType & thenMatrix() const
Definition: Select.h:98
Eigen::Select::cols
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Select.h:73
Eigen::Select::conditionMatrix
const EIGEN_DEVICE_FUNC ConditionMatrixType & conditionMatrix() const
Definition: Select.h:93
Eigen::Select::m_else
ElseMatrixType::Nested m_else
Definition: Select.h:111
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
Eigen::Select::Select
EIGEN_DEVICE_FUNC Select(const ConditionMatrixType &a_conditionMatrix, const ThenMatrixType &a_thenMatrix, const ElseMatrixType &a_elseMatrix)
Definition: Select.h:61
Eigen::Select::Base
internal::dense_xpr_base< Select >::type Base
Definition: Select.h:57
Eigen::internal::traits< Select< ConditionMatrixType, ThenMatrixType, ElseMatrixType > >::StorageKind
Dense StorageKind
Definition: Select.h:36
Eigen::Select::m_then
ThenMatrixType::Nested m_then
Definition: Select.h:110
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::DenseBase
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
Eigen::internal::no_assignment_operator
Definition: XprHelper.h:109
Eigen::internal::traits< Select< ConditionMatrixType, ThenMatrixType, ElseMatrixType > >::XprKind
traits< ThenMatrixType >::XprKind XprKind
Definition: Select.h:37
EIGEN_NOEXCEPT
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::traits< Select< ConditionMatrixType, ThenMatrixType, ElseMatrixType > >::ElseMatrixNested
ElseMatrixType::Nested ElseMatrixNested
Definition: Select.h:40
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Eigen::Select::elseMatrix
const EIGEN_DEVICE_FUNC ElseMatrixType & elseMatrix() const
Definition: Select.h:103
Eigen::Select
Expression of a coefficient wise version of the C++ ternary operator ?:
Definition: Select.h:52
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::Select::m_condition
ConditionMatrixType::Nested m_condition
Definition: Select.h:109
Eigen::Select::coeff
const EIGEN_DEVICE_FUNC Scalar coeff(Index i, Index j) const
Definition: Select.h:76
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Select::rows
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Select.h:71
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Dense
Definition: Constants.h:507


gtsam
Author(s):
autogenerated on Wed May 15 2024 15:21:34