Best approach to init a matrix from `std::vector`?

Issue #374 resolved
Ecolss Logan created an issue

From the doc, we could init a matrix from std::array, but I wonder what’s the best way to do init from a std::vector?

Although we could iterate the std::vector and assign the values, but not sure if the perf might be poor?

Comments (2)

  1. Klaus Iglberger

    Hi Ecolss!

    I apologize for the late reply. I hope you have found the array constructors that are available for all dense matrices:

    const std::unique_ptr<double[]> array( new double[6] );
    // ... Initialization of the dynamic array
    blaze::StaticMatrix<double,2UL,3UL> M1( 2UL, 3UL, array1.get() );
    
    const std::vector<double> vector{ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 };
    blaze::DynamicMatrix<double> M2( 2UL, 3UL, vector.data() );
    

    Best regards,

    Klaus!

  2. Log in to comment