Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Jan 26, 2024
1 parent e4e71e4 commit 6da2b92
Show file tree
Hide file tree
Showing 13 changed files with 1,050 additions and 814 deletions.
359 changes: 207 additions & 152 deletions test/Arrays/ArrayInputsReverseMode.C

Large diffs are not rendered by default.

51 changes: 28 additions & 23 deletions test/CUDA/GradientCuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -28,64 +28,69 @@ __device__ __host__ double gauss(double* x, double* p, double sigma, int dim) {

auto gauss_g = clad::gradient(gauss, "p");

// CHECK: void gauss_grad_1(double *x, double *p, double sigma, int dim, clad::array_ref<double> _d_p) __attribute__((device)) __attribute__((host)) {
//CHECK: void gauss_grad_1(double *x, double *p, double sigma, int dim, clad::array_ref<double> _d_p) {
//CHECK-NEXT: double _d_sigma = 0;
//CHECK-NEXT: int _d_dim = 0;
//CHECK-NEXT: double _d_t = 0;
//CHECK-NEXT: unsigned long _t0;
//CHECK-NEXT: int _t1;
//CHECK-NEXT: int _d_i = 0;
//CHECK-NEXT: clad::tape<double> _t1 = {};
//CHECK-NEXT: double _t2;
//CHECK-NEXT: int i = 0;
//CHECK-NEXT: clad::tape<double> _t2 = {};
//CHECK-NEXT: double _t3;
//CHECK-NEXT: double _t4;
//CHECK-NEXT: double _t5;
//CHECK-NEXT: double _t6;
//CHECK-NEXT: double _t7;
//CHECK-NEXT: double t = 0;
//CHECK-NEXT: _t0 = 0;
//CHECK-NEXT: for (int i = 0; i < dim; i++) {
//CHECK-NEXT: for (_t1 = i , i = 0; i < dim; i++) {
//CHECK-NEXT: _t0++;
//CHECK-NEXT: clad::push(_t1, t);
//CHECK-NEXT: clad::push(_t2, t);
//CHECK-NEXT: t += (x[i] - p[i]) * (x[i] - p[i]);
//CHECK-NEXT: }
//CHECK-NEXT: _t2 = t;
//CHECK-NEXT: _t3 = (2 * sigma * sigma);
//CHECK-NEXT: t = -t / _t3;
//CHECK-NEXT: _t6 = std::pow(2 * 3.1415926535897931, -dim / 2.);
//CHECK-NEXT: _t5 = std::pow(sigma, -0.5);
//CHECK-NEXT: _t4 = std::exp(t);
//CHECK-NEXT: _t3 = t;
//CHECK-NEXT: _t4 = (2 * sigma * sigma);
//CHECK-NEXT: t = -t / _t4;
//CHECK-NEXT: _t7 = std::pow(2 * 3.1415926535897931, -dim / 2.);
//CHECK-NEXT: _t6 = std::pow(sigma, -0.5);
//CHECK-NEXT: _t5 = std::exp(t);
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: {
//CHECK-NEXT: double _grad0 = 0.;
//CHECK-NEXT: double _grad1 = 0.;
//CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(2 * 3.1415926535897931, -dim / 2., 1 * _t4 * _t5, &_grad0, &_grad1);
//CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(2 * 3.1415926535897931, -dim / 2., 1 * _t5 * _t6, &_grad0, &_grad1);
//CHECK-NEXT: double _r1 = _grad0;
//CHECK-NEXT: double _r2 = _grad1;
//CHECK-NEXT: _d_dim += -_r2 / 2.;
//CHECK-NEXT: double _grad2 = 0.;
//CHECK-NEXT: double _grad3 = 0.;
//CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(sigma, -0.5, _t6 * 1 * _t4, &_grad2, &_grad3);
//CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(sigma, -0.5, _t7 * 1 * _t5, &_grad2, &_grad3);
//CHECK-NEXT: double _r3 = _grad2;
//CHECK-NEXT: _d_sigma += _r3;
//CHECK-NEXT: double _r4 = _grad3;
//CHECK-NEXT: double _r5 = _t6 * _t5 * 1 * clad::custom_derivatives::exp_pushforward(t, 1.).pushforward;
//CHECK-NEXT: double _r5 = _t7 * _t6 * 1 * clad::custom_derivatives::exp_pushforward(t, 1.).pushforward;
//CHECK-NEXT: _d_t += _r5;
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: t = _t2;
//CHECK-NEXT: t = _t3;
//CHECK-NEXT: double _r_d1 = _d_t;
//CHECK-NEXT: _d_t -= _r_d1;
//CHECK-NEXT: _d_t += -_r_d1 / _t3;
//CHECK-NEXT: double _r0 = _r_d1 * --t / (_t3 * _t3);
//CHECK-NEXT: _d_t += -_r_d1 / _t4;
//CHECK-NEXT: double _r0 = _r_d1 * --t / (_t4 * _t4);
//CHECK-NEXT: _d_sigma += 2 * _r0 * sigma;
//CHECK-NEXT: _d_sigma += 2 * sigma * _r0;
//CHECK-NEXT: }
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: t = clad::pop(_t1);
//CHECK-NEXT: double _r_d0 = _d_t;
//CHECK-NEXT: _d_p[i] += -_r_d0 * (x[i] - p[i]);
//CHECK-NEXT: _d_p[i] += -(x[i] - p[i]) * _r_d0;
//CHECK-NEXT: {
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: t = clad::pop(_t2);
//CHECK-NEXT: double _r_d0 = _d_t;
//CHECK-NEXT: _d_p[i] += -_r_d0 * (x[i] - p[i]);
//CHECK-NEXT: _d_p[i] += -(x[i] - p[i]) * _r_d0;
//CHECK-NEXT: }
//CHECK-NEXT: i = _t1;
//CHECK-NEXT: }
//CHECK-NEXT: }

Expand Down
22 changes: 14 additions & 8 deletions test/ErrorEstimation/ConditonalStatements.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,27 @@ float func(float x, float y) {
//CHECK-NEXT: double _delta_y = 0;
//CHECK-NEXT: float _EERepl_y0 = y;
//CHECK-NEXT: float _EERepl_y1;
//CHECK-NEXT: float _t1;
//CHECK-NEXT: float _d_temp = 0;
//CHECK-NEXT: double _delta_temp = 0;
//CHECK-NEXT: float _EERepl_temp0;
//CHECK-NEXT: float _t1;
//CHECK-NEXT: float _EERepl_temp1;
//CHECK-NEXT: float temp = 0;
//CHECK-NEXT: float _t2;
//CHECK-NEXT: float _EERepl_temp1;
//CHECK-NEXT: float _t3;
//CHECK-NEXT: double _ret_value0 = 0;
//CHECK-NEXT: _cond0 = x > y;
//CHECK-NEXT: if (_cond0) {
//CHECK-NEXT: _t0 = y;
//CHECK-NEXT: y = y * x;
//CHECK-NEXT: _EERepl_y1 = y;
//CHECK-NEXT: } else {
//CHECK-NEXT: float temp = y;
//CHECK-NEXT: _t1 = temp , temp = y;
//CHECK-NEXT: _EERepl_temp0 = temp;
//CHECK-NEXT: _t1 = temp;
//CHECK-NEXT: _t2 = temp;
//CHECK-NEXT: temp = y * y;
//CHECK-NEXT: _EERepl_temp1 = temp;
//CHECK-NEXT: _t2 = x;
//CHECK-NEXT: _t3 = x;
//CHECK-NEXT: x = y;
//CHECK-NEXT: }
//CHECK-NEXT: _ret_value0 = x + y;
Expand All @@ -63,21 +65,25 @@ float func(float x, float y) {
//CHECK-NEXT: }
//CHECK-NEXT: } else {
//CHECK-NEXT: {
//CHECK-NEXT: x = _t2;
//CHECK-NEXT: x = _t3;
//CHECK-NEXT: float _r_d2 = * _d_x;
//CHECK-NEXT: * _d_x -= _r_d2;
//CHECK-NEXT: * _d_y += _r_d2;
//CHECK-NEXT: * _d_x;
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: temp = _t1;
//CHECK-NEXT: temp = _t2;
//CHECK-NEXT: float _r_d1 = _d_temp;
//CHECK-NEXT: _d_temp -= _r_d1;
//CHECK-NEXT: * _d_y += _r_d1 * y;
//CHECK-NEXT: * _d_y += y * _r_d1;
//CHECK-NEXT: _delta_temp += std::abs(_r_d1 * _EERepl_temp1 * {{.+}});
//CHECK-NEXT: }
//CHECK-NEXT: * _d_y += _d_temp;
//CHECK-NEXT: {
//CHECK-NEXT: * _d_y += _d_temp;
//CHECK-NEXT: temp = _t1;
//CHECK-NEXT: _delta_temp += std::abs(_d_temp * _EERepl_temp0 * {{.+}});
//CHECK-NEXT: }
//CHECK-NEXT: }
//CHECK-NEXT: double _delta_x = 0;
//CHECK-NEXT: _delta_x += std::abs(* _d_x * x * {{.+}});
Expand Down
157 changes: 86 additions & 71 deletions test/ErrorEstimation/LoopsAndArrays.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,43 @@ float func(float* p, int n) {
//CHECK-NEXT: double _delta_sum = 0;
//CHECK-NEXT: float _EERepl_sum0;
//CHECK-NEXT: unsigned long _t0;
//CHECK-NEXT: int _t1;
//CHECK-NEXT: int _d_i = 0;
//CHECK-NEXT: clad::tape<float> _t1 = {};
//CHECK-NEXT: int i = 0;
//CHECK-NEXT: clad::tape<float> _t2 = {};
//CHECK-NEXT: clad::tape<float> _EERepl_sum1 = {};
//CHECK-NEXT: float sum = 0;
//CHECK-NEXT: _EERepl_sum0 = sum;
//CHECK-NEXT: _t0 = 0;
//CHECK-NEXT: for (int i = 0; i < n; i++) {
//CHECK-NEXT: for (_t1 = i , i = 0; i < n; i++) {
//CHECK-NEXT: _t0++;
//CHECK-NEXT: clad::push(_t1, sum);
//CHECK-NEXT: clad::push(_t2, sum);
//CHECK-NEXT: sum += p[i];
//CHECK-NEXT: clad::push(_EERepl_sum1, sum);
//CHECK-NEXT: }
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: _d_sum += 1;
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: {
//CHECK-NEXT: sum = clad::pop(_t1);
//CHECK-NEXT: float _r_d0 = _d_sum;
//CHECK-NEXT: _d_p[i] += _r_d0;
//CHECK-NEXT: float _r0 = clad::pop(_EERepl_sum1);
//CHECK-NEXT: _delta_sum += std::abs(_r_d0 * _r0 * {{.+}});
//CHECK-NEXT: {
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: {
//CHECK-NEXT: sum = clad::pop(_t2);
//CHECK-NEXT: float _r_d0 = _d_sum;
//CHECK-NEXT: _d_p[i] += _r_d0;
//CHECK-NEXT: float _r0 = clad::pop(_EERepl_sum1);
//CHECK-NEXT: _delta_sum += std::abs(_r_d0 * _r0 * {{.+}});
//CHECK-NEXT: }
//CHECK-NEXT: }
//CHECK-NEXT: i = _t1;
//CHECK-NEXT: }
//CHECK-NEXT: _delta_sum += std::abs(_d_sum * _EERepl_sum0 * {{.+}});
//CHECK-NEXT: clad::array<float> _delta_p(_d_p.size());
//CHECK-NEXT: int i = 0;
//CHECK-NEXT: for (; i < _d_p.size(); i++) {
//CHECK-NEXT: double _t2 = std::abs(_d_p[i] * p[i] * {{.+}});
//CHECK-NEXT: _delta_p[i] += _t2;
//CHECK-NEXT: _final_error += _t2;
//CHECK-NEXT: int i0 = 0;
//CHECK-NEXT: for (; i0 < _d_p.size(); i0++) {
//CHECK-NEXT: double _t3 = std::abs(_d_p[i0] * p[i0] * {{.+}});
//CHECK-NEXT: _delta_p[i0] += _t3;
//CHECK-NEXT: _final_error += _t3;
//CHECK-NEXT: }
//CHECK-NEXT: _final_error += _delta_sum;
//CHECK-NEXT: }
Expand All @@ -70,47 +75,52 @@ float func2(float x) {
//CHECK-NEXT: double _delta_z = 0;
//CHECK-NEXT: float _EERepl_z0;
//CHECK-NEXT: unsigned long _t0;
//CHECK-NEXT: int _t1;
//CHECK-NEXT: int _d_i = 0;
//CHECK-NEXT: clad::tape<float> _t1 = {};
//CHECK-NEXT: int i = 0;
//CHECK-NEXT: clad::tape<float> _t2 = {};
//CHECK-NEXT: float _d_m = 0;
//CHECK-NEXT: double _delta_m = 0;
//CHECK-NEXT: clad::tape<float> _EERepl_m0 = {};
//CHECK-NEXT: float m = 0;
//CHECK-NEXT: clad::tape<float> _t2 = {};
//CHECK-NEXT: clad::tape<float> _t3 = {};
//CHECK-NEXT: clad::tape<float> _EERepl_z1 = {};
//CHECK-NEXT: float z;
//CHECK-NEXT: _EERepl_z0 = z;
//CHECK-NEXT: _t0 = 0;
//CHECK-NEXT: for (int i = 0; i < 9; i++) {
//CHECK-NEXT: for (_t1 = i , i = 0; i < 9; i++) {
//CHECK-NEXT: _t0++;
//CHECK-NEXT: clad::push(_t1, m) , m = x * x;
//CHECK-NEXT: clad::push(_t2, m) , m = x * x;
//CHECK-NEXT: clad::push(_EERepl_m0, m);
//CHECK-NEXT: clad::push(_t2, z);
//CHECK-NEXT: clad::push(_t3, z);
//CHECK-NEXT: z = m + m;
//CHECK-NEXT: clad::push(_EERepl_z1, z);
//CHECK-NEXT: }
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: _d_z += 1;
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: {
//CHECK-NEXT: z = clad::pop(_t2);
//CHECK-NEXT: float _r_d0 = _d_z;
//CHECK-NEXT: _d_z -= _r_d0;
//CHECK-NEXT: _d_m += _r_d0;
//CHECK-NEXT: _d_m += _r_d0;
//CHECK-NEXT: float _r1 = clad::pop(_EERepl_z1);
//CHECK-NEXT: _delta_z += std::abs(_r_d0 * _r1 * {{.+}});
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: * _d_x += _d_m * x;
//CHECK-NEXT: * _d_x += x * _d_m;
//CHECK-NEXT: _d_m = 0;
//CHECK-NEXT: m = clad::pop(_t1);
//CHECK-NEXT: float _r0 = clad::pop(_EERepl_m0);
//CHECK-NEXT: _delta_m += std::abs(_d_m * _r0 * {{.+}});
//CHECK-NEXT: {
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: {
//CHECK-NEXT: z = clad::pop(_t3);
//CHECK-NEXT: float _r_d0 = _d_z;
//CHECK-NEXT: _d_z -= _r_d0;
//CHECK-NEXT: _d_m += _r_d0;
//CHECK-NEXT: _d_m += _r_d0;
//CHECK-NEXT: float _r1 = clad::pop(_EERepl_z1);
//CHECK-NEXT: _delta_z += std::abs(_r_d0 * _r1 * {{.+}});
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: * _d_x += _d_m * x;
//CHECK-NEXT: * _d_x += x * _d_m;
//CHECK-NEXT: _d_m = 0;
//CHECK-NEXT: m = clad::pop(_t2);
//CHECK-NEXT: float _r0 = clad::pop(_EERepl_m0);
//CHECK-NEXT: _delta_m += std::abs(_d_m * _r0 * {{.+}});
//CHECK-NEXT: }
//CHECK-NEXT: }
//CHECK-NEXT: i = _t1;
//CHECK-NEXT: }
//CHECK-NEXT: double _delta_x = 0;
//CHECK-NEXT: _delta_x += std::abs(* _d_x * x * {{.+}});
Expand Down Expand Up @@ -198,63 +208,68 @@ float func4(float x[10], float y[10]) {
//CHECK-NEXT: double _delta_sum = 0;
//CHECK-NEXT: float _EERepl_sum0;
//CHECK-NEXT: unsigned long _t0;
//CHECK-NEXT: int _t1;
//CHECK-NEXT: int _d_i = 0;
//CHECK-NEXT: clad::tape<float> _t1 = {};
//CHECK-NEXT: int i = 0;
//CHECK-NEXT: clad::tape<float> _t2 = {};
//CHECK-NEXT: clad::array<float> _delta_x(_d_x.size());
//CHECK-NEXT: clad::array<float> _EERepl_x0(_d_x.size());
//CHECK-NEXT: for (int i0 = 0; i0 < _d_x.size(); i0++) {
//CHECK-NEXT: _EERepl_x0[i0] = x[i0];
//CHECK-NEXT: }
//CHECK-NEXT: clad::tape<float> _EERepl_x1 = {};
//CHECK-NEXT: clad::tape<float> _t2 = {};
//CHECK-NEXT: clad::tape<float> _t3 = {};
//CHECK-NEXT: clad::tape<float> _EERepl_sum1 = {};
//CHECK-NEXT: float sum = 0;
//CHECK-NEXT: _EERepl_sum0 = sum;
//CHECK-NEXT: _t0 = 0;
//CHECK-NEXT: for (int i = 0; i < 10; i++) {
//CHECK-NEXT: for (_t1 = i , i = 0; i < 10; i++) {
//CHECK-NEXT: _t0++;
//CHECK-NEXT: clad::push(_t1, x[i]);
//CHECK-NEXT: clad::push(_t2, x[i]);
//CHECK-NEXT: x[i] += y[i];
//CHECK-NEXT: clad::push(_EERepl_x1, x[i]);
//CHECK-NEXT: clad::push(_t2, sum);
//CHECK-NEXT: clad::push(_t3, sum);
//CHECK-NEXT: sum += x[i];
//CHECK-NEXT: clad::push(_EERepl_sum1, sum);
//CHECK-NEXT: }
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: _d_sum += 1;
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: {
//CHECK-NEXT: sum = clad::pop(_t2);
//CHECK-NEXT: float _r_d1 = _d_sum;
//CHECK-NEXT: _d_x[i] += _r_d1;
//CHECK-NEXT: float _r1 = clad::pop(_EERepl_sum1);
//CHECK-NEXT: _delta_sum += std::abs(_r_d1 * _r1 * {{.+}});
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: x[i] = clad::pop(_t1);
//CHECK-NEXT: float _r_d0 = _d_x[i];
//CHECK-NEXT: _d_y[i] += _r_d0;
//CHECK-NEXT: float _r0 = clad::pop(_EERepl_x1);
//CHECK-NEXT: _delta_x[i] += std::abs(_r_d0 * _r0 * {{.+}});
//CHECK-NEXT: _final_error += _delta_x[i];
//CHECK-NEXT: _d_x[i];
//CHECK-NEXT: {
//CHECK-NEXT: for (; _t0; _t0--) {
//CHECK-NEXT: i--;
//CHECK-NEXT: {
//CHECK-NEXT: sum = clad::pop(_t3);
//CHECK-NEXT: float _r_d1 = _d_sum;
//CHECK-NEXT: _d_x[i] += _r_d1;
//CHECK-NEXT: float _r1 = clad::pop(_EERepl_sum1);
//CHECK-NEXT: _delta_sum += std::abs(_r_d1 * _r1 * {{.+}});
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: x[i] = clad::pop(_t2);
//CHECK-NEXT: float _r_d0 = _d_x[i];
//CHECK-NEXT: _d_y[i] += _r_d0;
//CHECK-NEXT: float _r0 = clad::pop(_EERepl_x1);
//CHECK-NEXT: _delta_x[i] += std::abs(_r_d0 * _r0 * {{.+}});
//CHECK-NEXT: _final_error += _delta_x[i];
//CHECK-NEXT: _d_x[i];
//CHECK-NEXT: }
//CHECK-NEXT: }
//CHECK-NEXT: i = _t1;
//CHECK-NEXT: }
//CHECK-NEXT: _delta_sum += std::abs(_d_sum * _EERepl_sum0 * {{.+}});
//CHECK-NEXT: int i = 0;
//CHECK-NEXT: for (; i < _d_x.size(); i++) {
//CHECK-NEXT: double _t3 = std::abs(_d_x[i] * _EERepl_x0[i] * {{.+}});
//CHECK-NEXT: _delta_x[i] += _t3;
//CHECK-NEXT: _final_error += _t3;
//CHECK-NEXT: int i0 = 0;
//CHECK-NEXT: for (; i0 < _d_x.size(); i0++) {
//CHECK-NEXT: double _t4 = std::abs(_d_x[i0] * _EERepl_x0[i0] * {{.+}});
//CHECK-NEXT: _delta_x[i0] += _t4;
//CHECK-NEXT: _final_error += _t4;
//CHECK-NEXT: }
//CHECK-NEXT: clad::array<float> _delta_y(_d_y.size());
//CHECK-NEXT: i = 0;
//CHECK-NEXT: for (; i < _d_y.size(); i++) {
//CHECK-NEXT: double _t4 = std::abs(_d_y[i] * y[i] * {{.+}});
//CHECK-NEXT: _delta_y[i] += _t4;
//CHECK-NEXT: _final_error += _t4;
//CHECK-NEXT: i0 = 0;
//CHECK-NEXT: for (; i0 < _d_y.size(); i0++) {
//CHECK-NEXT: double _t5 = std::abs(_d_y[i0] * y[i0] * {{.+}});
//CHECK-NEXT: _delta_y[i0] += _t5;
//CHECK-NEXT: _final_error += _t5;
//CHECK-NEXT: }
//CHECK-NEXT: _final_error += _delta_sum;
//CHECK-NEXT: }
Expand Down
Loading

0 comments on commit 6da2b92

Please sign in to comment.