class_CwiseUnaryOp.cpp
Go to the documentation of this file.
1 #include <Eigen/Core>
2 #include <iostream>
3 
4 // define a custom template unary functor
5 template<typename Scalar>
6 struct CwiseClampOp {
7  CwiseClampOp(const Scalar& inf, const Scalar& sup) : m_inf(inf), m_sup(sup) {}
8  const Scalar operator()(const Scalar& x) const { return x<m_inf ? m_inf : (x>m_sup ? m_sup : x); }
9  Scalar m_inf, m_sup;
10 };
11 
12 int main(int, char**)
13 {
15  std::cout << m1 << std::endl << "becomes: " << std::endl << m1.unaryExpr(CwiseClampOp<double>(-0.5,0.5)) << std::endl;
16  return 0;
17 }
Matrix3d m1
Definition: IOFormat.cpp:2
IndexedView_or_Block operator()(const RowIndices &rowIndices, const ColIndices &colIndices)
static const RandomReturnType Random()
Definition: Random.h:114
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
int main(int, char **)