Conversion between Eigen::Matrixcd and blaze::DynamicMatrix<std::complex<double>>

Issue #175 resolved
祁晓浪 created an issue

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)

  1. Klaus Iglberger

    Hi!

    A conversion from Eigen dense vectors and matrices to Blaze dense vectors and matrices is possible via the CustomVector and CustomMatrix 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!

  2. 祁晓浪 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!

  3. Klaus Iglberger

    Hi!

    The following example demonstrates the conversion between a Eigen::Matrix and blaze::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 the blaze::CustomMatrix, which interprets the given memory as a 2x3 column-major, unpadded, and unaligned dense matrix. For detailed information about the template parameters for CustomMatrix, please see the wiki.

    I hope this example helps to understand the general idea.

    Best regards,

    Klaus!

  4. 祁晓浪 reporter

    Thanks a lot, Klaus! And inspired by your snippet, I've come up with the example converting blaze::CustomMatrix to Eigen::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 :)

  5. Log in to comment