As an example, suppose I want to write a function that checks to see if each floating-point number in a dense native object is normal and returns 1.0 for the corresponding position if it is normal, or 0.0 if it is not. The conclusion should not be evaluated immediately and should preferably be in the form of an expression.
I read the documentation about passing my own objects as parameters , which led me to the following:
#include <functional> #include <Eigen/Dense> template <typename Derived> auto Fun(const Eigen::DenseBase<Derived>& matrix) -> decltype(matrix.unaryExpr(std::ptr_fun<typename Derived::Scalar, bool>(std::isnormal)).template cast<typename Derived::Scalar>()) { return matrix.unaryExpr(std::ptr_fun<typename Derived::Scalar, bool>(std::isnormal)).template cast<typename Derived::Scalar>(); } int main() { Eigen::Matrix<double, -1, -1> mat; mat.resize(100,100); mat.fill(100); auto mat2 = Fun(mat); return 0; }
This fails with the error that unaryExpr not defined for an object of type Eigen::DenseBase<Derived> , and, of course, if I look at the documentation for DenseBase I see that there is no such function.
So, if you don't evaluate every time I want to call this function, and listing my own object is evaluated by Matrix , how can I do this?
arman source share