-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #472
- Loading branch information
Showing
3 changed files
with
252 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters