[pooma-dev] How to apply a functor to ET leafs
Richard Guenther
rguenth at tat.physik.uni-tuebingen.de
Mon Oct 28 13:39:34 UTC 2002
On Mon, 28 Oct 2002, Richard Guenther wrote:
> Hi!
>
> I'd like to apply a functor to the parts of an expression and view
> the result as an expression. I suspect I can do this somehow using
> forEach(), but before I dig too far, I just ask if somebody knows
> the answer already. Take
>
> Field_t A, B, C;
> Interval I;
>
> C(I) = forEach(A*B, evalAt(0.5), ?)(I);
>
> which should "evaluate" A and B at 0.5 and then just apply the usual
> expression for interval I.
To follow up myself I created
struct evalAt {
evalAt(double x) : x_m(x) {}
const double x_m;
};
template <class T>
struct LeafFunctor<T, evalAt >
{
typedef double Type_t;
inline static Type_t apply(const T &p, const evalAt &x)
{
return peval(p, x.x_m);
}
};
and use now
C(I) = forEach((A*B).engine().expression(), evalAt(0.5), TreeCombine())(I);
but of course I cannot take a view of an expression. So how do I
re-construct a Field<,, ExpressionTag<>> from the forEach result? It needs
to match the A*B expression obviously. Also just using
C(I) = forEach((A(I)*B(I)).engine().expression(), evalAt(0.5), TreeCombine());
doesnt work, as evalAt gets called with Field<> as T, not with the actual
elements it seems.
I'm lost here, Richard.
--
Richard Guenther <richard.guenther at uni-tuebingen.de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/
The GLAME Project: http://www.glame.de/
More information about the pooma-dev
mailing list