1c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#include <Eigen/Core>
2c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#include <iostream>
3c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathusing namespace Eigen;
4c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathusing namespace std;
5c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
6c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// define function to be applied coefficient-wise
7c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathdouble ramp(double x)
8c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
9c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  if (x > 0)
10c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    return x;
11c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  else
12c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    return 0;
13c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
14c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
15c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathint main(int, char**)
16c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
17c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  Matrix4d m1 = Matrix4d::Random();
18c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(ptr_fun(ramp)) << endl;
19c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  return 0;
20c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
21