aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core
diff options
context:
space:
mode:
authorGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2011-04-12 22:34:16 +0100
committerGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2011-04-12 22:34:16 +0100
commit12a30a982feab745d36d647ab88dfb0a51da2213 (patch)
tree5042422112605946ecd39dfbb0b5453f70d8a97d /Eigen/src/Core
parent88b3116b9932ac8fecb5f72bf590e2b44fc9d0ff (diff)
Implement evaluator for Select.
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r--Eigen/src/Core/CoreEvaluators.h39
-rw-r--r--Eigen/src/Core/Select.h15
2 files changed, 54 insertions, 0 deletions
diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h
index bd41bf405..756ebde1e 100644
--- a/Eigen/src/Core/CoreEvaluators.h
+++ b/Eigen/src/Core/CoreEvaluators.h
@@ -576,6 +576,45 @@ struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDir
};
+// -------------------- Select --------------------
+
+template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
+struct evaluator_impl<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
+{
+ typedef Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> SelectType;
+
+ evaluator_impl(const SelectType& select)
+ : m_conditionImpl(select.conditionMatrix()),
+ m_thenImpl(select.thenMatrix()),
+ m_elseImpl(select.elseMatrix())
+ { }
+
+ typedef typename SelectType::Index Index;
+ typedef typename SelectType::CoeffReturnType CoeffReturnType;
+
+ CoeffReturnType coeff(Index row, Index col) const
+ {
+ if (m_conditionImpl.coeff(row, col))
+ return m_thenImpl.coeff(row, col);
+ else
+ return m_elseImpl.coeff(row, col);
+ }
+
+ CoeffReturnType coeff(Index index) const
+ {
+ if (m_conditionImpl.coeff(index))
+ return m_thenImpl.coeff(index);
+ else
+ return m_elseImpl.coeff(index);
+ }
+
+protected:
+ typename evaluator<ConditionMatrixType>::type m_conditionImpl;
+ typename evaluator<ThenMatrixType>::type m_thenImpl;
+ typename evaluator<ElseMatrixType>::type m_elseImpl;
+};
+
+
} // namespace internal
#endif // EIGEN_COREEVALUATORS_H
diff --git a/Eigen/src/Core/Select.h b/Eigen/src/Core/Select.h
index d0cd66a26..87a071fc7 100644
--- a/Eigen/src/Core/Select.h
+++ b/Eigen/src/Core/Select.h
@@ -101,6 +101,21 @@ class Select : internal::no_assignment_operator,
return m_else.coeff(i);
}
+ const ConditionMatrixType& conditionMatrix() const
+ {
+ return m_condition;
+ }
+
+ const ThenMatrixType& thenMatrix() const
+ {
+ return m_then;
+ }
+
+ const ElseMatrixType& elseMatrix() const
+ {
+ return m_else;
+ }
+
protected:
const typename ConditionMatrixType::Nested m_condition;
const typename ThenMatrixType::Nested m_then;