Zak
Zak

Reputation: 12623

How do you get an iterator to a row of a boost::numeric::ublas::matrix<T>?

I'm working on matrix multiplication, and I would like an iterator over a single row of a boost matrix? Can this be done?

Currently, I have to get an iterator and advance it. It seems like too much CPU work / non-optimized...

boost::numeric::ublas::matrix<T> aMatrix(2048, 4096);
typename boost::numeric::ublas::unbounded_array<T>::iterator it;
it = aMatrix.data().begin();
offset = row * aMatrix.size2();
advance(it, offset);

Upvotes: 3

Views: 2629

Answers (1)

Zak
Zak

Reputation: 12623

Eureka! Matrix proxies...

boost::numeric::ublas::matrix_row<boost::numeric::ublas::matrix<T> > aRow(aMatrix, row);

Upvotes: 4

Related Questions