Registered Member
|
Hi all,
I'm a new Eigen user, but have been enjoying playing around with it. It seems like it will definitely make my life easier and code cleaner. Anyway, right now I'm trying to find the most succinct way to modify both diagonals (topLeft --> bottomRight, and bottomLeft --> topRight) within a function in which I've used a Ref<T> so that the original matrix or block is writable. These are the relevant bits:
I have tried inserting eval() calls at various places, changing << to =, as well as giving fitLineToLMR() a VectorXf return type and putting it directly on the RHS. I seem to get a similar error message in each case, which I interpret as telling me that "M.rowwise().reverse().diagonal()" doesn't have the proper type for the operator<< or operator= methods (at least with another matrix ref. on the RHS). Probably because it's const? I broke it up a bit so it's more readable:
I understand what -fpermissive is, but I certainly don't know enough to think I should disable it, and I don't know how to go about working around it from here. In the Documentation for reverse(), there is an example where mat.reverse()(i , j) is assigned a value which then propagates back to the original matrix, which makes me wonder if there's some easy way I can get the above code to work as intended. Obviously, I could write a loop to accomplish the task, but in the interest of learning, I'm hoping someone can explain to me exactly why it doesn't work as written, or why the diagonal() call is automatically const, and/or point me towards a possible fix. Thanks! |
Registered Member
|
Ok, well I'm still not sure exactly when and why methods have to return const objects, so if anyone wants to shed some light on that, I would still appreciate it. With that said, I did come up with a solution to my particular problem by doing the rowwise().reverse() call on an identity matrix and then using applyOnTheLeft() to flip the matrix M vertically. Here's how the relevant parts look now:
} |
Moderator
|
This is because there is a shortcoming in the VectorwiseOp class where a non-const overload of reverse() is missing. You can workaround by bypassing VectorwiseOp with something like:
Reverse<Ref<MatrixXf>,Vertical>(M).diagonal() = ...; |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]