-
Notifications
You must be signed in to change notification settings - Fork 125
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
Incorrect derivative produced when array is passed to call expression inside a loop #441
Comments
This issue #441 seems very similar to issue #465. It appears that the variables _t2 and _t5 are being generated by the VisitArraySubscriptExpr() function in ReverseModeVisitor.cpp. However, currently, these two variables are not being added to the block label0. Even if we enter the if(dfdx()) block in VisitArraySubscriptExpr(), _t2 and _t5 are generated after modify_pullback() is called, as shown below:
To resolve this issue, we need to add _t2 and _t5 to the block label0 before calling modify_pullback(). |
@vaithak, do you think you can take a look and propose a fix for this? |
In my PR:
All the solutions match for my proposed solution, but GitHub is giving an error for the function fn4 in FunctionCalls.c, specifically. double fn4(double* arr, int n) { fn4_grad created by my PR:- The code is: Old programs solution :- The code is: |
@ShounakDas101, I have looked at the PR and it still fails in some tests. The fix you proposed there seems more like a workaround rather than an actual solution. Maybe @parth-07 can correct me if I am wrong but we need "just" to declare the variable before its first use. |
@parth-07 , I have run FunctionCalls.c locally, and all the results have matched. As far as I have tested, the variables are declared before their first use. In the codecov report, I could only see one error, but it actually gives the correct result in the end. This is true for all the test cases in FunctionCalls.c. If you can provide me with the functions that are causing errors, it will help me in resolving the issue. |
Fixes vgvassilev#465, vgvassilev#441, vgvassilev#439. Partially resolves vgvassilev#429 and vgvassilev#606.
This patch request optimizes storing and restoring in the reverse mode of Clad and introduces TBR analysis to determine when variables should be stored. Fixes vgvassilev#465, vgvassilev#441, vgvassilev#439. Partially resolves vgvassilev#429 and vgvassilev#606.
This patch optimizes storing and restoring in the reverse mode of Clad and introduces TBR analysis to determine when variables should be stored. Fixes vgvassilev#465, vgvassilev#441, vgvassilev#439. Partially resolves vgvassilev#429 and vgvassilev#606.
This patch optimizes storing and restoring in the reverse mode of Clad and introduces TBR analysis to determine when variables should be stored. Fixes vgvassilev#465, vgvassilev#441, vgvassilev#439, vgvassilev#429. Partially resolves vgvassilev#606.
This patch optimizes storing and restoring in the reverse mode of Clad and introduces TBR analysis to determine when variables should be stored. Fixes vgvassilev#465, vgvassilev#441, vgvassilev#439, vgvassilev#429. Partially resolves vgvassilev#606.
This patch optimizes storing and restoring in the reverse mode of Clad and introduces TBR analysis to determine when variables should be stored. Fixes vgvassilev#465, vgvassilev#441, vgvassilev#439, vgvassilev#429. Partially resolves vgvassilev#606.
Fixed in #655 |
Minimal reproducible example:
Expected output: d_i: 5
Actual output: d_i: 1
Derived functions generated by Clad:
Root cause of the error
Please consider the line marked as an interesting line in the above code snippet. Derivative of
arr[idx]
as returned byVisit(...)
is the expression:_d_arr[_t2]
. But_t2
is not declared or initialised anywhere in the program.The text was updated successfully, but these errors were encountered: