10 #ifndef EIGEN_SELECT_H
11 #define EIGEN_SELECT_H
13 #include "./InternalHeaderCheck.h"
33 template<
typename ConditionMatrixType,
typename ThenMatrixType,
typename ElseMatrixType>
34 struct traits<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
35 : traits<ThenMatrixType>
37 typedef typename traits<ThenMatrixType>::Scalar Scalar;
38 typedef Dense StorageKind;
39 typedef typename traits<ThenMatrixType>::XprKind XprKind;
40 typedef typename ConditionMatrixType::Nested ConditionMatrixNested;
41 typedef typename ThenMatrixType::Nested ThenMatrixNested;
42 typedef typename ElseMatrixType::Nested ElseMatrixNested;
44 RowsAtCompileTime = ConditionMatrixType::RowsAtCompileTime,
45 ColsAtCompileTime = ConditionMatrixType::ColsAtCompileTime,
46 MaxRowsAtCompileTime = ConditionMatrixType::MaxRowsAtCompileTime,
47 MaxColsAtCompileTime = ConditionMatrixType::MaxColsAtCompileTime,
48 Flags = (
unsigned int)ThenMatrixType::Flags & ElseMatrixType::Flags &
RowMajorBit
53 template<
typename ConditionMatrixType,
typename ThenMatrixType,
typename ElseMatrixType>
54 class Select :
public internal::dense_xpr_base< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::type,
55 internal::no_assignment_operator
59 typedef typename internal::dense_xpr_base<Select>::type Base;
60 EIGEN_DENSE_PUBLIC_INTERFACE(
Select)
62 inline EIGEN_DEVICE_FUNC
63 Select(
const ConditionMatrixType& a_conditionMatrix,
64 const ThenMatrixType& a_thenMatrix,
65 const ElseMatrixType& a_elseMatrix)
66 : m_condition(a_conditionMatrix), m_then(a_thenMatrix), m_else(a_elseMatrix)
68 eigen_assert(m_condition.rows() == m_then.rows() && m_condition.rows() == m_else.rows());
69 eigen_assert(m_condition.cols() == m_then.cols() && m_condition.cols() == m_else.cols());
72 inline EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
73 Index rows()
const EIGEN_NOEXCEPT {
return m_condition.rows(); }
74 inline EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
75 Index cols()
const EIGEN_NOEXCEPT {
return m_condition.cols(); }
77 inline EIGEN_DEVICE_FUNC
80 if (m_condition.coeff(i,j))
81 return m_then.coeff(i,j);
83 return m_else.coeff(i,j);
86 inline EIGEN_DEVICE_FUNC
87 const Scalar coeff(
Index i)
const
89 if (m_condition.coeff(i))
90 return m_then.coeff(i);
92 return m_else.coeff(i);
95 inline EIGEN_DEVICE_FUNC
const ConditionMatrixType& conditionMatrix()
const
100 inline EIGEN_DEVICE_FUNC
const ThenMatrixType& thenMatrix()
const
105 inline EIGEN_DEVICE_FUNC
const ElseMatrixType& elseMatrix()
const
111 typename ConditionMatrixType::Nested m_condition;
112 typename ThenMatrixType::Nested m_then;
113 typename ElseMatrixType::Nested m_else;
125 template<
typename Derived>
126 template<
typename ThenDerived,
typename ElseDerived>
139 template<
typename Derived>
140 template<
typename ThenDerived>
143 const typename ThenDerived::Scalar& elseScalar)
const
146 derived(), thenMatrix.
derived(), ThenDerived::Constant(rows(),cols(),elseScalar));
154 template<
typename Derived>
155 template<
typename ElseDerived>
161 derived(), ElseDerived::Constant(rows(),cols(),thenScalar), elseMatrix.
derived());
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:42
const Select< Derived, ThenDerived, ElseDerived > select(const DenseBase< ThenDerived > &thenMatrix, const DenseBase< ElseDerived > &elseMatrix) const
Definition: Select.h:128
Derived & derived()
Definition: EigenBase.h:48
Expression of a coefficient wise version of the C++ ternary operator ?:
Definition: Select.h:56
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59