-
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
Fixes incorrect derivative produced when array is passed to call expression inside a loop #560
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1260,6 +1260,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |
/*DirectInit=*/true); | ||
if (dfdx()) | ||
addToCurrentBlock(BuildDeclStmt(popVal), direction::reverse); | ||
else if(Ref) | ||
m_RPopIdxValues.push_back(BuildDeclStmt(popVal)); | ||
else | ||
m_PopIdxValues.push_back(BuildDeclStmt(popVal)); | ||
IdxStored = StmtDiff(IdxStored.getExpr(), BuildDeclRef(popVal)); | ||
|
@@ -1372,6 +1374,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |
|
||
StmtDiff ReverseModeVisitor::VisitCallExpr(const CallExpr* CE) { | ||
const FunctionDecl* FD = CE->getDirectCallee(); | ||
Ref=printArgTypes(CE);//finds if reference passed as argument | ||
if (!FD) { | ||
diag(DiagnosticsEngine::Warning, | ||
CE->getEndLoc(), | ||
|
@@ -1547,10 +1550,15 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |
block.insert(block.begin() + insertionPoint, | ||
BuildDeclStmt(argDiffLocalVD)); | ||
Expr* argDiffLocalE = BuildDeclRef(argDiffLocalVD); | ||
|
||
int Numref=0; | ||
while(!m_RPopIdxValues.empty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @parth-07 It keeps the DeclStmt of the variables which were being generated because of having a Reference Variable in the argument list but were not being added to the derived function. These variables were being generated in VisitArraySubscriptExpr() |
||
{ | ||
Numref++; | ||
block.insert(block.begin() + insertionPoint,m_RPopIdxValues.pop_back_val()); | ||
} | ||
// We added local variable to store result of `clad::pop(...)`. Thus | ||
// we need to correspondingly adjust the insertion point. | ||
insertionPoint += 1; | ||
insertionPoint = insertionPoint+1+Numref; | ||
// We cannot use the already existing `argDiff.getExpr()` here because | ||
// it will cause inconsistent pushes and pops to the clad tape. | ||
// FIXME: Modify `GlobalStoreAndRef` such that its functioning is | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this function called
printArgTypes
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a prototype function which did print the argument types. I had done this on last day of GSoC application so it is a complete mess and forgot to change the name. This part can be shifted to CladUtils. This function can be simplified a lot. All it is trying to find if there is any ReferenceType. I am very sorry for this.