-
Notifications
You must be signed in to change notification settings - Fork 123
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
Cloning call to method via clad::utils::StmtClone::VisitCXXMemberCallExpr causes segmentation fault #49
Comments
It no longer causes segfault on master, now just a warning But segfault is reproducible with such revisions
output
|
@Nirhar, can you look into this issue, too? |
@vgvassilev Can you give me some resources to understand the usecase of this class clad/lib/Differentiator/ForwardModeVisitor.cpp Lines 1278 to 1282 in 6f98627
and then in clad/lib/Differentiator/VisitorBase.cpp Lines 284 to 288 in 6f98627
but I didnt quite understand the concept of ReferenceUpdater and why we are cloning portions of the code. Can you help me with this? |
It will be difficult to find resources for this. A good place to start would be understanding how the Reverse Mode AD mechanism works and trying to produce hand-written derivatives of simple functions by using the Reverse Mode AD. |
running this code below:
throws But however, if the function is made static, then this error is not thrown:
Code snippet 2 runs smoothly The derivative generated by code snippet 1 is
and the derivative generated by code snippet 2 is:
I think both the generated derivatives are correct I think the issue lies in how the CladFunction execute function handles the code and how these derivatives are supposed to be linked to the cladfunction object. Especially the m_Functor object is null, which is the reason why the assertion fails. As far as I understand the m_Functor object will not be null only if I use a class overloads its "()" operator. Therefore logically m_functor should be null. So i guess the wrong template is being instantiated for the execute statement. @vgvassilev @parth-07 can you correct me if I am wrong? |
I am not getting any error on running the code snippet 1, can you please paste the complete code that is giving you the error? |
The code:
works properly with the output:
While the below code:
compiles successfully but during runtime throws the below error:
If I dump the derivative generated during compilation of code snippet 1 to a file, the following derivative is generated:
|
In the code snippet shown below, //Complete version of code snippet 1 from the previous comment
#include "clad/Differentiator/Differentiator.h"
#include <iostream>
class S{
public:
int f1(int x) { return x; }
};
int main() {
auto f_dx = clad::differentiate(&S::f1, 0);
double x=3;
std::cout << f_dx.execute(x) << std::endl;
f_dx.dump();
} Therefore, S s;
std::cout << f_dx.execute(s, x) << std::endl; |
Can be reproduced by
The text was updated successfully, but these errors were encountered: