Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Functions with Constant Array Type Parameters in Jacobian Mode #478

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Aug 12, 2022

  1. Add Support for Functions with Constant Array Type Parameters in Jaco…

    …bian Mode
    
    Now One must be able to find the Jacobian of functions with Constant Arrays in the parameter list.
    For example, a function of the form:
    ```cpp
    void func(double arr[3], double x, double y, double* output){
    	output[0]=arr[2]*x*y;
    	.
    	.
    	.
    	output[n-1]=arr[0]*arr[1]*arr[2];
    }
    ```
    
    will generate a Jacobian of size n x 5.
    
    Corresponding tests for the same have been written.
    
    Previously this feature was not implememnted because it was necessary to know the size
    of an array to correctly determine the size of the output jacobian matrix. This has now
    been achieved for constant arrays, as we know the array sizes for them and hence we can
    precisely locate where each jacobian entry for a array parameter is located. This is
    achieved with the help of m_IndependentVarsSize, which stores the number of actual parameters
    that each function parameter corresponds to.
    
    Prior to this commit a std::map<ValueDecl, Expr> was used to map variable declarations to
    their corresponding jacobian expression, so that we can lookup the latter during the reversemode
    computations quickly. While this is fine for primitive variables(because each variable will only
    correspond to one jacobian expression), an array declaration will correspond to multiple jacobian
    expressions, depending on which index of the array is being referred to. Since the ValueDecl can
    only refer to the name of the array and not name+index, we must update the map to use the name of
    the array + index as the key. This can be done easily by using a string representation of the
    ValueDecl name with the index as a suffix as the key of the map. Hence variables like
    m_ExprVariables, m_VectorOutputString have been introduced to map array declarations, indexed by
    position in array to their corresponding jacobian expressions.
    
    Closes vgvassilev#472
    Nirhar committed Aug 12, 2022
    Configuration menu
    Copy the full SHA
    b8d0fb6 View commit details
    Browse the repository at this point in the history