Registered Member
|
Dear all,
I followed the wiki to implement a custom scalar type with support for operator+, operator-, and operator*. Addition and subtraction work fine. However, multiplication yields an error during compilation which I do not know how to fix.
Compiled under macOS (10.11.6) with
and
I end up with the following error
Any help is highly appreciated. Best regards, Matthias |
Moderator
|
You need to add a ctor from T, e.g.:
this is needed to handle cases such as: Matrix<...>(3,0) * Matrix<...>(0,5) but since in your case sizes are known at compile-time we could remove this code at compile-time, perhaps for the next 3.3.5 release. |
Registered Member
|
Thank you very much for your reply.
I have added the ctor as suggested with
instead of
The latter produced the compiler error: no matching member function for call to 'Map' Matrix-matrix multiplication works well, thanks. The only downside of this approach is that the default ctors are no longer available by default. I have implemented
but this only supports matrix construction via
and not the more readable
Any suggestions are appreciated. Best, Matthias |
Registered Member
|
In addition to the above mentioned problems I encountered the following problem when combining custom scalar types of different type.
Using the implementation of ScalarType from my previous post, the following code in main
leads to the compiler error:
Matrix-vector multiplication of the custom scalar type does work:
Best, Matthias |
Moderator
|
You need to tell Eigen that they are compatible and what the return type is by specializing Eigen::ScalarBinaryOpTraits: http://eigen.tuxfamily.org/dox/structEi ... raits.html
If we move to C++14 and forget about C++03 support, then such type deduction could be done automatically. |
Registered Member
|
Thanks very much. I have implemented the trait as given in the wiki and it seems to work.
My apologise for reporting an error, which turned out to be just a typo in my implementation. Best, Matthias |
Registered Member
|
I still have some problems with making custom scalar types run. The complete code is given below.
Compilation with the following settings (1x1 dense matrices with compile-time sizes, lines 280-282)
works fine. However, when I switch to dynamic matrix sizes (-D__EIGEN_DYNAMIC, lines 284-286)
then I get the following compiler errors:
Any help is appreciated. Please note that this error is not due to libxsmm which is deactivated in the aforementioned compiler configuration. Code:
|
Moderator
|
use A.lazyProduct(B) to by pass the difficulties.
|
Registered Member
|
Thanks very much. Since lazy evaluation did not work as expected I had a deeper look into the Eigen kernel
IMHO, there is a bug in Eigen/src/SparseCore/ConservativeSparseSparseProduct.h. For custom scalar types it is not correct to use the same Scalar type for the Lhs, Rhs, and the ResultType in the functions conservative_sparse_sparse_product_impl and sparse_sparse_to_dense_product_impl. I have attached a patch file that makes the necessary changes: PATCH FILE
|
Moderator
|
thank you for the feedback, there were more occurrences though: https://bitbucket.org/eigen/eigen/commits/bccf2d933699
|
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]