-
Notifications
You must be signed in to change notification settings - Fork 121
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 differentiating functors in forward mode #240
Merged
vgvassilev
merged 20 commits into
vgvassilev:master
from
parth-07:differentiate-functors
Jul 8, 2021
Merged
Add support for differentiating functors in forward mode #240
vgvassilev
merged 20 commits into
vgvassilev:master
from
parth-07:differentiate-functors
Jul 8, 2021
Conversation
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
parth-07
force-pushed
the
differentiate-functors
branch
5 times, most recently
from
June 11, 2021 07:58
c7cd2b3
to
768b0c2
Compare
Codecov Report
@@ Coverage Diff @@
## master #240 +/- ##
==========================================
+ Coverage 84.39% 85.02% +0.63%
==========================================
Files 21 21
Lines 2736 2832 +96
==========================================
+ Hits 2309 2408 +99
+ Misses 427 424 -3
|
parth-07
force-pushed
the
differentiate-functors
branch
2 times, most recently
from
June 13, 2021 15:25
f2d51ff
to
e3be8fd
Compare
parth-07
force-pushed
the
differentiate-functors
branch
from
June 26, 2021 00:36
e400e09
to
6cd1472
Compare
parth-07
force-pushed
the
differentiate-functors
branch
from
June 26, 2021 00:46
6cd1472
to
54f04df
Compare
parth-07
force-pushed
the
differentiate-functors
branch
3 times, most recently
from
June 30, 2021 04:05
45fe756
to
98108ef
Compare
parth-07
force-pushed
the
differentiate-functors
branch
from
June 30, 2021 04:08
98108ef
to
e7f78ae
Compare
vgvassilev
reviewed
Jun 30, 2021
parth-07
force-pushed
the
differentiate-functors
branch
from
June 30, 2021 08:52
7ee7ce3
to
94d5e64
Compare
vgvassilev
reviewed
Jul 2, 2021
vgvassilev
reviewed
Jul 2, 2021
parth-07
force-pushed
the
differentiate-functors
branch
from
July 4, 2021 16:15
b843d5e
to
4dde5ff
Compare
vgvassilev
reviewed
Jul 5, 2021
- Use `Sema::LookupQualifiefName` instead of `DeclContext::lookup` - Use diagnostics from Sema which checks for visibility
vgvassilev
approved these changes
Jul 8, 2021
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.
Well done! LGTM!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to add support for differentiating functors in the forward differentiation mode.
operator()
member function when functor is passedCladFunction
Sema
diagnostics when an object of class without overloadedoperator()
or multiple overloads of call operator is passed to be differentiated.By differentiating functors, I mean, differentiating the
operator()
member function when a functor is passed, and implicitly executing the derived function using the passed functor.Functors can be passed to
clad::differentiate
both by reference and as pointers. For example:Implemented solution
The solution is implemented in 2 steps:
operator()
member function whenever functor (class type object) is passed to be differentiated.1st Step Implementation:
DiffPlanner
getArgFunction
is responsible for obtaining function to be differentiated from the call expression of clad differentiation functions.It currently behaves as follows:
DeclRefExpr
node of the 1st argument (which is, the function to be differentiated), and update theRelevantAncestor
parameter to the nearest ancestor of 1st argument which is of typeImplicitCastExpr
orUnaryOperator
.getArgFunction
has been modified such that, whenever a class type object is to be differentiated, it provides all the data for theoperator()
member function of the class type. By all the data, I am referring toDeclRefExpr
of theoperator()
method, the correct nearest ancestor for theoperator()
method.But since the
operator()
method hasn't actually passed, these nodes (DeclRefExpr
and ancestors of theoperator()
method) does not actually exist, and needs to be created insidegetArgFunction
. This effectively converts calls to differentiate class type object to calls to differentiate a member function for the rest of the clad.2nd Step Implementation:
CladFunction
has been modified to save an object through which derived member functions should be called when the user does not explicitly pass an object while callingCladFunction::execute
This behaviour is summarised in the following code snippet:
When a functor object is passed to be differentiated, it is saved in the corresponding
CladFunction
object so that it can be automatically taken by theCladFunction::execute
method to call the derived member function.Modifications to
clad::differentiate
clad::differentiate
is modified to have 2 overloads, one for differentiating functions (and methods), and the other for differentiating functors.2 separate overloads are required because function (and method) pointers need to be passed by value whereas objects need to be passed by reference (because we need to determine
constness
property (among others) of passed functor object)