Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Andriychuk authored and vgvassilev committed Sep 14, 2024
1 parent 4d8c423 commit 6ecc510
Show file tree
Hide file tree
Showing 7 changed files with 502 additions and 289 deletions.
29 changes: 19 additions & 10 deletions test/Jacobian/FunctionCalls.C
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,29 @@ 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: }

Expand Down Expand Up @@ -59,3 +67,4 @@ int main() {

test<2>(DERIVED_FN(fn1), 3, 5); // CHECK-EXEC: {405.00, 266.96, 201.18, 75.00}
}

219 changes: 145 additions & 74 deletions test/Jacobian/Functors.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@ struct Experiment {
}

// CHECK: void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) {
// CHECK-NEXT: double _t0 = output[0];
// CHECK-NEXT: output[0] = this->x * i * i * j;
// CHECK-NEXT: double _t1 = output[1];
// CHECK-NEXT: output[1] = this->y * i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * j * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += this->x * i * i * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += this->x * i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t0;
// CHECK-NEXT: }
// CHECK-NEXT: }

};

struct ExperimentConst {
Expand All @@ -44,19 +53,28 @@ struct ExperimentConst {
}

// CHECK: void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) const {
// CHECK-NEXT: double _t0 = output[0];
// CHECK-NEXT: output[0] = this->x * i * i * j;
// CHECK-NEXT: double _t1 = output[1];
// CHECK-NEXT: output[1] = this->y * i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * j * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += this->x * i * i * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += this->x * i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t0;
// CHECK-NEXT: }
// CHECK-NEXT: }

};

struct ExperimentVolatile {
Expand All @@ -72,20 +90,29 @@ struct ExperimentVolatile {

// CHECK: void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) volatile {
// CHECK-NEXT: double _t0 = this->x * i;
// CHECK-NEXT: double _t1 = output[0];
// CHECK-NEXT: output[0] = this->x * i * i * j;
// CHECK-NEXT: double _t1 = this->y * i;
// CHECK-NEXT: double _t2 = this->y * i;
// CHECK-NEXT: double _t3 = output[1];
// CHECK-NEXT: output[1] = this->y * i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _t1 * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _t1 * j * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _t2 * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _t2 * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t3;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += _t0 * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += _t0 * i * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += _t0 * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += _t0 * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: }

};

struct ExperimentConstVolatile {
Expand All @@ -101,20 +128,29 @@ struct ExperimentConstVolatile {

// CHECK: void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) const volatile {
// CHECK-NEXT: double _t0 = this->x * i;
// CHECK-NEXT: double _t1 = output[0];
// CHECK-NEXT: output[0] = this->x * i * i * j;
// CHECK-NEXT: double _t1 = this->y * i;
// CHECK-NEXT: double _t2 = this->y * i;
// CHECK-NEXT: double _t3 = output[1];
// CHECK-NEXT: output[1] = this->y * i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _t1 * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _t1 * j * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _t2 * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += _t2 * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t3;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += _t0 * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += _t0 * i * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += _t0 * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += _t0 * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: }

};

namespace outer {
Expand All @@ -130,41 +166,59 @@ namespace outer {
x = val;
}

// CHECK: void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) {
// CHECK-NEXT: output[0] = this->x * i * i * j;
// CHECK-NEXT: output[1] = this->y * i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += this->x * i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK: void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) {
// CHECK-NEXT: double _t0 = output[0];
// CHECK-NEXT: output[0] = this->x * i * i * j;
// CHECK-NEXT: double _t1 = output[1];
// CHECK-NEXT: output[1] = this->y * i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += this->y * 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += this->y * i * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += this->x * i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += this->x * i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t0;
// CHECK-NEXT: }
// CHECK-NEXT: }

};

auto lambdaNNS = [](double i, double j, double *output) {
output[0] = i*i*j;
output[1] = i*j*j;
};

// CHECK: inline void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) const {
// CHECK-NEXT: output[0] = i * i * j;
// CHECK-NEXT: output[1] = i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += i * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK: inline void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) const {
// CHECK-NEXT: double _t0 = output[0];
// CHECK-NEXT: output[0] = i * i * j;
// CHECK-NEXT: double _t1 = output[1];
// CHECK-NEXT: output[1] = i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += i * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t0;
// CHECK-NEXT: }
// CHECK-NEXT: }

}
}

Expand Down Expand Up @@ -201,17 +255,25 @@ int main() {
};

// CHECK: inline void operator_call_jac(double i, double j, double *output, double *jacobianMatrix) const {
// CHECK-NEXT: double _t0 = output[0];
// CHECK-NEXT: output[0] = i * i * j;
// CHECK-NEXT: double _t1 = output[1];
// CHECK-NEXT: output[1] = i * j * j;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += i * j * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += 1 * j * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += i * j * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += i * i * 1;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += 1 * j * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += i * 1 * j;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t0;
// CHECK-NEXT: }
// CHECK-NEXT: }

Expand All @@ -220,20 +282,28 @@ int main() {
output[1] = y*i*jj*jj;
};

// CHECK: inline void operator_call_jac(double i, double jj, double *output, double *jacobianMatrix) const {
// CHECK-NEXT: output[0] = x * i * i * jj;
// CHECK-NEXT: output[1] = y * i * jj * jj;
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += y * 1 * jj * jj;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += y * i * 1 * jj;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += y * i * jj * 1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += x * 1 * jj * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += x * i * 1 * jj;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += x * i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK: inline void operator_call_jac(double i, double jj, double *output, double *jacobianMatrix) const {
// CHECK-NEXT: double _t0 = output[0];
// CHECK-NEXT: output[0] = x * i * i * jj;
// CHECK-NEXT: double _t1 = output[1];
// CHECK-NEXT: output[1] = y * i * jj * jj;
// CHECK-NEXT: {
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{2U|2UL|2ULL}}] += y * 1 * jj * jj;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += y * i * 1 * jj;
// CHECK-NEXT: jacobianMatrix[{{3U|3UL|3ULL}}] += y * i * jj * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[1] = _t1;
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK-NEXT: {
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += x * 1 * jj * i;
// CHECK-NEXT: jacobianMatrix[{{0U|0UL|0ULL}}] += x * i * 1 * jj;
// CHECK-NEXT: jacobianMatrix[{{1U|1UL|1ULL}}] += x * i * i * 1;
// CHECK-NEXT: }
// CHECK-NEXT: output[0] = _t0;
// CHECK-NEXT: }
// CHECK-NEXT: }

auto lambdaNNS = outer::inner::lambdaNNS;

Expand Down Expand Up @@ -277,3 +347,4 @@ int main() {
TEST(E_NNS_Again); // CHECK-EXEC: {756.00, 294.00, 405.00, 630.00}, {756.00, 294.00, 405.00, 630.00}
TEST(lambdaWithCapture); // CHECK-EXEC: {756.00, 294.00, 405.00, 630.00}, {756.00, 294.00, 405.00, 630.00}
}

Loading

0 comments on commit 6ecc510

Please sign in to comment.