Skip to content

Commit

Permalink
master: vec_ad.cpp: test_funciton: test reverse hessian sparsity.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbell committed Nov 12, 2024
1 parent 27a4693 commit 2b419a6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ IF( POLICY CMP0054 )
ENDIF( POLICY CMP0054 )
#
# cppad_version is used by version.sh to get the version number.
SET(cppad_version "20241111")
SET(cppad_version "20241112")
SET(cppad_url "https://coin-or.github.io/CppAD" )
SET(cppad_description "Differentiation of C++ Algorithms" )
IF( NOT DEFINED CMAKE_BUILD_TYPE)
Expand Down
4 changes: 2 additions & 2 deletions include/cppad/core/rev_hes_sparsity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# define CPPAD_CORE_REV_HES_SPARSITY_HPP
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
// SPDX-FileContributor: 2003-23 Bradley M. Bell
// SPDX-FileContributor: 2003-24 Bradley M. Bell
// ----------------------------------------------------------------------------
/*
{xrst_begin rev_hes_sparsity}
Expand Down Expand Up @@ -106,7 +106,7 @@ Sparsity for Entire Hessian
***************************
Suppose that :math:`R` is the :math:`n \times n` identity matrix.
In this case, *pattern_out* is a sparsity pattern for
:math:`(s^\R{T} F) F^{(2)} ( x )`.
:math:`(s^\R{T} F)^{(2)} ( x )`.
Example
*******
Expand Down
60 changes: 59 additions & 1 deletion test_more/general/vec_ad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ bool jac_sparsity_test_function(CppAD::ADFun<double>& fun)
size_t nr = 5, nc = 5, nnz = 0;
sparse_rc pattern_check(nr, nc, nnz);
for(size_t i = 0; i < nr; ++i)
{ // values in v depend on x_2 and x_3
{ // values in v depend on x_2 and x_3
pattern_check.push_back(i, 2);
pattern_check.push_back(i, 3);
if( dependency )
Expand Down Expand Up @@ -537,6 +537,63 @@ bool jac_sparsity_test_function(CppAD::ADFun<double>& fun)
return ok;
}

bool hes_sparsity_test_function(CppAD::ADFun<double>& fun)
{ //
// ok
bool ok = true;
//
// size_vector
typedef CppAD::vector<size_t> size_vector;
//
// sparse_rc
typedef CppAD::sparse_rc<size_vector> sparse_rc;
//
// pattern_check
size_t nr = 5, nc = 5, nnz = 0;
sparse_rc pattern_check(nr, nc, nnz);
for(int r : {2, 3} )
{ for(int c : {2, 3} )
pattern_check.push_back(size_t(r), size_t(c));
}
//
// pattern_eye
nr = 5, nc = 5, nnz = 5;
sparse_rc pattern_eye(nr, nc, nnz);
for(size_t k = 0; k < nr; ++k)
pattern_eye.set(k, k, k);
//
// pattern_jac
sparse_rc pattern_jac;
bool dependency = false;
bool transpose = false;
bool internal_bool = false;
fun.for_jac_sparsity(
pattern_eye, transpose, dependency, internal_bool, pattern_jac
);
//
// select_range
CPPAD_TESTVECTOR(bool) select_range(5);
for(size_t i = 0; i < 5; ++i)
select_range[i] = false;
//
// i
for(size_t i = 0; i < 5; ++i)
{ //
// pattern_hes
sparse_rc pattern_hes;
select_range[i] = true;
fun.rev_hes_sparsity(
select_range, transpose, internal_bool, pattern_hes
);
select_range[i] = false;
//
// ok
ok &= pattern_hes == pattern_check;
}
//
return ok;
}

} // END empty namespace

bool VecAD(void)
Expand All @@ -553,6 +610,7 @@ bool VecAD(void)
ok &= forward_zero_test_function(fun, x);
ok &= forward_one_test_function(fun, x);
ok &= jac_sparsity_test_function(fun);
ok &= hes_sparsity_test_function(fun);
//
return ok;
}
2 changes: 1 addition & 1 deletion user_guide.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{xrst_comment BEGIN: Before changing see new_release.sh and check_version.sh}

cppad-20241111: CppAD User's Manual
cppad-20241112: CppAD User's Manual
###################################
{xrst_comment The scripts bin/check_version.sh and bin/new_release.sh
edit version numbers in tables below.}
Expand Down

0 comments on commit 2b419a6

Please sign in to comment.