Re: [proto] How to prevent function to be called for every evaluation of an expression?
> What exactly is dotProduct? Is it a C++ function? If so, it will just > get evaluated and the AST will contain the result of the evaluation. > In that case I would expect it to only get evaluated once. How are you > checking that it gets called multiple times? You might try setting a > breakpoint in dotProduct and check where it gets called from. Hi Bart, I must apologize: because of my messy prototype code layout I forgot that -- in order to benchmark my program -- I evaluated the expression several thousand times; hence the function dotProduct got called that often. But of course you are correct: for every evaluation of the vector expression it gets called only once. Thank you very much! Ole ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
Re: [proto] How to prevent function to be called for every evaluation of an expression?
On Fri, Aug 16, 2013 at 9:43 AM, Ole Svensson wrote: > 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. Hi Ole, What exactly is dotProduct? Is it a C++ function? If so, it will just get evaluated and the AST will contain the result of the evaluation. In that case I would expect it to only get evaluated once. How are you checking that it gets called multiple times? You might try setting a breakpoint in dotProduct and check where it gets called from. Cheers, Bart ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto
[proto] How to prevent function to be called for every evaluation of an expression?
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 ___ proto mailing list proto@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/proto