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 & HereditaryBits,
47  CoeffReadCost = traits<typename remove_all<ConditionMatrixNested>::type>::CoeffReadCost
48  + EIGEN_SIZE_MAX(traits<typename remove_all<ThenMatrixNested>::type>::CoeffReadCost,
49  traits<typename remove_all<ElseMatrixNested>::type>::CoeffReadCost)
50  };
51 };
52 }
53 
54 template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
56  public internal::dense_xpr_base< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::type
57 {
58  public:
59 
62 
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)
67  {
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());
70  }
71 
72  Index rows() const { return m_condition.rows(); }
73  Index cols() const { return m_condition.cols(); }
74 
75  const Scalar coeff(Index i, Index j) const
76  {
77  if (m_condition.coeff(i,j))
78  return m_then.coeff(i,j);
79  else
80  return m_else.coeff(i,j);
81  }
82 
83  const Scalar coeff(Index i) const
84  {
85  if (m_condition.coeff(i))
86  return m_then.coeff(i);
87  else
88  return m_else.coeff(i);
89  }
90 
91  const ConditionMatrixType& conditionMatrix() const
92  {
93  return m_condition;
94  }
95 
96  const ThenMatrixType& thenMatrix() const
97  {
98  return m_then;
99  }
100 
101  const ElseMatrixType& elseMatrix() const
102  {
103  return m_else;
104  }
105 
106  protected:
107  typename ConditionMatrixType::Nested m_condition;
108  typename ThenMatrixType::Nested m_then;
109  typename ElseMatrixType::Nested m_else;
110 };
111 
112 
121 template<typename Derived>
122 template<typename ThenDerived,typename ElseDerived>
125  const DenseBase<ElseDerived>& elseMatrix) const
126 {
127  return Select<Derived,ThenDerived,ElseDerived>(derived(), thenMatrix.derived(), elseMatrix.derived());
128 }
129 
135 template<typename Derived>
136 template<typename ThenDerived>
139  const typename ThenDerived::Scalar& elseScalar) const
140 {
142  derived(), thenMatrix.derived(), ThenDerived::Constant(rows(),cols(),elseScalar));
143 }
144 
150 template<typename Derived>
151 template<typename ElseDerived>
153 DenseBase<Derived>::select(const typename ElseDerived::Scalar& thenScalar,
154  const DenseBase<ElseDerived>& elseMatrix) const
155 {
157  derived(), ElseDerived::Constant(rows(),cols(),thenScalar), elseMatrix.derived());
158 }
159 
160 } // end namespace Eigen
161 
162 #endif // EIGEN_SELECT_H
const Scalar coeff(Index i) const
Definition: Select.h:83
Index rows() const
Definition: Select.h:72
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
ElseMatrixType::Nested m_else
Definition: Select.h:109
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
const ConditionMatrixType & conditionMatrix() const
Definition: Select.h:91
internal::dense_xpr_base< Select >::type Base
Definition: Select.h:60
const ThenMatrixType & thenMatrix() const
Definition: Select.h:96
Index cols() const
Definition: Select.h:73
const unsigned int HereditaryBits
const ElseMatrixType & elseMatrix() const
Definition: Select.h:101
const Select< Derived, ThenDerived, ElseDerived > select(const DenseBase< ThenDerived > &thenMatrix, const DenseBase< ElseDerived > &elseMatrix) const
Definition: Select.h:124
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
#define EIGEN_SIZE_MAX(a, b)
const Scalar coeff(Index i, Index j) const
Definition: Select.h:75
ThenMatrixType::Nested m_then
Definition: Select.h:108
ConditionMatrixType::Nested m_condition
Definition: Select.h:107
#define eigen_assert(x)
Expression of a coefficient wise version of the C++ ternary operator ?:
Definition: Select.h:55


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:04