Let's refactor my::norm_1() to use matrix_column:
// ... #include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/matrix_proxy.hpp> // 1 namespace ublas = boost::numeric::ublas; namespace my { double norm_1(ublas::matrix<double>& m) { double norm = 0.0; for(unsigned int j = 0; j < m.size2(); ++j) { ublas::matrix_column<ublas::matrix<double> > mc(m, j); // 2 double current = my::norm_1(mc); // 3 if(current > norm) norm = current; } return norm; } }1. Here are the matrix proxy definitions, remember to include this header file.
2. Declaring a matrix_column based on a matrix of doubles, passing to it the actual matrix and the index of the column we are interested in.
3. The matrix_column could be treated as a normal uBLAS vector, here we are passing it to our norm_1() functionality.
No comments:
Post a Comment