Boost logo

Glas :

Re: [glas] evaluation and dispatch of functions

From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2005-09-23 13:20:48


Hello,

I have finished a proposal for norm_2() for vectors.

Let me explain with examples:

typedef glas::dense_vector<double> dense_vector_type ;
typedef glas::add_blas_attribute<dense_vector_type>::type
blas_dense_vector_type ; // vector type that uses BLAS

dense_vector_type v(10); // creates a dense vector of size 10
blas_dense_vector_type w(10);

...

norm_2(v); // computes the 2-norm usin c++ code
norm_2(w); // uses boost-sandbox bindings for BLAS dnrm2()

The dispatching of norm_2 to the right function takes place following a
struct:

template <class Collection, class Attribute>
struct norm_2_function {
   typedef ... result_type ;

  static result_type apply( Collection const& c ) {
    ...
  }
};

Attribute is an mpl::vector containing the information that the dispatcher
needs to do his job.
For dense_vector_type, attribute<dense_vector_type>::type is mpl::equal to
mpl::vector<dense_collection_type>
For blas_dense_vector_type, attribute<dense_vector_type>::type is mpl::equal
to
mpl::vector<dense_collection_type,blas_type>

This attribute is used to do the dispatching.
The nice thing about this attribute is that mpl meta and lambda functions can
be used to create and manipulate them.

I also have some interesting timings, which I keep for my next e-mail.

I have similarly developed norm_1() and abs_sum().
abs_sum() corresponds to the blas asum: it makes the sum of the absolute
values of the real and imaginary parts. It is thus not the 1-norm.
In other words, norm_1() does not have a corresponding BLAS call.

Have a nice week-end,

Karl