Boost logo

Boost Users :

Subject: [Boost-users] [lambda] Subscripting in lamda expressions.
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-11-25 09:30:20


Here's a little quick and dirty square matirx multiply I've written. Ok. I
know
this leaves a lot to be desired on the quality front, but I'm not in a
position to
rewrite the whole system here!

The lambda function argument to accumulate is clearly not right, but how I
write something that implements the intention here?

Thanks, Rob.

typedef int block[ BLOCK_SIZE ][ BLOCK_SIZE ];

void matrix_product( block & result, const block & l, const block & r )
{
  typedef boost :: counting_iterator< unsigned > Iter;

  using namespace boost :: lambda;

  for ( unsigned y = 0; y != BLOCK_SIZE; ++ y )
    for ( unsigned x = 0; x != BLOCK_SIZE; ++ x )
      result[ y ][ x ] = std :: accumulate(
          Iter( 0 ), Iter( BLOCK_SIZE ), 0, l[ y ][ _1 ] * r[ _1 ][ x ] );
}



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net