Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2003-05-21 11:16:10


Here are my thoughts on what an ideal Expression Template Library should be
like. I do not know how several of these would be implemented, or if they
are feasible.

I only have a basic knowledge of tensors, so I might have some of the
concepts wrong, and I have not done differentiation in about four years, so
that may be rusty.

This list is by no means complete.

[1]

To be able to encode expressions in a natural way, e.g.
   A = 2 * B;
instead of a more complex construct, like

   typedef IndexOverType< std::vector > Vector;
   typedef ScalarType< int > Scalar;
   Assign< Vector >( A, Mult< Scalar, Vector >( 2, B ));

The latter is too complex, making it harder to read the code.

[2]

The ETL should integrate easily with the STL and Boost, i.e.:

[a] It should be easy to make use of functional objects, e.g.
       boost::etl::binary_operator< std::plus >
NOTE: I understand that std::plus operates over the same types, but this
should not matter if the two operands are convertable. It might take a
little more code to help type deduction, but it should be possible.

[b] It should also be possible to perform the expressions over STL and Boost
containers. This may mean supporting assignment from a container to an
expression, e.g.

       namespace stl // sample implementation
       {
          template< typename T, typename E >
          std::vector< T > & operator=
          (
             std::vector< T > & v,
             boost::etl::expression< E > & e
          )
          {
             typedef typename std::vector< T >::iterator
                     iterator;

             iterator end = v.end();
             long ind = 0;
             for( iterator i = v.begin(); i != end; ++i )
                *i = e[ ind++ ];
          }
       }

NOTE: It may be benificial to support std::map types to express named
indices for tensor-like constructs

[c] It should be compatible with iterators as well as numeric indices.
NOTE: What about string indices for certain tensor-like objects? Or
boost::etl::tensor_index for etnsor-like notation?

[3]

It should be possible to specify index variables to express more complex
loop expressions, e.g.

   boost::etl::index_variable i, j;
   T( i, j ) = A( j, i );

for matrix transposition, or

   boost::etl::index_variable i, j;
   boost::etl::einstein_summation k;
   C( i, j ) = A( i, k ) * B( k, j );

to express matrix multiplication, using an implicit summation variable.

[4]

It should be easy to construct Higher-Order Functions that operate over
expression templates, e.g. differention:

   differentiate< Expression >::type

NOTE: This should be capable of encoding known differentiation results, e.g.

   differentiate< std::sin >::type == std::cos
   differentiate< std::cos >::type == -std::sin

NOTE: I have made no attempt to encode the expression structure.

NOTE: The default behaviour for differentiate could be to estimate the
differential numerically, using the mathematical definition:

   differentiate< f( X ) > == ( f( X + delta ) - f( X )) / delta
   where
      delta = 0.00001; // or some other small value

delta could be determined via a template, e.g. delta< T >::value.

_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger


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