4
votes

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.

1

1 Answers

2
votes

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).