Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Programming

Journal 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?

Spam

Journal Journal: Today's 3-strikes winner

Here's today's list:

strategicamerican.com

I haven't seen one like this in a little while. The whois info seems to be incorrect, because if you call the number listed for the technical contact you'll get a very, very rude person who insists it's a wrong number and hangs up on you. If you go to the Website, the phone number on the 'contact' page has been disconnected. They make it easy to get blacklisted!

Spam

Journal Journal: Today's 3-strikes winners

Here's today's list. All came from the same subnet, in classic snowshoe spam style:

sarahchadyes.com
wearouse-in.com
whenbacks.com
flipping-sout.com
bett-in-bett.com

Spam

Journal Journal: Yahoo! spam back up; today's 3-strikes list

After taking a couple of months off, the levels of spam from Yahoo! has risen back to about 40-50% of the spam total. Not sure what that means, or what's going on.....

Here's today's list:

billionschip.info

Spam

Journal Journal: Today's 3-strikes winners

It's been slow for the spammers lately. Here's today's list:

sendeflyer.com
narutoswings.com

Slashdot Top Deals

An authority is a person who can tell you more about something than you really care to know.

Working...