-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5e410c
commit 0b10c47
Showing
4 changed files
with
23 additions
and
21 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
int square(int x) { | ||
double square(double x) { | ||
return x * x; | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#pragma once | ||
int square(int x); | ||
double square(double x); |
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 |
---|---|---|
@@ -1,23 +1,20 @@ | ||
#include <iostream> | ||
#include <limits> | ||
#include "library.hpp" | ||
|
||
int __enzyme_autodiff(int (*)(int), ...); | ||
double __enzyme_autodiff(double (*)(double), ...); | ||
|
||
int main() { | ||
int fail = 0; | ||
int sq = square(5); | ||
int dersq = __enzyme_autodiff(square, 5); | ||
double sq = square(5.0); | ||
double dsq = __enzyme_autodiff(square, 5.0); | ||
|
||
std::cout << "x = 5, x^2 = " << sq << ", d(x^2)/dx = " << dersq << "\n"; | ||
if (__enzyme_autodiff(square, 5) != 10) | ||
std::cout << "x = 5, x^2 = " << sq << ", d(x^2)/dx = " << dsq << "\n"; | ||
if (std::abs(dsq - 10.0) > std::numeric_limits<double>::epsilon()) | ||
{ | ||
--fail; | ||
// std::cout << "Incorrect result\n"; | ||
fail++; | ||
std::cout << "Result incorrect\n"; | ||
} | ||
if(fail < 0) | ||
std::cout << "Result incorrect\n\n"; | ||
else | ||
std::cout << "Bingo!!\n\n"; | ||
std:: cout << fail << "\n"; | ||
std::cout << "Status: " << fail << "\n"; | ||
return fail; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
#include <iostream> | ||
#include <limits> | ||
|
||
int square(int x) { | ||
double square(double x) { | ||
return x * x; | ||
} | ||
|
||
int __enzyme_autodiff(int(*)(int), ...); | ||
int dsquare(int x) { | ||
double __enzyme_autodiff(double(*)(double), ...); | ||
double dsquare(double x) { | ||
return __enzyme_autodiff(square, x); | ||
} | ||
|
||
int sq = square(5); | ||
int dsq = dsquare(5); | ||
double sq = square(5.0); | ||
double dsq = dsquare(5.0); | ||
|
||
int main() | ||
{ | ||
int fail = 0; | ||
std::cout << "x = 5, x^2 = " << sq << ", d(x^2)/dx = " << __enzyme_autodiff(square, 5) << "\n"; | ||
if (dsq != 10) | ||
std::cout << "x = 5, x^2 = " << sq << ", d(x^2)/dx = " << dsq << "\n"; | ||
if (std::abs(dsq - 10.0) > std::numeric_limits<double>::epsilon()) | ||
{ | ||
fail++; | ||
std::cout << "Result incorrect\n"; | ||
} | ||
std::cout << "Status: " << fail << "\n"; | ||
return fail; | ||
} |