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

Various minor cleanup patches #86

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions ADOL-C/boost-test/traceOperatorScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
111 changes: 52 additions & 59 deletions ADOL-C/include/adolc/adtl_hov.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ inline double makeInf() {
return ADOLC_MATH_NSP::numeric_limits<double>::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]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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
{
Expand All @@ -1225,14 +1226,14 @@ 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++) {
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];
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1364,17 +1365,15 @@ 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++) {
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];
}
Expand Down Expand Up @@ -1409,18 +1408,16 @@ 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++) {
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];
}
Expand Down Expand Up @@ -1580,17 +1577,15 @@ 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
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;
Expand All @@ -1617,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
}
Expand Down Expand Up @@ -2200,9 +2195,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;
Expand Down Expand Up @@ -2254,9 +2248,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];
Expand Down
6 changes: 2 additions & 4 deletions ADOL-C/src/adalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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 **),
Expand Down
7 changes: 3 additions & 4 deletions ADOL-C/src/fixpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,24 @@ 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<adouble> 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);
for (i = 0; i < dim_x; i++)
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;
}
6 changes: 3 additions & 3 deletions ADOL-C/src/tape_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1066,14 +1066,14 @@ void TapeInfos::copy(const TapeInfos &tInfos) {
pTapeInfos = tInfos.pTapeInfos;
}

PersistantTapeInfos::PersistantTapeInfos() {
PersistentTapeInfos::PersistentTapeInfos() {
char *ptr = (char *)(&forodec_nax), *end = (char *)(&paramstore);
for (; ptr != end; ptr++)
*ptr = 0;
paramstore = NULL;
}

PersistantTapeInfos::~PersistantTapeInfos() {
PersistentTapeInfos::~PersistentTapeInfos() {
if (jacSolv_nax) {
free(jacSolv_ci);
free(jacSolv_ri);
Expand Down
Loading
Loading