Skip to content

Commit

Permalink
Quiet warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnoel committed Feb 10, 2024
1 parent 699d568 commit c409a56
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 16 deletions.
17 changes: 13 additions & 4 deletions src/linad99/rngen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
* Description not yet available.
*/
#include "fvar.hpp"
#ifdef DEBUG
#include <cassert>
#endif

#define N 624
#define M 397
Expand All @@ -69,13 +72,16 @@
*/
random_number_generator::random_number_generator(const int seed)
{
unsigned long s=seed;
#ifdef DEBUG
assert(seed >= 0);
#endif
unsigned long s = static_cast<unsigned long>(seed);
mt=new unsigned long [N]; /* the array for the state vector */
mti=N+1; /* mti==N+1 means mt[N] is not initialized */

mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
mt[mti] = (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
mt[mti] = (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + static_cast<unsigned long>(mti));
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
Expand Down Expand Up @@ -105,10 +111,13 @@ random_number_generator::~random_number_generator()
*/
void random_number_generator::reinitialize(int seed)
{
unsigned long s=seed;
#ifdef DEBUG
assert(seed >= 0);
#endif
unsigned long s = static_cast<unsigned long>(seed);
mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
mt[mti] = (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
mt[mti] = (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + static_cast<unsigned long>(mti));
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
Expand Down
29 changes: 24 additions & 5 deletions src/linad99/vspline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/

#include <fvar.hpp>
#ifdef DEBUG
#include <cassert>
#include <climits>
#endif

dvar_vector spline(const dvector &x,const dvar_vector&y,double yp1,double ypn);
dvar_vector spline(const dvector &x,const dvar_vector&y,dvariable yp1,
Expand Down Expand Up @@ -40,7 +44,10 @@ dvariable splint(const dvector& _xa,const dvar_vector& _ya,
{
gradient_structure* gs = gradient_structure::_instance;
gs->RETURN_ARRAYS_INCREMENT();
dvariable ret = spline_cubic_val(_xa.size(), _xa, x, _ya, _y2a);
#ifdef DEBUG
assert(_xa.size() <= INT_MAX);
#endif
dvariable ret = spline_cubic_val(static_cast<int>(_xa.size()), _xa, x, _ya, _y2a);
gs->RETURN_ARRAYS_DECREMENT();
return ret;
}
Expand All @@ -59,7 +66,10 @@ dvariable splint(const dvector& _xa,const dvar_vector& _ya,
{
gradient_structure* gs = gradient_structure::_instance;
gs->RETURN_ARRAYS_INCREMENT();
dvariable ret = spline_cubic_val2(_xa.size(), _xa, _x, _ya, _y2a);
#ifdef DEBUG
assert(_xa.size() <= INT_MAX);
#endif
dvariable ret = spline_cubic_val2(static_cast<int>(_xa.size()), _xa, _x, _ya, _y2a);
gs->RETURN_ARRAYS_DECREMENT();
return ret;
}
Expand Down Expand Up @@ -169,7 +179,10 @@ dvar_vector spline(const dvector &_x,const dvar_vector&_y,dvariable yp1,
ybcend = ypn;
}

dvar_vector ret = spline_cubic_set(x.size(), x, y, ibcbeg, ybcbeg, ibcend,
#ifdef DEBUG
assert(x.size() <= INT_MAX);
#endif
dvar_vector ret = spline_cubic_set(static_cast<int>(x.size()), x, y, ibcbeg, ybcbeg, ibcend,
ybcend);
ret.shift(_x.indexmin());
return ret;
Expand Down Expand Up @@ -216,7 +229,10 @@ dvar_vector spline(const dvector &_x,const dvar_vector&_y,double yp1,
ybcend = ypn;
}

dvar_vector ret = spline_cubic_set(x.size(), x, y, ibcbeg, ybcbeg, ibcend,
#ifdef DEBUG
assert(x.size() <= INT_MAX);
#endif
dvar_vector ret = spline_cubic_set(static_cast<int>(x.size()), x, y, ibcbeg, ybcbeg, ibcend,
ybcend);
ret.shift(_x.indexmin());
return ret;
Expand Down Expand Up @@ -263,7 +279,10 @@ dvar_vector spline(const dvector &_x,const dvar_vector&_y,dvariable yp1,
ybcend = ypn;
}

dvar_vector ret = spline_cubic_set(x.size(), x, y, ibcbeg, ybcbeg, ibcend,
#ifdef DEBUG
assert(x.size() <= INT_MAX);
#endif
dvar_vector ret = spline_cubic_set(static_cast<int>(x.size()), x, y, ibcbeg, ybcbeg, ibcend,
ybcend);
ret.shift(_x.indexmin());
return ret;
Expand Down
5 changes: 3 additions & 2 deletions src/nh99/lbfgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static integer c__1 = 1;
/* **************** */

/* Subroutine */ int lbfgs_(integer *n, integer *m, doublereal *x, doublereal
*f, doublereal *g, logical *diagco, doublereal *diag, integer *iprint,
*f, doublereal *g, logical *diagco, doublereal *diag, [[maybe_unused]] integer *iprint,
doublereal *eps, doublereal *xtol, doublereal *w, integer *iflag,
integer* iter, integer * info)
{
Expand Down Expand Up @@ -299,7 +299,8 @@ ETERS (N OR M\002,\002 ARE NOT POSITIVE)\002)";
integer *);
static integer iscn, nfev, iycn;
static doublereal ftol;
static integer nfun, ispt, iypt, i, bound;
[[maybe_unused]] static integer nfun;
static integer ispt, iypt, i, bound;
static doublereal gnorm;
extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
integer *, doublereal *, integer *);
Expand Down
5 changes: 3 additions & 2 deletions src/nh99/t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ static integer c__1 = 1;

/* Subroutine */ int xlbfgs_(integer *n, integer *m, dvar_vector & x,
dvariable & f, dvar_vector & g, logical *diagco, dvar_vector & diag,
integer *iprint, double* eps, double* xtol, dvar_vector & w,
[[maybe_unused]] integer *iprint, double* eps, double* xtol, dvar_vector & w,
integer *iflag, integer* iter)
{
/* Initialized data */
Expand Down Expand Up @@ -454,7 +454,8 @@ ETERS (N OR M\002,\002 ARE NOT POSITIVE)\002)";
static integer inmc;
static integer info, iscn, nfev, iycn;
static double ftol;
static integer nfun, ispt, iypt, i, bound;
[[maybe_unused]] static integer nfun;
static integer ispt, iypt, i, bound;
static dvariable gnorm;
//extern /* Subroutine */
// int xdaxpy_(integer *n, dvariable* da,const dvar_vector & dx,
Expand Down
11 changes: 9 additions & 2 deletions src/nh99/xmodelm3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ using std::istringstream;
#include <admodel.h>
#include <df1b2fun.h>
#include <adrndeff.h>
#include<ctime>
#include <ctime>
#ifdef DEBUG
#include <cassert>
#include <climits>
#endif

void check_java_flags(int& start_flag,int& quit_flag,int& der_flag,
int& next_flag);
Expand Down Expand Up @@ -625,7 +629,10 @@ function_minimizer::function_minimizer(long int sz):
}
else
{
pgs = new gradient_structure(sz);
#ifdef DEBUG
assert(sz >= 0 && sz <= LONG_MAX);
#endif
pgs = new gradient_structure(static_cast<unsigned long>(sz));
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/tools99/tiny_ad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <iostream>
#define CSKIP(x) x
#endif
#ifdef DEBUG
#include <cassert>
#include <climits>
#endif

/* Select the vector class to use (Default: tiny_vec) */
#if defined(TINY_AD_USE_STD_VALARRAY)
Expand Down Expand Up @@ -304,7 +308,10 @@ namespace tiny_ad {
variable(Base x) : Base(x) {}
variable(double x) : Base(x) {}
variable(double x, int id) : Base(x) {
setid(id);
#ifdef DEBUG
assert(id >= 0 && id <= INT_MAX);
#endif
setid(static_cast<unsigned int>(id));
}
template<class Constant>
variable(Constant x) {
Expand Down

0 comments on commit c409a56

Please sign in to comment.