Registered Member
|
Relatively new Eigen user, but I've found it to be great so far!
I have a matrix and a row vector. I'm trying to multiply the vector coefficient-wise into each of the matrix's rows. Basically the following:
This gives a compile error since the return type of rowwise() evidently isn't a matrix (or something that implements the cwiseProduct() method). So, I needed to loop over the rows to do what I wanted. Is there a better way?
Thanks! |
Registered Member
|
I did some tests, and using replicate() on the row vector was actually a tad faster than the looping mechanism from before. So, I have a more efficient solution, and am down to a sexy one-liner. =)
|
Moderator
|
with default branch (soon 3.1) you can do: mat.array().rowwise() * rowvec;
|
Registered Member
|
Beautiful, thanks!
I guess the other (easier) workaround for the time being is to multiply by a diagonal like so:
|
Moderator
|
right, the diagonal product is the answer I used to give for this recurrent question, I don't know why I forgot it this one. Note that diagonal products are properly optimized.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]