Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix for const parameters #632

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Differentiator/CladUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ namespace clad {
else if (T->isArrayType())
valueType =
T->getPointeeOrArrayElementType()->getCanonicalTypeInternal();
valueType.removeLocalConst();
return valueType;
}

Expand Down
12 changes: 6 additions & 6 deletions test/Arrays/ArrayInputsForwardMode.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@

#include "clad/Differentiator/Differentiator.h"

double multiply(double *arr) {
double multiply(const double *arr) {
return arr[0] * arr[1];
}

//CHECK: double multiply_darg0_1(double *arr) {
//CHECK: double multiply_darg0_1(const double *arr) {
//CHECK-NEXT: return 0. * arr[1] + arr[0] * 1.;
//CHECK-NEXT: }

double divide(double *arr) {
double divide(const double *arr) {
return arr[0] / arr[1];
}

//CHECK: double divide_darg0_1(double *arr) {
//CHECK: double divide_darg0_1(const double *arr) {
//CHECK-NEXT: return (0. * arr[1] - arr[0] * 1.) / (arr[1] * arr[1]);
//CHECK-NEXT: }

double addArr(double *arr, int n) {
double addArr(const double *arr, int n) {
double ret = 0;
for (int i = 0; i < n; i++) {
ret += arr[i];
}
return ret;
}

//CHECK: double addArr_darg0_1(double *arr, int n) {
//CHECK: double addArr_darg0_1(const double *arr, int n) {
//CHECK-NEXT: int _d_n = 0;
//CHECK-NEXT: double _d_ret = 0;
//CHECK-NEXT: double ret = 0;
Expand Down
4 changes: 2 additions & 2 deletions test/Arrays/ArrayInputsReverseMode.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

#include "clad/Differentiator/Differentiator.h"

double addArr(double *arr, int n) {
double addArr(const double *arr, int n) {
double ret = 0;
for (int i = 0; i < n; i++) {
ret += arr[i];
}
return ret;
}

//CHECK: void addArr_pullback(double *arr, int n, double _d_y, clad::array_ref<double> _d_arr, clad::array_ref<int> _d_n) {
//CHECK: void addArr_pullback(const double *arr, int n, double _d_y, clad::array_ref<double> _d_arr, clad::array_ref<int> _d_n) {
//CHECK-NEXT: double _d_ret = 0;
//CHECK-NEXT: unsigned long _t0;
//CHECK-NEXT: int _d_i = 0;
Expand Down
12 changes: 6 additions & 6 deletions test/Arrays/ArrayInputsVectorForwardMode.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

#include "clad/Differentiator/Differentiator.h"

double multiply(double *arr) {
double multiply(const double *arr) {
return arr[0] * arr[1];
}

// CHECK: void multiply_dvec(double *arr, clad::array_ref<double> _d_arr) {
// CHECK: void multiply_dvec(const double *arr, clad::array_ref<double> _d_arr) {
// CHECK-NEXT: unsigned long indepVarCount = _d_arr.size();
// CHECK-NEXT: clad::matrix<double> _d_vector_arr = clad::identity_matrix(_d_arr.size(), indepVarCount, 0UL);
// CHECK-NEXT: {
Expand All @@ -33,15 +33,15 @@ double divide(double *arr) {
// CHECK-NEXT: }
// CHECK-NEXT: }

double addArr(double *arr, int n) {
double addArr(const double *arr, int n) {
double ret = 0;
for (int i = 0; i < n; i++) {
ret += arr[i];
}
return ret;
}

// CHECK: void addArr_dvec_0(double *arr, int n, clad::array_ref<double> _d_arr) {
// CHECK: void addArr_dvec_0(const double *arr, int n, clad::array_ref<double> _d_arr) {
// CHECK-NEXT: unsigned long indepVarCount = _d_arr.size();
// CHECK-NEXT: clad::matrix<double> _d_vector_arr = clad::identity_matrix(_d_arr.size(), indepVarCount, 0UL);
// CHECK-NEXT: clad::array<int> _d_vector_n = clad::zero_vector(indepVarCount);
Expand All @@ -61,7 +61,7 @@ double addArr(double *arr, int n) {
// CHECK-NEXT: }
// CHECK-NEXT: }

double maskedSum(double *arr, int n, int *signedMask, double alpha, double beta) {
double maskedSum(const double *arr, int n, int *signedMask, double alpha, double beta) {
double ret = 0;
for (int i = 0; i < n; i++) {
if (signedMask[i] > 0) {
Expand All @@ -73,7 +73,7 @@ double maskedSum(double *arr, int n, int *signedMask, double alpha, double beta)
return ret;
}

// CHECK: void maskedSum_dvec_0_3_4(double *arr, int n, int *signedMask, double alpha, double beta, clad::array_ref<double> _d_arr, double *_d_alpha, double *_d_beta) {
// CHECK: void maskedSum_dvec_0_3_4(const double *arr, int n, int *signedMask, double alpha, double beta, clad::array_ref<double> _d_arr, double *_d_alpha, double *_d_beta) {
// CHECK-NEXT: unsigned long indepVarCount = _d_arr.size() + 2UL;
// CHECK-NEXT: clad::matrix<double> _d_vector_arr = clad::identity_matrix(_d_arr.size(), indepVarCount, 0UL);
// CHECK-NEXT: clad::array<int> _d_vector_n = clad::zero_vector(indepVarCount);
Expand Down
Loading