Registered Member
|
Hey
I need to do a matrix-vector multiply, using the matrix or it's transpose depending on some condition, and I wanted to hide this test so I came up with: (where my_c is an instance of class c containing some matrices, and v is a vector)
the implementation of c::get_m():
This works OK. My first question is if this code will be good and do some kind of implicit transposition. The next thing is, I also want to sometimes modify either the matrix or its transpose depending on a condition i.e. do something like
But I found that when I alter get_m to instead return a regular, non-const, reference I get an error
Is there some way I can return a non-constant reference to the transpose? Thanks in advance for any insights |
Moderator
|
MatrixXf is a column major matrix, so when you do return m.transpose();, m.transpose() will be copied into a temporary. If "cond" can be known at compile time, then you can use template meta programming to return a const MatrixXf& or a Transpose<const MatrixXf> depending on "cond".
|
Registered Member
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot]