From 7fb532694bf38446270be33b85e57d346f0936f3 Mon Sep 17 00:00:00 2001 From: Vaibhav Thakkar Date: Sat, 3 Feb 2024 13:47:44 +0100 Subject: [PATCH] Fix ambiguity in indexing for array_ref --- include/clad/Differentiator/ArrayRef.h | 6 ++---- test/Arrays/ArrayInputsReverseMode.C | 3 --- test/ErrorEstimation/LoopsAndArrays.C | 4 ---- test/Gradient/FunctionCalls.C | 2 -- test/Gradient/Gradients.C | 1 - 5 files changed, 2 insertions(+), 14 deletions(-) diff --git a/include/clad/Differentiator/ArrayRef.h b/include/clad/Differentiator/ArrayRef.h index 6fd89247d..90e3f992c 100644 --- a/include/clad/Differentiator/ArrayRef.h +++ b/include/clad/Differentiator/ArrayRef.h @@ -35,6 +35,8 @@ template class array_ref { /// Operator for conversion from array_ref to T*. CUDA_HOST_DEVICE operator T*() { return m_arr; } + /// Operator for conversion from array_ref to const T*. + CUDA_HOST_DEVICE operator const T*() const { return m_arr; } template CUDA_HOST_DEVICE array_ref& operator=(const array& a) { @@ -61,10 +63,6 @@ template class array_ref { "inside the array size."); return array_ref(&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; } diff --git a/test/Arrays/ArrayInputsReverseMode.C b/test/Arrays/ArrayInputsReverseMode.C index 0b09a11a0..2137a4fe7 100644 --- a/test/Arrays/ArrayInputsReverseMode.C +++ b/test/Arrays/ArrayInputsReverseMode.C @@ -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: } @@ -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; @@ -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: } diff --git a/test/ErrorEstimation/LoopsAndArrays.C b/test/ErrorEstimation/LoopsAndArrays.C index 8281ee0a0..ab033c3f6 100644 --- a/test/ErrorEstimation/LoopsAndArrays.C +++ b/test/ErrorEstimation/LoopsAndArrays.C @@ -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 * {{.+}}); @@ -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; @@ -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; @@ -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 _delta_x(_d_x.size()); //CHECK-NEXT: int i = 0; diff --git a/test/Gradient/FunctionCalls.C b/test/Gradient/FunctionCalls.C index 6fb9fc014..b15f2ab74 100644 --- a/test/Gradient/FunctionCalls.C +++ b/test/Gradient/FunctionCalls.C @@ -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; @@ -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: } diff --git a/test/Gradient/Gradients.C b/test/Gradient/Gradients.C index 32d1028b4..fb215d31f 100644 --- a/test/Gradient/Gradients.C +++ b/test/Gradient/Gradients.C @@ -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: }