I want to move(or swap) an array of type Eigen::ArrayXXd to Eigen::MatrixXd. To achieve this, I tried,
#include <iostream>
#include <Eigen/Dense>
using namespace std;
int main(int , char** ) {
Eigen::ArrayXXd array(100,100);
auto mat2 = std::move(mat.matrix());
cout << array.size() << endl;
cout << mat.size() << endl;
}
The output shows that the both sizes are 10000, which means array was copied. To avoid copy, I also tried,
Eigen::MatrixXd mat;
mat.swap(array.matrix()); (runtime error assert failure)
// swap(array.matrix(), mat); (compile error)
The version of Eigen I tested is 3.2.0 beta1 and gcc 4.8.0 was used. From the experiment, it seems that the move semantic for Matrix and Arrays is not implemented yet. Is that right?
Is there a way I can safely move (without copy)?
You cannot force something to be moved. If Eigen does not have a move constructor/assignment operator for the operations you're trying to do (and I see no evidence of Eigen being move-aware in their documentation), then you can't move them.
Move isn't magic; it requires explicit support by the writer of a type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With