News for hackers. Stuff that matters.
Re:Haskell Beats C Using Generalized Stream Fusion [pdf] by kevingadd on Sunday April 07, 2013 @11:38AM (#5507530)
Before you say 'oh, Haskell is still only half the speed of C++', you should keep in mind just how insane the C++ code they had to write looks. The Eigen code they had to write is pretty nasty and getting it correct required some particular understanding.

In comparison, the performance they're getting out of Haskell is coming from comparatively mundane, easy to understand code. That's pretty impressive.

Or another way of putting it: It looks like naive Haskell outperforms naive C++, and naive Haskell is not that much slower than carefully-tuned C++.

    template < typename Derived >
    typename Derived::Scalar norm2( const MatrixBase <Derived >& v ) {
        return v.dot(v);
    }
Why is it a template function? Why does it return Derived::Scalar instead of double? Dear god, Eigen is magic.
Re:Haskell Beats C Using Generalized Stream Fusion [pdf] by pbsd on Sunday April 07, 2013 @12:59PM (#5507790)
While 'Derived::Scalar' could very well be replaced by 'double' in that case, you need the templated function to catch the temporary type (expression template) that represents the u-v computation. This lets Eigen compute u[i]-v[i] and the dot product inside the same inner loop.

Without the templated function, the compiler would first generate the subtraction into a temporary vector, and then compute the dot product on that vector.

Re:Haskell Beats C Using Generalized Stream Fusion [pdf] by kevingadd on Sunday April 07, 2013 @03:52PM (#5508454)
That makes sense, thanks! I figured the template was being used to magically substitute some sort of meta-type or container for temporaries.
Re:Haskell Beats C Using Generalized Stream Fusion [pdf] by dfbrown on Sunday April 07, 2013 @03:58PM (#5508481)
I'm not sure why they wrote this in the first place. Eigen's MatrixBase already has a squaredNorm function: http://eigen.tuxfamily.org/dox/classEigen_1_1MatrixBase.html...

edit: I see, they address this in the article: In this specific case the Eigen library has the squared L2-norm in its API, but in more complicated examples there might be no such built-in provision

Re:Haskell Beats C Using Generalized Stream Fusion [pdf] by marshray on Sunday April 07, 2013 @06:15PM (#5508990)
That code doesn't look particularly insane to me.

Uh oh.

Re:Haskell Beats C Using Generalized Stream Fusion [pdf] by ibotty on Sunday April 07, 2013 @12:07PM (#5507609)
if i understand the paper correctly (and apply the knowledge to eigen), it't because of the same reason: you want to allow different stream fusion strategies to work.
Re:Haskell Beats C Using Generalized Stream Fusion [pdf] by dchichkov on Monday April 08, 2013 @02:30AM (#5510263)
The code (actual instructions) that beats C++ in their example is being generated by their experimental "stream fusion" framework. And NOT by a generic Haskell compiler.

And now the question, do you really want to an unproven and unstable Haskell framework? While there are stable alternatives (lake Eigen, Theano, etc) available?

So no. Haskell (production ready Haskell) doesn't even come close.