[CppAD] constructing an AD function at runtime
Brad Bell
bradbell at seanet.com
Wed Sep 13 08:47:27 EDT 2006
Kipp:
I have added a new example
Example/StackMachine.cpp
that demonstrates how to accomplish what you are requesting.
Unfortunately, the nightly builds with the new dual license are not
quite ready yet,
so I have checked the new example into the
http://www.coin-or.org/svn/CppAD/branches/filename
branch. You can find the source code for the example at
https://projects.coin-or.org/CppAD/browser/branches/filename/Example/StackMachine.cpp
Once the nightly builds for the dual licenses are ready, the new example
will be merged into
http://www.coin-or.org/svn/CppAD/trunk/Example/StackMachine.cpp
Kipp Martin wrote:
> Hi all,
>
> In all the CppAd examples we could find, function expressions are
> hardcoded in the code (compile time).
> Now suppose I want to implement a constructAD function as follows
> (sort of like the Poly function in the "getstarted.cpp" example)
>
> Type constructAD(string[] infixTokens, int sizeOfInfixTokens){
> //an infixToken example of the function 2.1*x1^2) would be:
> {"2.1", "*", "x1", "^", "2") .
> //sizeOfInfixTokens in this example = 5
> Type y;
>
> ..... //need your help
> ... //e.g. you can "logically" do something like: for(int i = 0; i
> < sizeOfInfixTokens; i++){ y+=infixTokens[i] ;}
>
> return y;
> }
>
> How should I do it. The infixTokens is an array of function tokens.
> Each token is a string symbol. Notice you really don't know what the
> string array looks like except that the tokens are in standard infix
> and each token is exactly the same as the corrsponding c++ operator.
>
> As an alternative to passing string array, I can pass an array of
> AD<double> tokens (making it easy to implement the above function).
> For example, I know how to create a number AD, which is as simple as
> AD<double> numberToken = 2.1
> But how should I create a "+" AD? I don't think I can create it like
> AD<double> plusToken = + //compile time error
> or
> AD<double> plusToken = "+" //operator = not ready to take a string?
>
> All the hard-coded example always construct an AD with a term like
> AD<doulbe> plusTerm = 3 + numberToken;
>
> Hope there is a solution constructing AD function at runtime in CppAD.
>
> Jun and Kipp
>
>
>
>
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cppad
>
>
More information about the CppAD
mailing list