joaoleal / CppADCodeGen

Source Code Generation for Automatic Differentiation using Operator Overloading
Other
162 stars 36 forks source link

Use CppADCodeGen with variable number of independent variable arrays #72

Closed fdevinc closed 2 years ago

fdevinc commented 2 years ago

I managed to define and generate code for functions of the form ADFun adFun(x, y);, but this is not desirable if x must always be assembled from an array of independent variable vectors. Luckily, in the file _genericmodel.hpp I found the following declaration:

/**
     * Determines the dependent variable values using a variable number of 
     * independent variable arrays.
     * This method can be useful if the generic model was prepared
     * considering that the independent variables are provided by several
     * arrays.
     * 
     * @param x Contains the several independent variable vectors
     * @param dep The values of the dependent variables
     */
    virtual void ForwardZero(const std::vector<const Base*> &x,
                             ArrayView<Base> dep) = 0;

I would really like to use this functionality! However, I cannot manage to create an ADFun object that satisfies the above interface (it seems that an adequate constructor is missing). Also, I could not find any examples about this matter. How can I enable my models to be used as in the above snippet?

joaoleal commented 2 years ago

Hello,

That particular method is not meant to be used in normal models (you will not find the equivalent Jacoban/Hessian methods). I would advise using the normal methods with a single independent variable vector.

Kind regards, João

fdevinc commented 2 years ago

Thank you very much @joaoleal! Then I will stick to the usual single independent variable vector!