Hi,
for educational purposes I am implementing an EDSL for vector arithmetic and lazy evaluation which works quite nice (and fast) so far. But when I compile something like:
Vector a, b, c;
a = b + c + dotProduct(b, c);
the result is computed correctly but dotProduct() is called for every component of the vector which is clearly undesirable. I thought of solving this by using transforms to pre-evaluate scalar-valued sub-expressions but when I call
proto::display_expr( b + c + dotProduct(b,c) );
the AST that is printed does not include some kind of function node but the return value of dotProduct(b,c) -- i.e., some number.
So my questions are:
a) Why is dotProduct(b,c) still evaluated for every component and
b) how can I prevent this from happening for *every* scalar-valued function? (I.e., I do not want to declare *specific* functions as terminals in my DSL.)
Many thanks and best regards
Ole