Skip to content

Commit

Permalink
master: fix remaining clang warnings in check_test_more.
Browse files Browse the repository at this point in the history
test_one.sh.in: configue compiler.
.gitignore: ignore *.warn.
  • Loading branch information
bradbell committed Aug 13, 2018
1 parent 0f5c201 commit e6711c8
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# specific extensions in top direcotry
/*.err
/*.log
/*.warn
# ----------------------------------------------------------------------------
# vim swap files in any directory
*.swp
Expand Down
42 changes: 37 additions & 5 deletions bin/test_one.sh.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/bash -e
# -----------------------------------------------------------------------------
# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
#
# CppAD is distributed under multiple licenses. This distribution is under
# the terms of the
Expand All @@ -17,7 +17,7 @@ usage: bin/test_one.sh dir/file [extra]
dir: directory in front of file name
file: name of *.cpp file, with extension, that contains the test
extra: extra source files and/or options for the g++ command
extra: extra source files and/or options for the compile command
EOF
exit 1
fi
Expand Down Expand Up @@ -117,15 +117,47 @@ do
done
#
# compile command
compile_command="g++ test_one.cpp -o test_one.exe
compile_command="@CMAKE_CXX_COMPILER@ test_one.cpp -o test_one.exe
$dir/$file $extra
-g
$cxx_flags
$include_flags
$library_flags
"
echo "$compile_command"
$compile_command
echo "$compile_command 2> test_one.err"
if ! $compile_command 2> test_one.err
then
tail test_one.err
echo 'test_one.sh: see test_one.err'
exit 1
fi
# --------------------------------------------------------------------------
cat << EOF > test_one.sed
# Lines that describe where error is
/^In file included from/d
/: note:/d
#
# Ipopt has sign conversion warnings
/\/coin\/.*-Wsign-conversion/d
#
# Adolc has multiple types of conversion warnings
/\/adolc\/.*-W[a-z-]*conversion/d
/\/adolc\/.*-Wshorten-64-to-32/d
#
# Lines describing the error begin with space
/^ /d
#
# Lines summarizing results
/^[0-9]* warnings generated/d
EOF
sed -f test_one.sed < test_one.err > test_one.warn
rm test_one.sed
if [ -s test_one.warn ]
then
cat test_one.warn
echo 'test_one.sh: unexpected warnings: see test_one.warn, test_one.err'
exit 1
fi
# --------------------------------------------------------------------------
library_path='@PROJECT_BINARY_DIR@/cppad_lib'
if ! echo $LD_LIBRARY_PATH | grep "$library_path"
Expand Down
12 changes: 6 additions & 6 deletions cppad/core/checkpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ class checkpoint : public atomic_base<Base> {
The default value is unspecified.
\param optimize [in]
l should the operation sequence corresponding to the algo be optimized.
should the operation sequence corresponding to the algo be optimized.
The default value is true, but it is
sometimes useful to use false for debugging purposes.
*/
Expand All @@ -1443,11 +1443,11 @@ l should the operation sequence corresponding to the algo be optimized.
bool optimize = true
) :
atomic_base<Base>(name , sparsity) ,
f_( omp_get_max_threads() ) ,
jac_sparse_set_( omp_get_max_threads() ) ,
jac_sparse_bool_( omp_get_max_threads() ) ,
hes_sparse_set_( omp_get_max_threads() ) ,
hes_sparse_bool_( omp_get_max_threads() )
f_( size_t( omp_get_max_threads() ) ) ,
jac_sparse_set_( size_t( omp_get_max_threads() ) ) ,
jac_sparse_bool_( size_t( omp_get_max_threads() ) ) ,
hes_sparse_set_( size_t( omp_get_max_threads() ) ) ,
hes_sparse_bool_( size_t( omp_get_max_threads() ) )
{
CheckSimpleVector< CppAD::AD<Base> , ADVector>();

Expand Down
14 changes: 7 additions & 7 deletions test_more/cppad_for_tmb/cppad_for_tmb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
CppAD is distributed under multiple licenses. This distribution is under
the terms of the
Expand Down Expand Up @@ -154,9 +154,9 @@ bool multi_thread_checkpoint(void)
{ bool ok = true;

// OpenMP setup
int num_threads = 4; // number of threads
omp_set_dynamic(0); // turn off dynamic thread adjustment
omp_set_num_threads(num_threads); // set number of OMP threads
size_t num_threads = 4; // number of threads
omp_set_dynamic(0); // turn off dynamic thread adjustment
omp_set_num_threads( int(num_threads) ); // set number of OMP threads

// check that multi-threading is possible on this machine
if( omp_get_max_threads() < 2 )
Expand All @@ -181,11 +181,11 @@ bool multi_thread_checkpoint(void)

// place to hold result for each thread
d_vector y(num_threads);
for(int thread = 0; thread < num_threads; thread++)
for(size_t thread = 0; thread < num_threads; thread++)
y[thread] = 0.0;

# pragma omp parallel for
for(int thread = 0; thread < num_threads; thread++)
for(size_t thread = 0; thread < num_threads; thread++)
{ ad_vector au(n), av(m);
au[0] = 1.0;
CppAD::Independent(au);
Expand All @@ -201,7 +201,7 @@ bool multi_thread_checkpoint(void)
}

// check the results
for(int thread = 0; thread < num_threads; thread++)
for(size_t thread = 0; thread < num_threads; thread++)
{ double check = double( n_sum_ * (thread + 1) );
ok &= check == y[thread];
}
Expand Down
4 changes: 2 additions & 2 deletions test_more/general/base_adolc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
CppAD is distributed under multiple licenses. This distribution is under
the terms of the
Expand Down Expand Up @@ -32,7 +32,7 @@ bool base_adolc(void)
CPPAD_TESTVECTOR(ADDdouble) aa_x(n);

// value of the independent variables
int tag = 0; // Adolc setup
short tag = 0; // Adolc setup
int keep = 1;
trace_on(tag, keep);
size_t j;
Expand Down
5 changes: 3 additions & 2 deletions test_more/general/eigen_mat_inv.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
CppAD is distributed under multiple licenses. This distribution is under
the terms of the
Expand Down Expand Up @@ -37,6 +37,7 @@ y[3] = x[0] / (x[0] * x[1] + 2)
bool non_symmetric(void)
{
bool ok = true;
using Eigen::Index;
// -------------------------------------------------------------------
// object that computes inverse of a 2x2 matrix
atomic_eigen_mat_inv<scalar> mat_inv;
Expand Down Expand Up @@ -65,7 +66,7 @@ bool non_symmetric(void)
CPPAD_TESTVECTOR(ad_scalar) ad_y(4);
for(size_t i = 0; i < nr; i++)
for(size_t j = 0; j < nr; j++)
ad_y[ i * nr + j ] = ad_result(i, j);
ad_y[ i * nr + j ] = ad_result( Index(i), Index(j) );
/* Used to test hand calculated derivaives
CppAD::AD<scalar> ad_dinv = 1.0 / (ad_x[0] * ad_x[1] + 2.0);
ad_y[0] = ad_x[1] * ad_dinv;
Expand Down
4 changes: 2 additions & 2 deletions test_more/general/mul_level.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
CppAD is distributed under multiple licenses. This distribution is under
the terms of the
Expand Down Expand Up @@ -174,7 +174,7 @@ bool adolc(void)
CPPAD_TESTVECTOR(ADDdouble) aa_x(n);

// value of the independent variables
int tag = 0; // Adolc setup
short tag = 0; // Adolc setup
int keep = 1;
trace_on(tag, keep);
size_t j;
Expand Down
30 changes: 15 additions & 15 deletions test_more/general/new_dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ bool operator_with_variable(void)

// range space vector
CPPAD_TESTVECTOR(AD<double>) ay(n);
int k = 0;
ay[k] = double(-k-1)*(adynamic[k] + ax[k]) * (ax[k] + adynamic[k]);
size_t k = 0;
ay[k] = -1.0*(k+1)*(adynamic[k] + ax[k]) * (ax[k] + adynamic[k]);
++k;
ay[k] = double(-k-1)*(adynamic[k] - ax[k]) * (ax[k] - adynamic[k]);
ay[k] = -1.0*(k+1)*(adynamic[k] - ax[k]) * (ax[k] - adynamic[k]);
++k;
ay[k] = double(-k-1)*(adynamic[k] * ax[k]) + (ax[k] * adynamic[k]);
ay[k] = -1.0*(k+1)*(adynamic[k] * ax[k]) + (ax[k] * adynamic[k]);
++k;
ay[k] = double(-k-1)*(adynamic[k] / ax[k]) + (ax[k] / adynamic[k]);
ay[k] = -1.0*(k+1)*(adynamic[k] / ax[k]) + (ax[k] / adynamic[k]);
++k;
ay[k] = ax[k];
ay[k] += adynamic[k];
Expand Down Expand Up @@ -80,18 +80,18 @@ bool operator_with_variable(void)
double check;
k = 0;
check = ( Value(adynamic[k]) + x[k] ) * ( x[k] + Value(adynamic[k]) );
check *= double(-k-1);
check *= -1.0*(k+1);
ok &= NearEqual(y[k] , check, eps, eps);
++k;
check = ( Value(adynamic[k]) - x[k] ) * ( x[k] - Value(adynamic[k]) );
check *= double(-k-1);
check *= -1.0*(k+1);
ok &= NearEqual(y[k] , check, eps, eps);
++k;
check = double(-k-1)*( Value(adynamic[k]) * x[k] );
check = -1.0*(k+1)*( Value(adynamic[k]) * x[k] );
check += ( x[k] * Value(adynamic[k]) );
ok &= NearEqual(y[k] , check, eps, eps);
++k;
check = double(-k-1)*( Value(adynamic[k]) / x[k] );
check = -1.0*(k+1)*( Value(adynamic[k]) / x[k] );
check += ( x[k] / Value(adynamic[k]) );
ok &= NearEqual(y[k] , check, eps, eps);
++k;
Expand Down Expand Up @@ -126,16 +126,16 @@ bool operator_with_variable(void)
//
y = f.Forward(0, x);
k = 0;
check = double(-k-1)*( dynamic[k] + x[k] ) * ( x[k] + dynamic[k] );
check = -1.0*(k+1)*( dynamic[k] + x[k] ) * ( x[k] + dynamic[k] );
ok &= NearEqual(y[k] , check, eps, eps);
++k;
check = double(-k-1)*( dynamic[k] - x[k] ) * ( x[k] - dynamic[k] );
check = -1.0*(k+1)*( dynamic[k] - x[k] ) * ( x[k] - dynamic[k] );
ok &= NearEqual(y[k] , check, eps, eps);
++k;
check = double(-k-1)*( dynamic[k] * x[k] ) + ( x[k] * dynamic[k] );
check = -1.0*(k+1)*( dynamic[k] * x[k] ) + ( x[k] * dynamic[k] );
ok &= NearEqual(y[k] , check, eps, eps);
++k;
check = double(-k-1)*( dynamic[k] / x[k] ) + ( x[k] / dynamic[k] );
check = -1.0*(k+1)*( dynamic[k] / x[k] ) + ( x[k] / dynamic[k] );
ok &= NearEqual(y[k] , check, eps, eps);
++k;
check = x[k] + dynamic[k];
Expand Down Expand Up @@ -192,7 +192,7 @@ bool dynamic_operator(void)
ny += 6;
# endif
CPPAD_TESTVECTOR(AD<double>) ay(ny);
int k = 0;
size_t k = 0;
// ----------------------------------------------------------
// 98 standard math
ay[k] = acos(adynamic[0]);
Expand Down Expand Up @@ -367,7 +367,7 @@ bool dynamic_operator(void)
check = CppAD::CondExpEq(dynamic[0], 0.5, 1.0, -1.0);
++k;
// ----------------------------------------------------------
ok &= size_t(k) == ny;
ok &= k == ny;
//
return ok;
}
Expand Down
10 changes: 5 additions & 5 deletions test_more/general/to_string.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
CppAD is distributed under multiple licenses. This distribution is under
the terms of the
Expand All @@ -19,8 +19,8 @@ namespace {
bool test(void)
{ bool ok = true;
Float eps = std::numeric_limits<Float>::epsilon();
Float pi = 4.0 * std::atan(1.0);
Float e = std::exp(1.0);
Float pi = Float( 4.0 * std::atan(1.0) );
Float e = Float( std::exp(1.0) );
typedef std::complex<Float> Base;
Base c = Base(pi, e);
std::string s = CppAD::to_string( CppAD::AD<Base>(c) );
Expand All @@ -35,10 +35,10 @@ namespace {
while( s[index] != ')' )
imag += s[index++];
//
Float check = std::atof( real.c_str() );
Float check = Float( std::atof( real.c_str() ) );
ok &= std::fabs( check / pi - 1.0 ) <= 2.0 * eps;
//
check = std::atof( imag.c_str() );
check = Float( std::atof( imag.c_str() ) );
ok &= std::fabs( check / e - 1.0 ) <= 2.0 * eps;
//
return ok;
Expand Down

0 comments on commit e6711c8

Please sign in to comment.