Registered Member
|
I have implemented an algorithm using Eigen, and after a few thousand iterations, NaN's start to show up. Two part question:
- In the next version, can you add the predicates hasNaN() and hasInf() that test for the presence of an element with either condition? - In the meantime, what is the best way to iterate across all of the elements of an Eigen matrix - just build my own nested loop over the row and column indexes? Is there a pre-formed iterator, or some other means of accessing all of the storage as a linear array? Ideally, this method would be efficient for both sparse and dense matrices and vectors. Thanks, -Jonathan |
Moderator
|
why not.
The are at least 3 possibilities: 1 - you can use two basic nested loops: (only for dense matrix)
2 - you can use an "outer" loop + an iterator: (for dense and sparse)
3 - you can write/build a functor to apply it: - to generate a matrix (see MatrixBase::nullOp()) - coeff wise (see MatrixBase::unaryOp()) - coeff wise between two matrices - to perform a reduction - and we also have visitors Our functor mechanism is compatible with the STL, so you can build them using std::bind, etc.. So basically, for your hasNan() predicate, you can simply write a trivial functor testing for a single scalar, and then do:
You can even extend MatrixBase to implement a m.hasNan() shorcut yourself without having to modify any Eigen's file. See http://eigen.tuxfamily.org/api/CustomizingEigen.html. |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]