-
Notifications
You must be signed in to change notification settings - Fork 129
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 of variadic functions as call exprs in Forward mode #1246
Open
kchristin22
wants to merge
3
commits into
vgvassilev:master
Choose a base branch
from
kchristin22:variadic-functions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// RUN: %cladclang -std=c++17 %s -I%S/../../include -oVariadicCall.out 2>&1 | %filecheck %s | ||
// RUN: ./VariadicCall.out | %filecheck_exec %s | ||
|
||
#include "clad/Differentiator/Differentiator.h" | ||
|
||
// CHECK: warning: function 'printf' was not differentiated because clad failed to differentiate it and no suitable overload was found in namespace 'custom_derivatives' | ||
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. We should add |
||
// CHECK: note: fallback to numerical differentiation is disabled by the 'CLAD_NO_NUM_DIFF' macro; considering 'printf' as 0 | ||
|
||
template <typename... T> | ||
double fn1(double x, T... y) { | ||
return (x * ... * y); | ||
} | ||
|
||
double fn2(double x, double y) { | ||
printf("x is %f, y is %f\n", x, y); | ||
return fn1(x, y); | ||
} | ||
|
||
// CHECK: double fn2_darg0(double x, double y) { | ||
// CHECK-NEXT: double _d_x = 1; | ||
// CHECK-NEXT: double _d_y = 0; | ||
// CHECK-NEXT: printf("x is %f, y is %f\n", x, y); | ||
// CHECK-NEXT: clad::ValueAndPushforward<double, double> _t0 = fn1_pushforward(x, y, _d_x, _d_y); | ||
// CHECK-NEXT: return _t0.pushforward; | ||
// CHECK-NEXT: } | ||
|
||
double fn3(double x, double y) { | ||
return fn1(x, y, y); | ||
} | ||
|
||
// CHECK: double fn3_darg0(double x, double y) { | ||
// CHECK-NEXT: double _d_x = 1; | ||
// CHECK-NEXT: double _d_y = 0; | ||
// CHECK-NEXT: clad::ValueAndPushforward<double, double> _t0 = fn1_pushforward(x, y, y, _d_x, _d_y, _d_y); | ||
// CHECK-NEXT: return _t0.pushforward; | ||
// CHECK-NEXT: } | ||
|
||
int main() { | ||
auto d_fn2 = clad::differentiate(fn2, "x"); | ||
printf("{%.2f}\n", d_fn2.execute(1.0, 2.0)); // CHECK-EXEC: x is 1.000000, y is 2.000000 | ||
// CHECK-EXEC: {2.00} | ||
auto d_fn3 = clad::differentiate(fn3, "x"); | ||
printf("{%.2f}\n", d_fn3.execute(1.0, 2.0)); // CHECK-EXEC: {4.00} | ||
return 0; | ||
} | ||
|
||
// CHECK: clad::ValueAndPushforward<double, double> fn1_pushforward(double x, double y, double _d_x, double _d_y) { | ||
// CHECK-NEXT: return {x * y, _d_x * y + x * _d_y}; | ||
// CHECK-NEXT:} | ||
|
||
// CHECK: clad::ValueAndPushforward<double, double> fn1_pushforward(double x, double y, double y2, double _d_x, double _d_y, double _d_y2) { | ||
// CHECK-NEXT: double _t0 = x * y; | ||
// CHECK-NEXT: return {_t0 * y2, (_d_x * y + x * _d_y) * y2 + _t0 * _d_y2}; | ||
// CHECK-NEXT:} |
Oops, something went wrong.
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.
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.
warning: no header providing "std::size_t" is directly included [misc-include-cleaner]