This forum has been archived. All content is frozen. Please use KDE Discuss instead.

SparseMatrix multiplication results RowMajor Storage order

Tags: None
(comma "," separated)
matthiasw
Registered Member
Posts
6
Karma
0
Hello,

I have a problem concerning sparse matrix multiplication and storage order. I have tried the following code:
Code: Select all
typedef Eigen::SparseMatrix<double> sparse_type;
sparse_type P(3,3), U(3,3);
P.setIdentity();
U.setIdentity();


auto A = P * U.transpose();
auto B= U * (P * U.transpose()).eval();
auto C = U * P * U.transpose();
auto D = (U * P * U.transpose()).eval();
printf("%d %d %d %d %d %d",
               (U.Flags & Eigen::RowMajorBit),
               (P.Flags & Eigen::RowMajorBit),
               (A.Flags & Eigen::RowMajorBit),
               (B.Flags & Eigen::RowMajorBit),
               (C.Flags & Eigen::RowMajorBit),
               (D.Flags & Eigen::RowMajorBit)
               ); // prints 0 0 0 0 1 1


To unknown reasons the storage order is changed from column-major to row-major when evaluating the expression U*P*U.T. I know the combination of auto keyword and template expressions is difficult, but as far as I know the above expression should be safe and valid. When I replace auto by sparse_type, the storage order is unchanged. However in the end I would like to do something like:
Code: Select all
sparse_type R(3,3);
R += U * P * U.transpose();

in order to remove the creation of temporary objects, which is not possible due to mismatching storage orders.
Probably, I missed something in the docs concerning triple matrix products.

Thank you for your help.
Matthias

// Edit: added case D, which also changes the storage order.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]