Skip to content

Commit

Permalink
Fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Andriychuk authored and Max Andriychuk committed Sep 6, 2024
1 parent 9e543e5 commit 229a8a7
Show file tree
Hide file tree
Showing 8 changed files with 507 additions and 297 deletions.
17 changes: 8 additions & 9 deletions test/Analyses/ActivityReverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ double f1(double x){
}

//CHECK: void f1_grad(double x, double *_d_x) {
//CHECK-NEXT: double _d_a = 0;
//CHECK-NEXT: double _d_a = 0.;
//CHECK-NEXT: double a = x * x;
//CHECK-NEXT: double _d_b = 0;
//CHECK-NEXT: double b = 1;
//CHECK-NEXT: double _t0 = b;
//CHECK-NEXT: b = b * b;
//CHECK-NEXT: _d_a += 1;
//CHECK-NEXT: b = _t0;
//CHECK-NEXT: {
//CHECK-NEXT: *_d_x += _d_a * x;
//CHECK-NEXT: *_d_x += x * _d_a;
Expand All @@ -45,14 +45,13 @@ double f2(double x){
//CHECK-NEXT: bool _cond0;
//CHECK-NEXT: double _t0;
//CHECK-NEXT: bool _cond1;
//CHECK-NEXT: double _d_d = 0;
//CHECK-NEXT: double d = 0;
//CHECK-NEXT: double d = 0.;
//CHECK-NEXT: double _t1;
//CHECK-NEXT: double _d_a = 0;
//CHECK-NEXT: double _d_a = 0.;
//CHECK-NEXT: double a = x * x;
//CHECK-NEXT: double _d_b = 0;
//CHECK-NEXT: double _d_b = 0.;
//CHECK-NEXT: double b = 1;
//CHECK-NEXT: double _d_g = 0;
//CHECK-NEXT: double _d_g = 0.;
//CHECK-NEXT: double g;
//CHECK-NEXT: {
//CHECK-NEXT: _cond0 = a;
Expand All @@ -73,12 +72,12 @@ double f2(double x){
//CHECK-NEXT: if (_cond0) {
//CHECK-NEXT: b = _t0;
//CHECK-NEXT: double _r_d0 = _d_b;
//CHECK-NEXT: _d_b = 0;
//CHECK-NEXT: _d_b = 0.;
//CHECK-NEXT: *_d_x += _r_d0;
//CHECK-NEXT: } else if (!_cond1) {
//CHECK-NEXT: g = _t1;
//CHECK-NEXT: double _r_d1 = _d_g;
//CHECK-NEXT: _d_g = 0;
//CHECK-NEXT: _d_g = 0.;
//CHECK-NEXT: _d_a += _r_d1;
//CHECK-NEXT: }
//CHECK-NEXT: {
Expand Down
30 changes: 20 additions & 10 deletions test/Jacobian/FunctionCalls.C
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,34 @@ void fn1(double i, double j, double* output) {
}

// CHECK: void fn1_jac(double i, double j, double *output, double *jacobianMatrix) {
// CHECK-NEXT: double _t0 = output[0];
// CHECK-NEXT: output[0] = std::pow(i, j);
// CHECK-NEXT: double _t1 = output[1];
// CHECK-NEXT: output[1] = std::pow(j, i);
// CHECK-NEXT: {
// CHECK-NEXT: double _r2 = 0.;
// CHECK-NEXT: double _r3 = 0.;
// CHECK-NEXT: clad::custom_derivatives::pow_pullback(j, i, 1, &_r2, &_r3);
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _r2;
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += _r3;
// CHECK-NEXT: {
// CHECK-NEXT: double _r2 = 0.;
// CHECK-NEXT: double _r3 = 0.;
// CHECK-NEXT: clad::custom_derivatives::pow_pullback(j, i, 1, &_r2, &_r3);
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _r2;
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += _r3;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: double _r0 = 0.;
// CHECK-NEXT: double _r1 = 0.;
// CHECK-NEXT: clad::custom_derivatives::pow_pullback(i, j, 1, &_r0, &_r1);
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += _r0;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += _r1;
// CHECK-NEXT: {
// CHECK-NEXT: double _r0 = 0.;
// CHECK-NEXT: double _r1 = 0.;
// CHECK-NEXT: clad::custom_derivatives::pow_pullback(i, j, 1, &_r0, &_r1);
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += _r0;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += _r1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t0;
// CHECK-NEXT: }
// CHECK-NEXT: }



#define INIT(F) auto d_##F = clad::jacobian(F);

#define DERIVED_FN(F) d_##F
Expand Down
Loading

0 comments on commit 229a8a7

Please sign in to comment.