Registered Member
|
This is a follow up on this question: viewtopic.php?f=74&t=111094.
I am writing a class (e.g. class A) that contains and operates on a matrix with custom scalars (class B). The instances of class B, however, can be multiplied by doubles, i.e. class B contains relevant overloads. I would like to know how would it be possible to implement matrix (containing custom scalars) multiplication by doubles. Here is a simple example of what I would like to do:
I presume one way to resolve the issue would be to introduce another overload for operator* in Eigen library. However, I am not sure how to approach the problem. Another way would be to write a custom multiplication procedure that would run through the whole matrix and multiply each element individually. Obviously, this is a much easier solution, but it would defy (to some extent) the purpose of using Eigen matrix class for my application, as, I presume, such solution would be very inefficient comparing to the algorithms used by Eigen. Basically the questions are: 1). How easy do you think it would be to introduce the multiplication by double for someone with little knowledge of Eigen classes from the developers perspective? Could you suggest how to do it? 2). Are there any simple workarounds that I have not thought of? 3). How much more inefficient would be the iterative multiplication for large matrices? Thank you. |
Moderator
|
You can implement an overload of operator* and make it returns an Eigen expression type, e.g.:
You also need to specialize internal::scalar_product_traits for your type:
and don't forget the symmetric cases. |
Registered Member
|
Works well. Was not expecting to get a ready solution. Thank you very much.
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]