Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
Programming

Journal npsimons's Journal: Boost UBLAS matrix iterators and templates - Solved

UPDATE: I had a look around, figured I would try substituting a std::vector<std::vector<double> > for the uBLAS matrix<double>, still got the same error. So I started looking better into templates (no, I'm not quite done with vol2 of "Thinking in C++") and found out about typename. Seems to fix the problem.

I know I should probably post this to stackoverflow or the Boost/UBLAS mailing list, but I figure there are plenty of smart people here at slashdot.

Let's say you are using UBLAS from Boost and you want to implement a cumulative summing function for matrices. Here's what I think is a fairly straightforward way to do it:

// For boost::numeric::ublas::matrix<>.
#include <boost/numeric/ublas/matrix.hpp>

// For std::partial_sum().
#include <numeric>

template<class T>
boost::numeric::ublas::matrix<T> cumSum
(const boost::numeric::ublas::matrix<T>& input_,
const bool& colWise_ = true)
{
using namespace boost::numeric::ublas;
using namespace std;

matrix<T> result_(input_);

if (colWise_)
for (matrix<T>::iterator2 colIter = result_.begin2();
colIter < result_.end2();
colIter++)
partial_sum(colIter.begin(),
colIter.end(),
colIter.begin());
else
for (matrix<T>::iterator1 rowIter = result_.begin1();
rowIter < result_.end1();
rowIter++)
partial_sum(rowIter.begin(),
rowIter.end(),
rowIter.begin());

return result_;
}

For now, I'm ignoring completely templatizing this to make the row-wise/column-wise distinction disappear in the code and focusing on just getting it working. Only it doesn't work; won't compile. Couldn't figure out why, but g++ kept saying it was expecting a ';' before colIter and rowIter. I had a hunch and replaced one of the iterator's 'T's with 'double' and it stopped complaining about that one. Am I missing something, or does UBLAS not implement iterators properly?What am I missing?

This discussion has been archived. No new comments can be posted.

Boost UBLAS matrix iterators and templates - Solved

Comments Filter:

For God's sake, stop researching for a while and begin to think!

Working...