print Eigen matrix of type T in operator()

437 views
Skip to first unread message

phreak...@gmail.com

unread,
Nov 20, 2017, 6:37:43 AM11/20/17
to Ceres Solver
Hi, I'm trying to debug my cost function and would like to print intermediate values to console. I'm using Eigen to wrap the pointer-to-T arrays as Eigen matrices of type T, thus I'm doing:

std::cout << residual << std::endl;

where residual is of type Eigen::Matrix<T,3,1>. However, I'm getting: 

/usr/include/eigen3/Eigen/src/Core/MathFunctions.h:365:34: error: invalid static_cast from type ‘const ceres::Jet<double, 13>’ to type ‘int’
     return static_cast<NewType>(x);

It would seem that Eigen is trying to cast the elements to numbers for display and thus it does not call the stream operator directly on its elements (which I assume is implemented on ceres side). How could I print my residual in this case?

Best,
Matias

Alex Stewart

unread,
Nov 20, 2017, 7:14:50 AM11/20/17
to ceres-...@googlegroups.com
There should be no issues streaming matrices of Jets - updating the example helloworld.cc for example to:

struct CostFunctor {
  template <typename T> bool operator()(const T* const x, T* residual) const {
    residual[0] = 10.0 - x[0];
    std::cerr << "Residual: " << Eigen::Map<Eigen::Matrix<T, 1, 1> >(residual) << std::endl;
    return true;
  }
};

produces the expected output of the form:

Residual:          [9.5 ; -1]

when T is a Jet.  What is the callstack for this error?  And what version of Ceres & Eigen are you using?

-Alex

--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/4fb7ab36-aa02-4464-893b-c65f359e27d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

phreak...@gmail.com

unread,
Nov 21, 2017, 4:35:05 AM11/21/17
to Ceres Solver
Hi,
I think the problem was that I had a Ref to a Matrix, not a Matrix itself. 
Reply all
Reply to author
Forward
0 new messages