Registered Member
|
Dear all,
While experimenting with custom scalar types I figured out that dense-sparse matrix-matrix multiply dispatches to sparse-dense matrix-matrix multiply with both matrices transposed (and the resulting matrix transposed, too). However, the scalar types of all matrices involved remain unchanged. I have implemented a custom scalar type that represents local dense n x m matrices including all admissible operations like (n x m) = (n x k) * (k x m). If the global container matrices are transposed then this has to be done for the custom scalar types as well. Otherwise, the global multiply is no longer well defined. Is there an internal trait that I can specialize for my custom scalar type that tells Eigen how to treat the scalar type in case the transpose() method is called on the global matrix? Best regard, Matthias |
Moderator
|
yes, currently we assume fields with associative addition and multiplication, which is not your case. This is also a problem for, say, {Sparse}Matrix<Quaternion>. Such a trick is used is several other matrix product cases. The easiest might be to wrap scalar products like "a*b" through a template helper that would swap the factor if needed.
|
Registered Member
|
I looked into the file Eigen/src/SparseCore/SparseDenseProduct.h
1) IMHO, it might be better to replace the occurrence of 'const typename Res::Scalar& alpha' by 'const AlphaType& alpha; in the various run(...) methods since (a) AlphaType is a template parameter of the struct anyway, and (b) the method that should be called by the user
follows this convention anyway. See attached patch: 2) Would you mind adding a dense_time_sparse_product_impl or, alternatively, add an extra template parameter to sparse_time_dense_product_impl, which let's the user decide whether internally res = lhs * rhs or res = rhs * lhs should be computed? If I understand you correctly, Eigen assumes associativity of addition and multiplication. In my case the latter is not true but I could very easily re-use the sparse_time_dense_product_impl by simply swapping the order lhs * rhs -> rhs * lhs. If this could be controlled by an extra templated bool flag that would be great. Patch for issue 1)
|
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]