class_CwiseUnaryOp.cpp
Go to the documentation of this file.
1 #include <Eigen/Core>
2 #include <iostream>
3 using namespace Eigen;
4 using namespace std;
5 
6 // define a custom template unary functor
7 template<typename Scalar>
8 struct CwiseClampOp {
9  CwiseClampOp(const Scalar& inf, const Scalar& sup) : m_inf(inf), m_sup(sup) {}
10  const Scalar operator()(const Scalar& x) const { return x<m_inf ? m_inf : (x>m_sup ? m_sup : x); }
11  Scalar m_inf, m_sup;
12 };
13 
14 int main(int, char**)
15 {
16  Matrix4d m1 = Matrix4d::Random();
17  cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(CwiseClampOp<double>(-0.5,0.5)) << endl;
18  return 0;
19 }
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
CwiseClampOp::CwiseClampOp
CwiseClampOp(const Scalar &inf, const Scalar &sup)
Definition: class_CwiseUnaryOp.cpp:9
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
m1
Matrix3d m1
Definition: IOFormat.cpp:2
CwiseClampOp::m_sup
Scalar m_sup
Definition: class_CwiseUnaryOp.cpp:11
CwiseClampOp::operator()
const Scalar operator()(const Scalar &x) const
Definition: class_CwiseUnaryOp.cpp:10
std
Definition: BFloat16.h:88
inf
static double inf
Definition: testMatrix.cpp:31
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
CwiseClampOp
Definition: class_CwiseUnaryOp.cpp:8
main
int main(int, char **)
Definition: class_CwiseUnaryOp.cpp:14


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:06