Boost logo

Boost :

From: Serge Barral (sbarral_at_[hidden])
Date: 2001-03-30 05:35:29


On Fri, 30 Mar 2001 07:20:22 Jeremy Siek wrote:
>[...]
> One especially cool/wild aspect of the code is that there is no extra
> algorithm code for matrices, they are treated a lot like vectors (whose
> elements happen to also be row or column vectors). Since there are
> expression template operators defined for vectors, each operator used in
> the outer loop expands to create the inner loop. This is explained here:
>
> http://www.lsc.nd.edu/~jsiek/mxtl.html

Concerning the discussion about overloaded operators, I find the idea of
having only 3 (did I count well??) signatures for a binary operator quite
seducing.
I'm not sure, however, that I understand what you mean when you say that
with other approaches, binary operators would have to be defined for all
combinations of matrices and vectors. Do you mean that they need to be
overloaded for
( matrix_type1, matrix_type1 )
( matrix_type2, matrix_type1 )
( matrix_type1, matrix_type2 )
( exp< T >, matrix_type1 )
 and so on?

If so, I think there are alternative approaches (I suspect Blitz uses one
of these) which let you define at most n+2 overloaded operators (n is the
number of supported basic types, excluding expressions). It can be achieved
for example by deriving (with the B&N trick) from a common base class every
supported type as well as the expression template type and by overloading:
( matrix_type1, T )
( matrix_type2, T )
( exp<T1>, T2)
( T1, base_class<T2> )

of course, that still requires several overloaded operators, but not that
much (one slight advantage is that it leaves the possibilty to involve an
arbitrary scalar type in a binary operation).

           Serge


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk