Skip to content

Commit

Permalink
Fix ambiguity in indexing for array_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
vaithak committed Feb 3, 2024
1 parent ed8422c commit 7fb5326
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 14 deletions.
6 changes: 2 additions & 4 deletions include/clad/Differentiator/ArrayRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ template <typename T> class array_ref {

/// Operator for conversion from array_ref<T> to T*.
CUDA_HOST_DEVICE operator T*() { return m_arr; }
/// Operator for conversion from array_ref<T> to const T*.
CUDA_HOST_DEVICE operator const T*() const { return m_arr; }

template <typename U>
CUDA_HOST_DEVICE array_ref<T>& operator=(const array<U>& a) {
Expand All @@ -61,10 +63,6 @@ template <typename T> class array_ref {
"inside the array size.");
return array_ref<T>(&m_arr[offset], size);
}
/// Returns the reference to the location at the index of the underlying
/// array
CUDA_HOST_DEVICE T& operator[](std::size_t i) { return m_arr[i]; }
CUDA_HOST_DEVICE const T& operator[](std::size_t i) const { return m_arr[i]; }
/// Returns the reference to the underlying array
CUDA_HOST_DEVICE T& operator*() { return *m_arr; }

Expand Down
3 changes: 0 additions & 3 deletions test/Arrays/ArrayInputsReverseMode.C
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ float func(float* a, float* b) {
//CHECK-NEXT: _d_a[i] -= _r_d0;
//CHECK-NEXT: _d_a[i] += _r_d0 * b[i];
//CHECK-NEXT: _d_b[i] += a[i] * _r_d0;
//CHECK-NEXT: _d_a[i];
//CHECK-NEXT: }
//CHECK-NEXT: }
//CHECK-NEXT: }
Expand Down Expand Up @@ -440,7 +439,6 @@ double func8(double i, double *arr, int n) {
//CHECK-NEXT: arr[0] = _t3;
//CHECK-NEXT: double _r_d2 = _d_arr[0];
//CHECK-NEXT: _d_arr[0] -= _r_d2;
//CHECK-NEXT: _d_arr[0];
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: res = _t1;
Expand All @@ -460,7 +458,6 @@ double func8(double i, double *arr, int n) {
//CHECK-NEXT: arr[0] = _t0;
//CHECK-NEXT: double _r_d0 = _d_arr[0];
//CHECK-NEXT: _d_arr[0] -= _r_d0;
//CHECK-NEXT: _d_arr[0];
//CHECK-NEXT: }
//CHECK-NEXT: }

Expand Down
4 changes: 0 additions & 4 deletions test/ErrorEstimation/LoopsAndArrays.C
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ float func4(float x[10], float y[10]) {
//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: _delta_sum += std::abs(_d_sum * _EERepl_sum0 * {{.+}});
Expand Down Expand Up @@ -307,7 +306,6 @@ double func5(double* x, double* y, double* output) {
//CHECK-NEXT: _d_x[1] += y[0] * -_r_d2;
//CHECK-NEXT: _delta_output[2] += std::abs(_r_d2 * _EERepl_output3 * {{.+}});
//CHECK-NEXT: _final_error += _delta_output[2];
//CHECK-NEXT: _d_output[2];
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: output[1] = _t1;
Expand All @@ -319,7 +317,6 @@ double func5(double* x, double* y, double* output) {
//CHECK-NEXT: _d_y[2] += x[0] * -_r_d1;
//CHECK-NEXT: _delta_output[1] += std::abs(_r_d1 * _EERepl_output2 * {{.+}});
//CHECK-NEXT: _final_error += _delta_output[1];
//CHECK-NEXT: _d_output[1];
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: output[0] = _t0;
Expand All @@ -331,7 +328,6 @@ double func5(double* x, double* y, double* output) {
//CHECK-NEXT: _d_y[1] += x[2] * -_r_d0;
//CHECK-NEXT: _delta_output[0] += std::abs(_r_d0 * _EERepl_output1 * {{.+}});
//CHECK-NEXT: _final_error += _delta_output[0];
//CHECK-NEXT: _d_output[0];
//CHECK-NEXT: }
//CHECK-NEXT: clad::array<double> _delta_x(_d_x.size());
//CHECK-NEXT: int i = 0;
Expand Down
2 changes: 0 additions & 2 deletions test/Gradient/FunctionCalls.C
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ float sum(double* arr, int n) {
// CHECK-NEXT: arr[0] = _t2;
// CHECK-NEXT: double _r_d1 = _d_arr[0];
// CHECK-NEXT: _d_arr[0] += 10 * _r_d1;
// CHECK-NEXT: _d_arr[0];
// CHECK-NEXT: }
// CHECK-NEXT: for (; _t0; _t0--) {
// CHECK-NEXT: --i;
Expand Down Expand Up @@ -328,7 +327,6 @@ double modify2(double* arr) {
// CHECK-NEXT: _d_arr[0] -= _r_d0;
// CHECK-NEXT: _d_arr[0] += 5 * _r_d0;
// CHECK-NEXT: _d_arr[1] += _r_d0;
// CHECK-NEXT: _d_arr[0];
// CHECK-NEXT: }
// CHECK-NEXT: }

Expand Down
1 change: 0 additions & 1 deletion test/Gradient/Gradients.C
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ float running_sum(float* p, int n) {
// CHECK-NEXT: p[i] = clad::pop(_t1);
// CHECK-NEXT: float _r_d0 = _d_p[i];
// CHECK-NEXT: _d_p[i - 1] += _r_d0;
// CHECK-NEXT: _d_p[i];
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: }
Expand Down

0 comments on commit 7fb5326

Please sign in to comment.