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?

Bug

Journal Journal: Slashdot link weirdness solved: rogue link tracker 5

In the last week or two links to external sites on Slashdot generally don't seem to work unless I click several times. This only appears to happen on Firefox... Chrome is unaffected. I haven't tried IE, Safari, or any other browser. Finally fed up with it, I decided to look through the javascript to see if there was anything funky going on. Looks like there's a script being included from leads.demandbase.com that defines some kind of click tracker. Here's a snippet:

  • else if(a[i].className.match(/clicky_log_outbound/i)){clicky.add_event(a[i],"mousedown",clicky.outbound);}else{clicky.add_event(a[i],"mousedown",clicky.click);

So if you find you've oddly had to click a few times to RTFA, it's not your mouse button dying. Open up adblock and disable everything from leads.demandbase.com and it will be fixed. Links clicked once in Firefox will properly load as they used to. Thanks Slashdot for using an external company for tracking my click behavior. Though perhaps implementing this poorly is Taco's way of giving us a heads-up. Much like the "Idle" section, his overlords may have mandated the addition of this awesomeness to the site and by making it break it alerts us to what we need to block. In which case, a non-sarcastic thanks is due.

I also found this wonderful gem:

  • function pageload_done( $, console, maybe ){
            pageload.after_readycode = (new Date).getTime();
            pageload.content_ready_time = pageload.content_ready - pageload.before_content;
            pageload.script_ready_time = pageload.after_readycode - pageload.content_ready;
            pageload.ready_time = pageload.after_readycode - pageload.before_content; // Only report 1% of cases.
            maybe || (Math.random()>0.01) || $.ajax({ data: {
                    op: 'page_profile',
                    pagemark: pageload.pagemark,
                    dom: pageload.content_ready_time,
                    js: pageload.script_ready_time
            } });
    }

Unless my javascript is really rusty, won't this report 99% of cases?

Anyway, pass this information on so everyone can RTFA without the hassle.

User Journal

Journal Journal: "I could care less"

It's amazing how people try to rationalize away the phrase "I could care less", much in the same way that Star Wars apologists try to rationalize the use of parsecs when talking about the Kessel Run. Maybe there are black holes to navigate around, and minimizing the distance is the sign of a good pilot, or maybe this, or maybe that... or maybe George Lucas just made a mistake, you know?

So when it comes to people rationalizing away "I could care less" as being some nonchalant way of saying "yeah, I could but I'm not going to bother" I just don't buy it. It's a misquote of the perfectly unambiguous phrase "I couldn't care less". So when I stumbled across a rationalization of that, my mind wandered upon what I think is a pretty damned good analogy of why it doesn't make sense: I could eat more.

User Journal

Journal Journal: Tragic Love Story Junkies anonymous 4

Hi, my name is Nat^H^H^HJim, and I admit, I have a problem: I'm addicted to tragic love stories.

It started simply enough with "Romeo and Juliet", but then I saw "Crouching Tiger, Hidden Dragon", and I was hooked, because it had not one, but TWO sets of star-crossed lovers.

Next was "Moulin Rouge", which even my gay brother despises. But it holds a special place in my heart.

I was okay for a while, high on such movies as "Fight Club". But then that bastard Chris Nolan had to make "Memento" (I'm particularly drawn to stories about men who have lost the woman they love). For some odd reason, the "Star Wars" prequels didn't really strike a chord, although they were close.

Then I got married, and I thought I was doing better. Then along comes "Inception". Oh sure, everyone hypes it for being "mind-bending" (what? it wasn't like it was "Primer"), but I secretly believe that Nolan knows how to make an excellent tragic love story, and it shows in not only "Memento" but "Inception".

As I sit here listening to the final track of the "Inception" soundtrack CD (the music from baggage claim to the credits; my favorite by far), I find myself hungry for more. I'm not even sure how to find more, as it's hard to describe. Some other stories I'm acquainted with touch close on similar feelings: the ending to "Lord of Light" by Zelazney, "Permutation City" by Egan (and even further off track, but still close in tone "Diaspora"). "The Fountain" by Aronofsky is definitely another movie that meets the criterion, as well as "Chasing Amy" by Kevin Smith.

I guess I could at least take a stab at some adjectives: a sense of loss, a longing for those truly special people we will never meet again, a feeling of mystery and awe; stories that end with catharsis. So, could you do a junkie a favor and find him one more fix? Thanks :)

User Journal

Journal Journal: Fucking Microsoft 4

You know why I hate Microsoft? They can't follow standards. Or they declare themselves a de facto standards body, even over things they have no rights to dictate standards on. Like C++. I had forgotten that MSVS has a broken version of std::copy(). It doesn't work on simple char arrays. Works fine on VxWorks and Linux. Fucking Microsoft.

Slashback

Journal Journal: Dear slashdot 3

The foe/friend limit is ridiculous, even with subscription. 400 friends/foes is simply not enough to foe all the people who post baseless assertions and get modded to +5, and simultaneously friend people who who get modded troll for posting an informative link that blows the moderators' beliefs out of the water. Pls fx, kthxbye.

User Journal

Journal Journal: Profiling 3

No, not the racial kind. This has to do with code efficiency. I was recently writing patch acceptance guidelines, and was trying to explain that maintainability matters far more than efficiency. I was trying to be polite about people who harp on "efficiency", but my basic feelings boil down to: "People who talk about software efficiency, yet aren't familiar with software profiling, are idiots." Discuss.

User Journal

Journal Journal: Rare earth metals 3

Just a quick thought before I have to go into work today: so China is possibly looking at cutting back their rare earth metal exports, but that doesn't seem to stop them putting them in children's toys and/or jewelry. So, why not this: don't chastise China for bad behavior; just buy up all the heavy metal toys as they are imported and melt them down! Heck, it even says in the article that the jewelry "easily sheds" cadmium.

I mean, lead was one thing, we're not in need of that (apparently we use something else for our pipes now). But cadmium? Last I checked, that was good for electronics, and we *always* need more of those.

GNU is Not Unix

Journal Journal: Stable API Nonsense 2

Recently there was a discussion about how Linux cell phones are basically DOA, and within that discussion was a thread on a stable driver interface in Linux. Rather than respond to every comment as to why this is a bad idea, I figured I would just post the original response to this request for a stable driver API which was put together the first time people noticed it was hard to ship binary drivers for Linux:

Let me just point out that this approach *works* and *has worked* quite well for quite sometime. These days, when I buy a new piece of hardware, I throw out the driver CD without even looking at it. I plug in the hardware to my Linux box fully expecting it to work; if it doesn't, I figure it's broken. Occasionally, it's not broken hardware but rather I have made a mistake and invested in a piece of hardware from a company that has not seen the light and open sourced their drivers. I make a point never to buy from that company again, and I get a refund for the hardware. I might point out that this is a very rare occurrence. Most of the time there is support for hardware out of the box under Linux - no driver CDs, no install and no reboot required - just plug and go.

Implementing a stable API for drivers would lead to bloat, insecurity and instability; we've seen it happen in Windows, and even starting to happen with binary drivers under Linux! The technical argument is that Linus (and his kernel devs) reserve the right to rip out or reimplement anything they please in the kernel, with no regard whatsoever to backwards compatibility. This model has worked very well so far, as evidenced by the fact that you can plug in 99% of hardware into a Linux box and have it just work, no driver CD, download or install required.

Still, some people argue this is a political issue, not a technical one. I would agree, on one point: the hardware vendors are the ones making this a political issue. By refusing to release their source code, they limit how well their device can be supported. For what purpose do they need to keep their drivers closed? They sell hardware, not software, therefore they don't even have an economical reason. The arguments for releasing source are legion: support in ALL distros on ALL architectures by default; more stable and better tuned drivers; no need to ship driver CDs; no worry about having to support your drivers as they are now in the kernel, etc. I can think of no reason other than petty greed to keep drivers closed. And it's greed that doesn't even function properly at that, as it doesn't gain the greedy companies anything.

Is there any *technical* reason to keep drivers closed source? Please elucidate, and remember that even if there is, it must somehow outweigh all the benefits of having the same driver as an open source driver in the kernel in order to argue that there should be a stable driver API. This isn't an ideological, or even political issue; open source drivers have been shown *in practice* to work better, and provide all of the benefits I've listed. Why should we throw out one model that works for one that has been shown to not work nearly as well?

Music

Journal Journal: Found something that I think sounds cool 6

*Sigh*, I'm still waiting on my 1TB HDDs for the file server, which I will use to replace the 250GB drive, which I can then put in the web and email server. For now, that means I still post journal/blog entries here, as I don't see the point of upgrading the software on the web/email server until I have the drive available for it. Anyway, my pointless rambling is all a preface for this:

http://www.archive.org/details/Snu-op025-Caravan

I found it while looking for recordings of sheet music we play in our Big Band (guess which song I was looking for :). I thought the song sounded pretty cool, so I'm sharing it with you. Hope you enjoy it!

GNU is Not Unix

Journal Journal: "Free Software doesn't have end users" 3

So, I was going through the links on BBSpot today, and I found what I can only describe as one of the most lucid, well-written articles on Free culture I've seen in a long time: Thank you for giving me the opportunity to explain this to you. It's so fan-fucking-tastically good that I'm severely tempted to make my new signature on slashdot a link to that article with the title "Free Software doesn't have end users".

Every time I see some whiny bastard say "but Linux will never take over the desktop! you have to pay attention to MEEEE -*- cough -*- I mean, you have to pay attention to the end users!" I just want to bitchslap the little schmuck. What have these so-called "end users" done for Linux? Fuck them! The end users of Linux and Free Software have always been the same people who created it: the developers. If you "just want it to work", and you can't even be arsed to file a bug report, fuck you. It works for us; you should be grateful we decided to share the source with you.

Ranting aside, this really cuts to the heart of why I use Free Software: even if it wasn't technologically superior (which it is, precisely because it is Free Software), I would still use it because it is the only software I can modify and use however I want without having to say the equivalent of "please sir, may I have another?" to some big corp. whose only concern is next quarter's earnings.

Free Software doesn't have end users; that's kind of the point. You can either participate and contribute a little something back or you can pay some company to tell you what you are not allowed to do. We welcome your input, but if all you can do is say "your software sucks! do what I say or I'll use someone else's software!" then all I can say is farewell and peace be to you.

User Journal

Journal Journal: Mod points 3

So after lurking on the site a while, I kicked off my Slashdot account with this post. Just over six years later, I get mod points for the first time today. What's up with that?

Slashback

Journal Journal: Getting messages to show at the top of the page 2

Messages used to show at the top of the page above the first article, in a format like: "You have 2 new messages and 1 old message". Now they show up in a box on the right which, even though I know it's there, just doesn't work for me. As a consequence, I'm constantly missing out on replies and others' journal entries. I noticed you can drag the box around, but only in that column. Anybody know how to get the message notification to show up like it used to?

Books

Journal Journal: John Taylor Gatto's "Underground History of Education" 5

So I've been reading The Underground History of American Education by John Taylor Gatto. I've found it very enlightening, and up until Chapter 14 I was pretty much agreeing with the author. Now, I'm not one who dismisses everything I disagree with out of hand; on the contrary, I try to seek out opinions different from mine and test them (and mine) against evidence to better understand the world. But when Gatto starts citing court rulings such as the "posting the ten commandments in school rooms is unconstitutional" as bad and anti-religious, I start to grow a bit skeptical.

As I had been reading TUHoAE I detected faint warning signs that Gatto might have a religious bias. Little things that warned me, such as his antipathy towards what he called "scientific teaching". I could excuse some of these as perhaps merely terminology differences; what Gatto meant by "scientific thinking" did not match up with what I meant by it.

But then the other shoe dropped: Gatto demonstrates his bias against science which contradicts his religion:

Instead of remaining merely a useful description of how things work, great synthesizing theories like Big Bang or Natural Selection purport to explain the origin of the universe or how life best progresses. Yet by their nature, these things are beyond proof or disproof. Few laymen understand that the synthesizing theories of Science are religious revelations in disguise.

How are the big bang theory and the theory of natural selection not useful descriptions of how things work? How could someone who is obviously so erudite and had researched previous chapters so well fall into the trap of baseless assertions and a basic misunderstanding of the way science works? Is he not aware that natural selection has been demonstrated many times?

Another quote that left me gaping:

We are hidden by more than a half-century from the shock and numbness this new doctrine of "separation of church and state" occasioned, a great bewilderment caused in part by the absence of any hint of such a separation doctrine in the Declaration, Constitution, or the Bill of Rights.

Did he seriously just ignore the first amendment? Is he completely oblivious to the treaty of Tripoli, which by the constitution is legally binding as law of the land, and it states "the Government of the United States of America is not, in any sense, founded on the Christian religion" and it was signed over two centuries ago?

Another question I had was why had no one noticed this? In all the reviews I read, no one had mentioned that Gatto turned into a raving young-earth creationist midway through his book. Had these people read the book all the way through? Where are all the people who should be calling him out on his kookiness? The chapter I'm currently reading is his least footnoted and therefore least supported by evidence one so far, although I notice that previous chapters had been slowly but steadily heading towards less references.

Gatto tries to sound unbiased and reasonable, but the way he phrases things makes it obvious he thinks that there can be no morality without religion. Through the court decisions he throws out as "anti-religious" the reader can also tell he is one of those christians who believes he is being persecuted because he isn't allowed to force his religion on others.

I will try to make myself finish the book, grating though Gatto's unfounded assertions may be. I do value the eye-opening, well-researched and well-documented information that was contained in the earlier part of the book. It had always seemed to me that there was something wrong with public school education in America; I'm grateful to have substantiating evidence to back that assertion up. But I think that Gatto has misdiagnosed the cause and blamed the wrong driving forces for the downfall of education in this country. While I will not deny that anything can be taken dogmatically, I don't believe that returning to one dogma (religion) in place of another (so called unscientific "scientism") is the answer. I believe the answer is to become more rational, less biased and more pragmatic towards how people learn.

What do you think?

Slashdot Top Deals

New York... when civilization falls apart, remember, we were way ahead of you. - David Letterman

Working...