4

If I have n vectors of length m and want to join them to create an mxn matrix, what is the most efficient way to do this in C++ using Boost uBLAS?

Obviously, I can just loop though them and assign each matrix element with the corresponding vector value, but I feel like there is a better way to do this I am unaware of.

al0
  • 308
  • 1
  • 2
  • 13

1 Answers1

2

Rather than iterating the entire list of vectors element-wise, I would try assigning each of your vectors directly into the corresponding matrix column.

template<class AE >  
BOOST_UBLAS_INLINE matrix_column &  operator= (const vector_expression< AE > &ae) 

You have to copy each element at some point, but this should be faster than a nested loop (or a perf bug in Boost.uBlas, if not).

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140