[lambda] Subscripting in lamda expressions.

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 ] ); }

AMDG Robert Jones wrote:
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?
Iter( 0 ), Iter( BLOCK_SIZE ), 0, l[ y ][ _1 ] * r[ _1 ][ x ] );
I think you need var(l)[y][_1] * var(r)[_1][x] (Remember that operator[] can only be defined as a member) In Christ, Steven Watanabe
participants (2)
-
Robert Jones
-
Steven Watanabe