- marked as enhancement
Conversion between Eigen::Matrixcd and blaze::DynamicMatrix<std::complex<double>>
Great thks to Klaus team for your brilliant fast matrix lib! We'd like to know if there is a fast way to do Conversion between Eigen::Matrixcd and blaze::DynamicMatrix<std::complex<double>>. It would be good if they can share the same memory object.
Comments (7)
-
reporter -
-
assigned issue to
-
assigned issue to
-
- changed status to open
-
- changed status to resolved
Hi!
A conversion from Eigen dense vectors and matrices to Blaze dense vectors and matrices is possible via the
CustomVector
andCustomMatrix
classes. This solution also guarantees that no copy is performed, but the same memory is used.I hope this feature is exactly what you are looking for. Thanks for using Blaze,
Best regards,
Klaus!
-
reporter Klaus, thanks a lot for your timely reply. Could you kindly show some code examples of the conversion between Eigen and Blaze? Thanks in advance!
-
Hi!
The following example demonstrates the conversion between a
Eigen::Matrix
andblaze::CustomMatrix
:Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,Eigen::ColMajor> A( 2UL, 3UL ); A << 1, 2, 3, 4, 5, 6; std::cout << "\n A =\n" << A << "\n"; blaze::CustomMatrix<int,blaze::unaligned,blaze::unpadded,blaze::columnMajor> B( A.data(), 2UL, 3UL ); std::cout << "\n B =\n" << B << "\n\n";
Output:
A = 1 2 3 4 5 6 B = ( 1 2 3 ) ( 4 5 6 )
The
data()
function returns a pointer to the first element of the matrix. This pointer is passed to theblaze::CustomMatrix
, which interprets the given memory as a2x3
column-major, unpadded, and unaligned dense matrix. For detailed information about the template parameters forCustomMatrix
, please see the wiki.I hope this example helps to understand the general idea.
Best regards,
Klaus!
-
reporter Thanks a lot, Klaus! And inspired by your snippet, I've come up with the example converting
blaze::CustomMatrix
toEigen::Matrix
:Eigen::Map<Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,Eigen::ColMajor>> XX(B.data(), 2UL, 3UL); std::cout << "\n XX =\n" << XX << "\n\n";
Hope this thread could help some other guys :)
- Log in to comment