Registered Member
|
Dear Eigen experts,
to apply a matrix-free version of a Krylov solver (e.g. CG), I would like to write a replacement for the matrix. Is there already an example available online? For example a base class that one can use to derive a wrapper class from would be very helpful. Thanks in advance! kbr |
Moderator
|
I remember this as already been discussed there, a search should lead you to some examples. Basically you need a class that export the Scalar type, and that implements rows(), cols(), and operator*(const MatrixBase<Derived>& rhs). The later is the most tricky one: to avoid temporaries it is recommended to return a proxy class inheriting EigenBase and implementing evalTo(const MatrixBase<Derived>& dest).
|
Registered Member
|
Dear ggael,
thank you for your answer! Unfortunately, the topic is not easy to find in this forum, the only message I found is viewtopic.php?f=74&t=110556&p=261852&hilit=bicgstab#p261852, but I could not find any working example. The methods rows() and cols() are clear but the implementation of the operator*() seems to be really tricky. I run into a lot of compiler errors with a traits class. Do you propose the operator*() to be implemented similarly as the operator solve() in a preconditioner, e.g. in DiagonalPreconditioner? Is there some documentation for the ReturnByValue class? And could you please hint me to an explication on when and why to delegate operations using Derived()? Could you please provide a short snippet showing how to implement matrix-free versions? That would help me a lot! Thank you very much in advance! kbr |
Moderator
|
yes, will try to come up with a documented exemple. In the meantime you might also not bother about this operator* and simply make it return a plain vector. Another solution would be to inherit SparseMatrixBase and implement an InnerIterator on your data. This way you don't have to implement the matrix product yourself that might be an advantage if your data structure does not allow for any fancy optimization here. For products, the InnerIterator does not have to be sorted and non zeros might occur several time in which case they will be accumulated.
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]