Skip to content

Commit fad93ba

Browse files
committed
constify input arguments
1 parent eab24dd commit fad93ba

File tree

9 files changed

+271
-233
lines changed

9 files changed

+271
-233
lines changed

ADOL-C/include/adolc/fortutils.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ BEGIN_C_DECLS
2525
ADOLC_DLL_EXPORT void spread1(int m, const fdouble *x, double *X);
2626
ADOLC_DLL_EXPORT void pack1(int m, const double *X, fdouble *x);
2727

28-
ADOLC_DLL_EXPORT void spread2(int m, int n, fdouble *x, double **X);
29-
ADOLC_DLL_EXPORT void pack2(int m, int n, double **X, fdouble *x);
28+
ADOLC_DLL_EXPORT void spread2(int m, int n, const fdouble *x, double **X);
29+
ADOLC_DLL_EXPORT void pack2(int m, int n, const double *const *X, fdouble *x);
3030

31-
ADOLC_DLL_EXPORT void spread3(int m, int n, int p, fdouble *x, double ***X);
32-
ADOLC_DLL_EXPORT void pack3(int m, int n, int p, double ***X, fdouble *x);
31+
ADOLC_DLL_EXPORT void spread3(int m, int n, int p, const fdouble *x,
32+
double ***X);
33+
ADOLC_DLL_EXPORT void pack3(int m, int n, int p, const double *const *const *X,
34+
fdouble *x);
3335

3436
END_C_DECLS
3537

ADOL-C/include/adolc/interfaces.h

Lines changed: 103 additions & 81 deletions
Large diffs are not rendered by default.

ADOL-C/src/fo_rev.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ int fos_pl_sig_reverse(short tnum, /* tape id */
230230
int depen, /* consistency chk on # of deps */
231231
int indep, /* consistency chk on # of indeps */
232232
int swchk, /* consistency chk on # of switches */
233-
short *siggrad, double *lagrange,
233+
const short *siggrad, const double *lagrange,
234234
double *results) /* coefficient vectors */
235235
#else
236236
int fos_reverse(short tnum, /* tape id */
@@ -245,35 +245,37 @@ int fos_reverse(short tnum, /* tape id */
245245
/* First-Order Vector Reverse Pass. */
246246
/****************************************************************************/
247247

248-
int fov_reverse(short tnum, /* tape id */
249-
int depen, /* consistency chk on # of deps */
250-
int indep, /* consistency chk on # of indeps */
251-
int nrows, /* # of Jacobian rows being calculated */
252-
double **lagrange, /* domain weight vector */
253-
double **results) /* matrix of coefficient vectors */
248+
int fov_reverse(short tnum, /* tape id */
249+
int depen, /* consistency chk on # of deps */
250+
int indep, /* consistency chk on # of indeps */
251+
int nrows, /* # of Jacobian rows being calculated */
252+
const double *const *lagrange, /* domain weight vector */
253+
double **results) /* matrix of coefficient vectors */
254254

255255
#elif defined(_INT_REV_)
256256
#if defined(_TIGHT_)
257257
/****************************************************************************/
258258
/* First Order Vector version of the reverse mode for bit patterns, tight */
259259
/****************************************************************************/
260-
int int_reverse_tight(short tnum, /* tape id */
261-
int depen, /* consistency chk on # of deps */
262-
int indep, /* consistency chk on # of indeps */
263-
int nrows, /* # of Jacobian rows being calculated */
264-
size_t **lagrange, /* domain weight vector[var][row](in)*/
265-
size_t **results) /* matrix of coeff. vectors[var][row]*/
260+
int int_reverse_tight(
261+
short tnum, /* tape id */
262+
int depen, /* consistency chk on # of deps */
263+
int indep, /* consistency chk on # of indeps */
264+
int nrows, /* # of Jacobian rows being calculated */
265+
const size_t *const *lagrange, /* domain weight vector[var][row](in)*/
266+
size_t **results) /* matrix of coeff. vectors[var][row]*/
266267

267268
#elif defined(_NTIGHT_)
268269
/****************************************************************************/
269270
/* First Order Vector version of the reverse mode, bit pattern, safe */
270271
/****************************************************************************/
271-
int int_reverse_safe(short tnum, /* tape id */
272-
int depen, /* consistency chk on # of deps */
273-
int indep, /* consistency chk on # of indeps */
274-
int nrows, /* # of Jacobian rows being calculated */
275-
size_t **lagrange, /* domain weight vector[var][row](in)*/
276-
size_t **results) /* matrix of coeff. vectors[var][row]*/
272+
int int_reverse_safe(
273+
short tnum, /* tape id */
274+
int depen, /* consistency chk on # of deps */
275+
int indep, /* consistency chk on # of indeps */
276+
int nrows, /* # of Jacobian rows being calculated */
277+
const size_t *const *lagrange, /* domain weight vector[var][row](in)*/
278+
size_t **results) /* matrix of coeff. vectors[var][row]*/
277279
#else
278280
#error Neither _TIGHT_ nor _NTIGHT_ defined
279281
#endif

ADOL-C/src/fortutils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ void pack1(int m, const double *X, fdouble *x) {
3535
}
3636

3737
/*--------------------------------------------------------------------------*/
38-
void spread2(int m, int n, fdouble *x, double **X) {
38+
void spread2(int m, int n, const fdouble *x, double **X) {
3939
int i, j;
4040
for (j = 0; j < n; j++)
4141
for (i = 0; i < m; i++)
4242
X[i][j] = *x++;
4343
}
4444

4545
/*--------------------------------------------------------------------------*/
46-
void pack2(int m, int n, double **X, fdouble *x) {
46+
void pack2(int m, int n, const double *const *X, fdouble *x) {
4747
int i, j;
4848
for (j = 0; j < n; j++)
4949
for (i = 0; i < m; i++)
5050
*x++ = X[i][j];
5151
}
5252

5353
/*--------------------------------------------------------------------------*/
54-
void spread3(int m, int n, int p, fdouble *x, double ***X) {
54+
void spread3(int m, int n, int p, const fdouble *x, double ***X) {
5555
int i, j, k;
5656
for (k = 0; k < p; k++)
5757
for (j = 0; j < n; j++)
@@ -60,7 +60,7 @@ void spread3(int m, int n, int p, fdouble *x, double ***X) {
6060
}
6161

6262
/*--------------------------------------------------------------------------*/
63-
void pack3(int m, int n, int p, double ***X, fdouble *x) {
63+
void pack3(int m, int n, int p, const double *const *const *X, fdouble *x) {
6464
int i, j, k;
6565
for (k = 0; k < p; k++)
6666
for (j = 0; j < n; j++)

ADOL-C/src/forward_partx.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ BEGIN_C_DECLS
2222
/* zos_forward_partx(tag, m, mdim[n], n, x[n][d], y[m]) */
2323
/* (based on zos_forward) */
2424

25-
int zos_forward_partx(short tag, int m, int n, int *ndim, double **x,
26-
double *y) {
25+
int zos_forward_partx(short tag, int m, int n, const int *ndim,
26+
const double *const *x, double *y) {
2727
double *x0; /* base point */
2828
int i, j, ind, sum_n, rc;
2929

@@ -52,8 +52,8 @@ int zos_forward_partx(short tag, int m, int n, int *ndim, double **x,
5252
/* fos_forward_partx(tag, m, n, ndim[n], x[n][][2], y[m][2]) */
5353
/* (based on fos_forward) */
5454

55-
int fos_forward_partx(short tag, int m, int n, int *ndim, double ***x,
56-
double **y) {
55+
int fos_forward_partx(short tag, int m, int n, const int *ndim,
56+
const double *const *const *x, double **y) {
5757
double *x0; /* base point */
5858
double *xtay; /* Taylor coefficients */
5959
double *y0; /* result */
@@ -97,8 +97,8 @@ int fos_forward_partx(short tag, int m, int n, int *ndim, double ***x,
9797
/* hos_forward_partx(tag, m, n, ndim[n], d, x[n][][d+1], y[m][d+1]) */
9898
/* (based on hos_forward) */
9999

100-
int hos_forward_partx(short tag, int m, int n, int *ndim, int d, double ***x,
101-
double **y) {
100+
int hos_forward_partx(short tag, int m, int n, const int *ndim, int d,
101+
const double *const *const *x, double **y) {
102102
double *x0; /* base point */
103103
double **xtay; /* Taylor coefficients */
104104
double *y0; /* result */
@@ -145,8 +145,9 @@ int hos_forward_partx(short tag, int m, int n, int *ndim, int d, double ***x,
145145
y[m], Y[m][p]) */
146146
/* (based on fov_forward) */
147147

148-
int fov_forward_partx(short tag, int m, int n, int *ndim, int p, double **x,
149-
double ***Xppp, double *y, double **Ypp) {
148+
int fov_forward_partx(short tag, int m, int n, const int *ndim, int p,
149+
const double *const *x, const double *const *const *Xppp,
150+
double *y, double **Ypp) {
150151
double *x0; /* base point */
151152
double **X; /* Taylor coefficients */
152153
int i, j, k, ind, sum_n, rc;
@@ -181,8 +182,10 @@ int fov_forward_partx(short tag, int m, int n, int *ndim, int p, double **x,
181182
y[m], Y[m][p][d]) */
182183
/* (based on hov_forward) */
183184

184-
int hov_forward_partx(short tag, int m, int n, int *ndim, int d, int p,
185-
double **x, double ****Xpppp, double *y, double ***Yppp) {
185+
int hov_forward_partx(short tag, int m, int n, const int *ndim, int d, int p,
186+
const double *const *x,
187+
const double *const *const *const *Xpppp, double *y,
188+
double ***Yppp) {
186189
double *x0; /* base point */
187190
double ***X; /* Taylor coefficients */
188191
int i, j, k, l, ind, sum_n, rc;

ADOL-C/src/ho_rev.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,36 +238,36 @@ int hos_reverse(short tnum, /* tape id */
238238
return rc;
239239
}
240240

241-
int hos_ti_reverse(short tnum, /* tape id */
242-
int depen, /* consistency chk on # of deps */
243-
int indep, /* consistency chk on # of indeps */
244-
int degre, /* highest derivative degre */
245-
double **lagrange, /* range weight vectors */
246-
double **results) /* matrix of coefficient vectors */
241+
int hos_ti_reverse(short tnum, /* tape id */
242+
int depen, /* consistency chk on # of deps */
243+
int indep, /* consistency chk on # of indeps */
244+
int degre, /* highest derivative degre */
245+
const double *const *lagrange, /* range weight vectors */
246+
double **results) /* matrix of coefficient vectors */
247247

248248
#elif _HOS_OV_
249249

250250
/***************************************************************************/
251251
/* Higher Order Scalar Reverse Pass, Vector Keep. */
252252
/***************************************************************************/
253-
int hos_ov_reverse(short tnum, /* tape id */
254-
int depen, /* consistency chk on # of deps */
255-
int indep, /* consistency chk on # of indeps */
256-
int degre, /* highest derivative degre */
257-
int nrows, /* # of Jacobian rows calculated */
258-
double **lagrange, /* range weight vector */
253+
int hos_ov_reverse(short tnum, /* tape id */
254+
int depen, /* consistency chk on # of deps */
255+
int indep, /* consistency chk on # of indeps */
256+
int degre, /* highest derivative degre */
257+
int nrows, /* # of Jacobian rows calculated */
258+
const double *const *lagrange, /* range weight vector */
259259
double ***results) /* matrix of coefficient vectors */
260260

261261
#elif _HOV_
262262
/***************************************************************************/
263263
/* Higher Order Vector Reverse Pass. */
264264
/***************************************************************************/
265-
int hov_reverse(short tnum, /* tape id */
266-
int depen, /* consistency chk on # of deps */
267-
int indep, /* consistency chk on # of indeps */
268-
int degre, /* highest derivative degre */
269-
int nrows, /* # of Jacobian rows calculated */
270-
double **lagrange, /* domain weight vector */
265+
int hov_reverse(short tnum, /* tape id */
266+
int depen, /* consistency chk on # of deps */
267+
int indep, /* consistency chk on # of indeps */
268+
int degre, /* highest derivative degre */
269+
int nrows, /* # of Jacobian rows calculated */
270+
const double *const *lagrange, /* domain weight vector */
271271
double ***results, /* matrix of coefficient vectors */
272272
short **nonzero) /* structural sparsity pattern */
273273
{
@@ -284,14 +284,15 @@ int hov_reverse(short tnum, /* tape id */
284284
return rc;
285285
}
286286

287-
int hov_ti_reverse(short tnum, /* tape id */
288-
int depen, /* consistency chk on # of deps */
289-
int indep, /* consistency chk on # of indeps */
290-
int degre, /* highest derivative degre */
291-
int nrows, /* # of Jacobian rows calculated */
292-
double ***lagrange, /* domain weight vectors */
293-
double ***results, /* matrix of coefficient vectors */
294-
short **nonzero) /* structural sparsity pattern */
287+
int hov_ti_reverse(
288+
short tnum, /* tape id */
289+
int depen, /* consistency chk on # of deps */
290+
int indep, /* consistency chk on # of indeps */
291+
int degre, /* highest derivative degre */
292+
int nrows, /* # of Jacobian rows calculated */
293+
const double *const *const *lagrange, /* domain weight vectors */
294+
double ***results, /* matrix of coefficient vectors */
295+
short **nonzero) /* structural sparsity pattern */
295296

296297
#endif
297298

ADOL-C/src/interfaces.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ int forward(short tag, int m, int n, int d, int keep, double **X, double *Y)
159159
/****************************************************************************/
160160
/* X and Y can be one dimensional if d = 0 */
161161
/* */
162-
int forward(short tag, int m, int n, int d, int keep, double *X, double *Y)
162+
int forward(short tag, int m, int n, int d, int keep, const double *X,
163+
double *Y)
163164
/* forward(tag, m, n, 0, keep, X[n], Y[m]), d=0 */
164165
{
165166
int rc = -1;
@@ -176,7 +177,7 @@ int forward(short tag, int m, int n, int d, int keep, double *X, double *Y)
176177
/****************************************************************************/
177178
/* X and Y can be one dimensional if d omitted */
178179
/* */
179-
int forward(short tag, int m, int n, int keep, double *X, double *Y)
180+
int forward(short tag, int m, int n, int keep, const double *X, double *Y)
180181
/* forward(tag, m, n, keep, X[n], Y[m]) */
181182
{
182183
return zos_forward(tag, m, n, keep, X, Y);
@@ -185,8 +186,8 @@ int forward(short tag, int m, int n, int keep, double *X, double *Y)
185186
/****************************************************************************/
186187
/* general call */
187188
/* */
188-
int forward(short tag, int m, int n, int d, int p, double *x, double ***X,
189-
double *y, double ***Y)
189+
int forward(short tag, int m, int n, int d, int p, const double *x,
190+
const double *const *const *X, double *y, double ***Y)
190191
/* forward(tag, m, n, d, p, x[n], X[n][p][d], y[m], Y[m][p][d]) */
191192
{
192193
return hov_forward(tag, m, n, d, p, x, X, y, Y);
@@ -195,8 +196,8 @@ int forward(short tag, int m, int n, int d, int p, double *x, double ***X,
195196
/****************************************************************************/
196197
/* general call */
197198
/* */
198-
int forward(short tag, int m, int n, int p, double *x, double **X, double *y,
199-
double **Y)
199+
int forward(short tag, int m, int n, int p, const double *x,
200+
const double *const *X, double *y, double **Y)
200201
/* forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]) */
201202
{
202203
return fov_forward(tag, m, n, p, x, X, y, Y);
@@ -208,7 +209,7 @@ int forward(short tag, int m, int n, int p, double *x, double **X, double *y,
208209
/****************************************************************************/
209210
/* general call */
210211
/* */
211-
int reverse(short tag, int m, int n, int d, double *u, double **Z)
212+
int reverse(short tag, int m, int n, int d, const double *u, double **Z)
212213
/* reverse(tag, m, n, d, u[m], Z[n][d+1]) */
213214
{
214215
return hos_reverse(tag, m, n, d, u, Z);
@@ -234,7 +235,7 @@ int reverse(short tag, int m, int n, int d, double u, double **Z)
234235
/****************************************************************************/
235236
/* Z can be vector if d = 0; Done by specialized code */
236237
/* */
237-
int reverse(short tag, int m, int n, int d, double *u, double *Z)
238+
int reverse(short tag, int m, int n, int d, const double *u, double *Z)
238239
/* reverse(tag, m, n, 0, u[m], Z[n]), d=0 */
239240
{
240241
if (d != 0) {
@@ -266,8 +267,8 @@ int reverse(short tag, int m, int n, int d, double u, double *Z)
266267
/****************************************************************************/
267268
/* general call */
268269
/* */
269-
int reverse(short tag, int m, int n, int d, int q, double **U, double ***Z,
270-
short **nz)
270+
int reverse(short tag, int m, int n, int d, int q, const double *const *U,
271+
double ***Z, short **nz)
271272
/* reverse(tag, m, n, d, q, U[q][m], Z[q][n][d+1], nz[q][n]) */
272273
{
273274
return hov_reverse(tag, m, n, d, q, U, Z, nz);
@@ -301,7 +302,8 @@ int reverse(short tag, int m, int n, int d, int q, double *U, double ***Z,
301302
/* */
302303
/* If d=0 then Z may be matrix; Done by specialized code */
303304
/* */
304-
int reverse(short tag, int m, int n, int d, int q, double **U, double **Z)
305+
int reverse(short tag, int m, int n, int d, int q, const double *const *U,
306+
double **Z)
305307
/* reverse(tag, m, n, 0, q, U[q][m], Z[q][n]), d=0 => Z matrix */
306308
{
307309
int rc = -1;
@@ -319,7 +321,7 @@ int reverse(short tag, int m, int n, int d, int q, double **U, double **Z)
319321
/* */
320322
/* d=0 may be omitted, then Z may be a matrix; specialized code */
321323
/* */
322-
int reverse(short tag, int m, int n, int q, double **U, double **Z)
324+
int reverse(short tag, int m, int n, int q, const double *const *U, double **Z)
323325
/* reverse(tag, m, n, q, U[q][m], Z[q][n]), d=0 => Z matrix */
324326
{
325327
int rc = -1;

0 commit comments

Comments
 (0)