|
Boost : |
From: Joerg Walter (jhr.walter_at_[hidden])
Date: 2002-07-01 00:40:52
----- Original Message -----
From: "Benedikt Weber" <weber_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.devel
To: <boost_at_[hidden]>
Sent: Sunday, June 30, 2002 2:19 PM
Subject: [boost] Re: uBLAS and expression templates
> Joerg
>
> > It's a proven (but not well known ;-) technique to reintroduce
> > temporaries at the right places into the expression, i.e. writing A *
> vector
> > (B * v).
>
> I am glad there is at least a possibility to force the creation of a
> temporary. However, the user should not have to be concerned about such
> details. I never did anything with expression templates and I only
recently
> read about them in the context of the Spirit parser. However, I think it
> should be possible to change the design so a temporary is automatically
> introduced where appropriate (say for the prod() functions). I urge you to
> think about a possibility to change that. It would be a real benefit for
the
> library.
Ok. After discussing this issue intensely with Mathias (thanks, Mathias!),
I've added overloads like the following:
template<class M, class E1, class E2>
NUMERICS_INLINE
M
prod (const matrix_expression<E1> &e1,
const vector_expression<E2> &e2) {
return M (prod (e1, e2));
}
With these new overloads, we'd recommend to write your original sample in
the following way:
t.restart ();
for (int run = 0; run < 1000; ++ run)
r.assign (prod (prod<matrix<double> > (A, B), v));
std::cout << t.elapsed () << std::endl;
t.restart ();
for (int run = 0; run < 1000; ++ run)
r.assign (prod (A, prod<vector<double> > (B, v)));
std::cout << t.elapsed () << std::endl;
A couple of questions remain open:
- Should we rename the original ET' based prod() functions to something like
defer_prod()? - Is it possible to determine a sensible default for the type
of the temporary (for example via some traits classes)?
[snip]
Regards
Joerg
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk