From c832c58729b84a783162048d840dde6d54608d22 Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Mon, 13 May 2024 08:42:11 +0200 Subject: [PATCH 1/5] Fix various typos in documentation --- ADOL-C/boost-test/traceOperatorScalar.cpp | 6 +++--- ADOL-C/src/tape_handling.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ADOL-C/boost-test/traceOperatorScalar.cpp b/ADOL-C/boost-test/traceOperatorScalar.cpp index 9f335336..0127bdb8 100644 --- a/ADOL-C/boost-test/traceOperatorScalar.cpp +++ b/ADOL-C/boost-test/traceOperatorScalar.cpp @@ -17,10 +17,10 @@ BOOST_AUTO_TEST_SUITE(trace_scalar) /* Naming convention for test cases: Operatorname_Operator_ZOS_Forward for * primal value (= zero order derivative), Operatorname_Operator_FOS_Forward - * for foward derivative evulation and Operatorname_Operator_FOS_Reverse for - * reverse mode derivative evalution. + * for forward derivative evaluation and Operatorname_Operator_FOS_Reverse for + * reverse mode derivative evaluation. * - * For documentation of concrete test implementation, check traceless scalar + * For documentation of a concrete test implementation, check the traceless scalar * mode test implementation. The testing order is consistent with that file * as well. */ diff --git a/ADOL-C/src/tape_handling.cpp b/ADOL-C/src/tape_handling.cpp index 5713e815..472140db 100644 --- a/ADOL-C/src/tape_handling.cpp +++ b/ADOL-C/src/tape_handling.cpp @@ -768,7 +768,7 @@ int removeTape(short tapeID, short type) { /****************************************************************************/ /* Initialization for the taping process. Creates buffers for this tape, */ -/* sets files names, and calls appropriate setup routines. */ +/* sets file names, and calls appropriate setup routines. */ /****************************************************************************/ int trace_on(short tnum, int keepTaylors) { int retval = 0; From 351333fcc89ddfcd826a77bdb9f6e4c068dd535b Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Mon, 25 Nov 2024 17:14:32 +0100 Subject: [PATCH 2/5] Remove a few unused variables --- ADOL-C/include/adolc/adtl_hov.h | 14 +++----------- ADOL-C/src/adalloc.c | 6 ++---- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/ADOL-C/include/adolc/adtl_hov.h b/ADOL-C/include/adolc/adtl_hov.h index 8db615b5..baeeee64 100644 --- a/ADOL-C/include/adolc/adtl_hov.h +++ b/ADOL-C/include/adolc/adtl_hov.h @@ -1225,7 +1225,7 @@ inline adouble pow(const adouble &a, double v) { // and u_k } } else { - int i, m; + int i; double sum1 = 0.0, sum2 = 0.0; for (int l = 0; l < adouble::numDir; l++) { for (int k = 0; k < adouble::degree; k++) { @@ -1364,10 +1364,8 @@ inline adouble sinh(const adouble &a) { { tmp2 = ADOLC_MATH_NSP::cosh(a.val); int i, m; - double sum; double sum1 = 0.0, sum2 = 0.0; for (int l = 0; l < adouble::numDir; l++) { - sum = 0.0; for (int k = 0; k < adouble::degree; k++) { // ho_deriv[k][l] m = k + 1; @@ -1409,11 +1407,9 @@ inline adouble cosh(const adouble &a) { if (do_hoval()) // ADTL_HOV { int i, m; - double sum; double sum1 = 0.0, sum2 = 0.0; tmp2 = ADOLC_MATH_NSP::sinh(a.val); for (int l = 0; l < adouble::numDir; l++) { - sum = 0.0; for (int k = 0; k < adouble::degree; k++) { // ho_deriv[k][l] m = k + 1; @@ -1580,8 +1576,6 @@ inline adouble fabs(const adouble &a) { // TODO: do not forget to check the function value. it is the zero-th taylor // coefficient - int i, m; - double sum; int *leading_sgn = (int *)alloca(sizeof(int) * adouble::degree); for (int l = 0; l < adouble::numDir; l++) // Init { @@ -2200,9 +2194,8 @@ inline adouble &adouble::operator*=(const adouble &a) { if (do_hoval()) // ADTL_HOV { - int i, m; + int i; double sum; - double sum1 = 0.0, sum2 = 0.0; for (int l = 0; l < adouble::numDir; l++) { for (int k = 0; k < degree; k++) { sum = val * a.ho_deriv[k][l] + ho_deriv[k][l] * a.val; @@ -2254,9 +2247,8 @@ inline adouble &adouble::operator/=(const adouble &a) { if (do_hoval()) // ADTL_HOV { adouble tmp; - int i, m; + int i; double sum; - double sum1 = 0.0, sum2 = 0.0; for (int l = 0; l < adouble::numDir; l++) { for (int k = 0; k < degree; k++) { sum = tmp.val * a.ho_deriv[k][l]; diff --git a/ADOL-C/src/adalloc.c b/ADOL-C/src/adalloc.c index 7cc4da27..7c0fc57b 100644 --- a/ADOL-C/src/adalloc.c +++ b/ADOL-C/src/adalloc.c @@ -39,7 +39,7 @@ char *populate_dpp(double ***const pointer, char *const memory, int n, int m) { char *tmp; double **tmp1; double *tmp2; - int i, j; + int i; tmp = (char *)memory; tmp1 = (double **)memory; *pointer = tmp1; @@ -86,7 +86,7 @@ char *populate_dppp_nodata(double ****const pointer, char *const memory, int n, char *tmp; double ***tmp1; double **tmp2; - int i, j; + int i; tmp = (char *)memory; tmp1 = (double ***)memory; *pointer = tmp1; @@ -117,7 +117,6 @@ double *myalloc1(size_t m) { double **myalloc2(size_t m, size_t n) { double **A = NULL; if (m > 0 && n > 0) { - int i; char *Adum = (char *)ADOLC_MALLOC( m * n * sizeof(double) + m * sizeof(double *), sizeof(char)); if (Adum == NULL) { @@ -136,7 +135,6 @@ myalloc3(size_t m, size_t n, size_t p) { /* This function allocates 3-tensors contiguously */ double ***A = NULL; if (m > 0 && n > 0 && p > 0) { - int i, j; char *Adum = (char *)ADOLC_MALLOC(m * n * p * sizeof(double) + m * n * sizeof(double *) + m * sizeof(double **), From 7a351c58905dec1d682414b36f74935b04c698d6 Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Mon, 25 Nov 2024 17:16:41 +0100 Subject: [PATCH 3/5] Replace one C array by std::vector --- ADOL-C/src/fixpoint.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ADOL-C/src/fixpoint.cpp b/ADOL-C/src/fixpoint.cpp index 07298fb7..7cd7ea15 100644 --- a/ADOL-C/src/fixpoint.cpp +++ b/ADOL-C/src/fixpoint.cpp @@ -213,13 +213,13 @@ fp_iteration(int sub_tape_num, fpi_stack.push_back(data); // put x and u together - adouble *xu = new adouble[dim_x + dim_u]; + std::vector xu(dim_x + dim_u); for (i = 0; i < dim_x; i++) xu[i] = x_0[i]; for (i = 0; i < dim_u; i++) xu[dim_x + i] = u[i]; - k = call_ext_fct(edf_iteration, dim_x + dim_u, xu, dim_x, x_fix); + k = call_ext_fct(edf_iteration, dim_x + dim_u, xu.data(), dim_x, x_fix); // tape near solution trace_on(sub_tape_num, 1); @@ -227,11 +227,10 @@ fp_iteration(int sub_tape_num, xu[i] <<= x_fix[i].getValue(); for (i = 0; i < dim_u; i++) xu[dim_x + i] <<= u[i].getValue(); - adouble_F(xu, xu + dim_x, x_fix, dim_x, dim_u); + adouble_F(xu.data(), xu.data() + dim_x, x_fix, dim_x, dim_u); for (i = 0; i < dim_x; i++) x_fix[i] >>= dummy; trace_off(); - delete[] xu; return k; } From eb28bdbe64dfeaf4f042677204ae204701ca81df Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Mon, 25 Nov 2024 17:18:54 +0100 Subject: [PATCH 4/5] Rename PersistantTapeInfos to PersistentTapeInfos Because that is the correct spelling of 'persistent'. --- ADOL-C/src/tape_handling.cpp | 4 ++-- ADOL-C/src/taping_p.h | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ADOL-C/src/tape_handling.cpp b/ADOL-C/src/tape_handling.cpp index 472140db..c940f03a 100644 --- a/ADOL-C/src/tape_handling.cpp +++ b/ADOL-C/src/tape_handling.cpp @@ -1066,14 +1066,14 @@ void TapeInfos::copy(const TapeInfos &tInfos) { pTapeInfos = tInfos.pTapeInfos; } -PersistantTapeInfos::PersistantTapeInfos() { +PersistentTapeInfos::PersistentTapeInfos() { char *ptr = (char *)(&forodec_nax), *end = (char *)(¶mstore); for (; ptr != end; ptr++) *ptr = 0; paramstore = NULL; } -PersistantTapeInfos::~PersistantTapeInfos() { +PersistentTapeInfos::~PersistentTapeInfos() { if (jacSolv_nax) { free(jacSolv_ci); free(jacSolv_ri); diff --git a/ADOL-C/src/taping_p.h b/ADOL-C/src/taping_p.h index fc37f126..3dfadd5a 100644 --- a/ADOL-C/src/taping_p.h +++ b/ADOL-C/src/taping_p.h @@ -160,7 +160,7 @@ typedef struct SparseHessInfos { } SparseHessInfos; #endif -typedef struct PersistantTapeInfos { /* survive tape re-usage */ +typedef struct PersistentTapeInfos { /* survive tape re-usage */ int forodec_nax, forodec_dax; double *forodec_y, *forodec_z, **forodec_Z; double **jacSolv_J; @@ -198,11 +198,11 @@ typedef struct PersistantTapeInfos { /* survive tape re-usage */ revreal *paramstore; #ifdef __cplusplus - PersistantTapeInfos(); - ~PersistantTapeInfos(); - PersistantTapeInfos &operator=(const PersistantTapeInfos &) = default; + PersistentTapeInfos(); + ~PersistentTapeInfos(); + PersistentTapeInfos &operator=(const PersistentTapeInfos &) = default; #endif -} PersistantTapeInfos; +} PersistentTapeInfos; /** * maximal number of locations writen per op code @@ -291,7 +291,7 @@ typedef struct TapeInfos { locint *switchlocs; double *signature; - PersistantTapeInfos pTapeInfos; + PersistentTapeInfos pTapeInfos; #if defined(__cplusplus) TapeInfos(); From 21894d44365dfe3ae064d6788860dfb19083833f Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Tue, 26 Nov 2024 06:24:48 +0100 Subject: [PATCH 5/5] Remove some signed/unsigned compiler warnings --- ADOL-C/include/adolc/adtl_hov.h | 97 +++++++++++++++++---------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/ADOL-C/include/adolc/adtl_hov.h b/ADOL-C/include/adolc/adtl_hov.h index baeeee64..71e21295 100644 --- a/ADOL-C/include/adolc/adtl_hov.h +++ b/ADOL-C/include/adolc/adtl_hov.h @@ -369,13 +369,13 @@ inline double makeInf() { return ADOLC_MATH_NSP::numeric_limits::infinity(); } -#define FOR_I_EQ_0_LT_NUMDIR for (int _i = 0; _i < adouble::numDir; ++_i) +#define FOR_I_EQ_0_LT_NUMDIR for (decltype(adouble::numDir) _i = 0; _i < adouble::numDir; ++_i) #define FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR \ - for (int _j = 0; _j < adouble::degree; ++_j) \ - for (int _i = 0; _i < adouble::numDir; ++_i) + for (decltype(adouble::degree) _j = 0; _j < adouble::degree; ++_j) \ + for (decltype(adouble::numDir) _i = 0; _i < adouble::numDir; ++_i) #define FOR_I_EQ_0_LT_NUMDIR_FOR_J_EQ_0_LT_DEGREE \ - for (int _i = 0; _i < adouble::numDir; ++_i) \ - for (int _j = 0; _j < adouble::degree; ++_j) + for (decltype(adouble::numDir) _i = 0; _i < adouble::numDir; ++_i) \ + for (decltype(adouble::degree) _j = 0; _j < adouble::degree; ++_j) #define ADVAL_I adval[_i] #define ADV_I adv[_i] #define V_I v[_i] @@ -647,11 +647,11 @@ inline adouble adouble::operator*(const adouble &a) const { { int i; double sum = 0.0; - for (int l = 0; l < numDir; l++) { - for (int k = 0; k < degree; k++) { + for (size_t l = 0; l < numDir; l++) { + for (size_t k = 0; k < degree; k++) { sum = val * a.ho_deriv[k][l] + ho_deriv[k][l] * a.val; i = k - 1; - for (int j = 0; j < k; j++) { + for (size_t j = 0; j < k; j++) { sum = sum + ho_deriv[j][l] * a.ho_deriv[i - j][l]; } tmp.ho_deriv[k][l] = sum; @@ -720,11 +720,11 @@ inline adouble adouble::operator/(const adouble &a) const { { int i; double sum = 0.0; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { sum = tmp.val * a.ho_deriv[k][l]; i = k - 1; - for (int j = 0; j < k; j++) { + for (size_t j = 0; j < k; j++) { sum += tmp.ho_deriv[j][l] * a.ho_deriv[i - j][l]; } tmp.ho_deriv[k][l] = (1.0 / a.val) * (ho_deriv[k][l] - sum); @@ -757,11 +757,11 @@ inline adouble operator/(const double v, const adouble &a) { { int i; double sum = 0.0; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { sum = tmp.val * a.ho_deriv[k][l]; i = k - 1; - for (int j = 0; j < k; j++) { + for (size_t j = 0; j < k; j++) { sum += tmp.ho_deriv[j][l] * a.ho_deriv[i - j][l]; } tmp.ho_deriv[k][l] = (1.0 / a.val) * (-sum); @@ -877,10 +877,10 @@ inline adouble exp(const adouble &a) { double sum = 0; int i; FOR_I_EQ_0_LT_NUMDIR - for (int k = 0; k < adouble::degree; k++) { + for (size_t k = 0; k < adouble::degree; k++) { sum = tmp.val * (k + 1) * a.ho_deriv[k][_i]; i = k - 1; - for (int j = 0; j < k; j++) + for (size_t j = 0; j < k; j++) sum += tmp.ho_deriv[i - j][_i] * (j + 1.0) * a.ho_deriv[j][_i]; tmp.ho_deriv[k][_i] = (1.0 / (k + 1)) * sum; sum = 0.0; @@ -915,11 +915,11 @@ inline adouble log(const adouble &a) { { int i; double sum = 0.0; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { // ho_deriv[i-j][l] i = k - 1; - for (int j = 0; j < k; j++) + for (size_t j = 0; j < k; j++) sum += a.ho_deriv[i - j][l] * (j + 1) * tmp.ho_deriv[j][l]; tmp.ho_deriv[k][l] = (1.0 / (k + 1)) * (1.0 / a.val) * ((k + 1) * a.ho_deriv[k][l] - sum); @@ -956,11 +956,11 @@ inline adouble sqrt(const adouble &a) { { int i; double sum = 0.0; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { // ho_deriv[i-j][l] i = k - 1; - for (int j = 0; j < k; j++) + for (size_t j = 0; j < k; j++) sum += tmp.ho_deriv[j][l] * tmp.ho_deriv[i - j][l]; tmp.ho_deriv[k][l] = 1.0 / (2.0 * tmp.val) * (a.ho_deriv[k][l] - sum); sum = 0.0; @@ -999,14 +999,14 @@ inline adouble sin(const adouble &a) { { int i, m; double sum1 = 0.0, sum2 = 0.0; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { // ho_deriv[k][l] m = k + 1; sum1 = tmp2.val * m * a.ho_deriv[k][l]; sum2 = -tmp.val * m * a.ho_deriv[k][l]; i = k - 1; - for (int j = 0; j < k; j++) { + for (size_t j = 0; j < k; j++) { sum1 += (j + 1) * a.ho_deriv[j][l] * tmp2.ho_deriv[i - j][l]; sum2 += -(j + 1) * a.ho_deriv[j][l] * tmp.ho_deriv[i - j][l]; } @@ -1042,14 +1042,14 @@ inline adouble cos(const adouble &a) { { int i, m; double sum1 = 0.0, sum2 = 0.0; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { // ho_deriv[k][l] m = k + 1; sum1 = tmp2.val * m * a.ho_deriv[k][l]; sum2 = -tmp.val * m * a.ho_deriv[k][l]; i = k - 1; - for (int j = 0; j < k; j++) { + for (size_t j = 0; j < k; j++) { sum1 += (j + 1) * a.ho_deriv[j][l] * tmp2.ho_deriv[i - j][l]; sum2 += -(j + 1) * a.ho_deriv[j][l] * tmp.ho_deriv[i - j][l]; } @@ -1210,9 +1210,10 @@ inline adouble pow(const adouble &a, double v) { // this is different than in GW08. The formula in the table gives a nan // for input zero. double factorial_val = tgamma(v + 1.0); - for (int k = 0; k < adouble::degree; k++) - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; + for (size_t k = 0; k < adouble::degree; k++) + for (size_t l = 0; l < adouble::numDir; l++) { + // TODO: This is shadowing the outer loop variable + for (size_t k = 0; k < adouble::degree; k++) // unsure if this is needed here. keep it for the moment // TODO: check if tmp.ho_deriv is zero before here { @@ -1227,12 +1228,12 @@ inline adouble pow(const adouble &a, double v) { } else { int i; double sum1 = 0.0, sum2 = 0.0; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { // ho_deriv[k][l] sum1 = tmp.val * (k + 1) * a.ho_deriv[k][l]; i = k - 1; - for (int j = 0; j < k; j++) { + for (size_t j = 0; j < k; j++) { sum1 += tmp.ho_deriv[i - j][l] * (j + 1) * a.ho_deriv[j][l]; sum2 += a.ho_deriv[i - j][l] * (1 + j) * tmp.ho_deriv[j][l]; } @@ -1299,13 +1300,13 @@ inline adouble pow(double v, const adouble &a) { { int i; double sum; - for (int l = 0; l < adouble::numDir; l++) { + for (size_t l = 0; l < adouble::numDir; l++) { sum = 0.0; - for (int k = 0; k < adouble::degree; k++) { + for (size_t k = 0; k < adouble::degree; k++) { // ho_deriv[k][l] sum = tmp.val * (k + 1) * a.ho_deriv[k][l]; i = k - 1; - for (int j = 0; j < k; j++) + for (size_t j = 0; j < k; j++) sum += tmp.ho_deriv[i - j][l] * (j + 1) * a.ho_deriv[j][l]; tmp.ho_deriv[k][l] = (1.0 / (k + 1)) * sum * ADOLC_MATH_NSP::log(v); sum = 0.0; @@ -1365,14 +1366,14 @@ inline adouble sinh(const adouble &a) { tmp2 = ADOLC_MATH_NSP::cosh(a.val); int i, m; double sum1 = 0.0, sum2 = 0.0; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { // ho_deriv[k][l] m = k + 1; sum1 = tmp2.val * m * a.ho_deriv[k][l]; sum2 = tmp.val * m * a.ho_deriv[k][l]; i = k - 1; - for (int j = 0; j < k; j++) { + for (size_t j = 0; j < k; j++) { sum1 += (j + 1) * a.ho_deriv[j][l] * tmp2.ho_deriv[i - j][l]; sum2 += (j + 1) * a.ho_deriv[j][l] * tmp.ho_deriv[i - j][l]; } @@ -1409,14 +1410,14 @@ inline adouble cosh(const adouble &a) { int i, m; double sum1 = 0.0, sum2 = 0.0; tmp2 = ADOLC_MATH_NSP::sinh(a.val); - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { // ho_deriv[k][l] m = k + 1; sum1 = tmp2.val * m * a.ho_deriv[k][l]; sum2 = tmp.val * m * a.ho_deriv[k][l]; i = k - 1; - for (int j = 0; j < k; j++) { + for (size_t j = 0; j < k; j++) { sum1 += (j + 1) * a.ho_deriv[j][l] * tmp2.ho_deriv[i - j][l]; sum2 += (j + 1) * a.ho_deriv[j][l] * tmp.ho_deriv[i - j][l]; } @@ -1577,14 +1578,14 @@ inline adouble fabs(const adouble &a) { // coefficient int *leading_sgn = (int *)alloca(sizeof(int) * adouble::degree); - for (int l = 0; l < adouble::numDir; l++) // Init + for (size_t l = 0; l < adouble::numDir; l++) // Init { leading_sgn[l] = 1; } bool found; - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { if (tmp.ho_deriv[k][l] > 0 && (!found)) { leading_sgn[l] = 1; found = true; @@ -1611,8 +1612,8 @@ inline adouble fabs(const adouble &a) { // assume we found all leading Taylor coefficients - for (int l = 0; l < adouble::numDir; l++) { - for (int k = 0; k < adouble::degree; k++) { + for (size_t l = 0; l < adouble::numDir; l++) { + for (size_t k = 0; k < adouble::degree; k++) { tmp.ho_deriv[k][l] *= leading_sgn[l]; // TODO do not forget zero-th Taylor coefficient }