Registered Member
|
I couldn't find this issue in the forums or in the bug reports, so please let me know if it is a known issue.
I have a dynamic vector, and I am trying to transpose it in place so that a row vector becomes a column vector and vice versa. From what I understand transposeInPlace should permanently alter the structure of the vector unlike transpose. Here is some example code to show the erroneous output I am seeing: // try to transpose a vector Eigen::VectorXi colVector(5); colVector << 1, 2, 3, 4, 5; std::cout << "col vector: " << std::endl; std::cout << colVector << std::endl; std::cout << "row vector: " << std::endl; colVector.transposeInPlace(); std::cout << colVector << std::endl; // matrix transpose Eigen::MatrixXi beforeTranspose(3,2); beforeTranspose << 1,2,3,4,5,6; std::cout << "matrix before transpose: " << std::endl; std::cout << beforeTranspose << std::endl; beforeTranspose.transposeInPlace(); std::cout << "matrix after transpose: " << std::endl; std::cout << beforeTranspose << std::endl; Here's the console output for this section of code: col vector: 1 2 3 4 5 row vector: 1 2 3 4 5 matrix before transpose: 1 2 3 4 5 6 matrix after transpose: 1 3 5 2 4 6 As you can see the transposeInPlace works for the dynamic matrix but not the dynamic vector. I am using the stable release of Eigen 2.0.12. I am running the code in Microsoft Visual Studio 2008 version 9.0.30729.1 SP. Please let me know if I am doing something wrong or if this is a legitimate bug. Thanks. |
Registered Member
|
You're doing something wrong: since colVector is of type Eigen::VectorXi, which means "column vector", it can't be transposed in-place, as that would amount to trying to fit a row-vector in a col-vector.
This is something that we actually can't check for sure at compile-time, because if your vector had length 1, that would be a valid operation (albeit a NOP). But since this operation is either illegal or a NOP, I'm OK to forbid it. Just don't have time, patches welcome
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Thanks for the quick answer. I wasn't aware that Eigen::VectorXi was just a column vector. I assumed it could handle either column or row vectors. I suggest that this distinction be added to the tutorial pages in order to avoid future confusion.
Thanks. |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]