1 # ifndef CPPAD_CORE_CHKPOINT_ONE_SET_HES_SPARSE_BOOL_HPP
2 # define CPPAD_CORE_CHKPOINT_ONE_SET_HES_SPARSE_BOOL_HPP
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
5 
6 CppAD is distributed under the terms of the
7              Eclipse Public License Version 2.0.
8 
9 This Source Code may also be made available under the following
10 Secondary License when the conditions for such availability set forth
11 in the Eclipse Public License, Version 2.0 are satisfied:
12       GNU General Public License, Version 2.0 or later.
13 ---------------------------------------------------------------------------- */
14 
15 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
16 
17 template <class Base>
set_hes_sparse_bool(void)18 void checkpoint<Base>::set_hes_sparse_bool(void)
19 {   // make sure member_ is allocated for this thread
20     size_t thread = thread_alloc::thread_num();
21     allocate_member(thread);
22     //
23     CPPAD_ASSERT_UNKNOWN( member_[thread]->hes_sparse_bool_.size() == 0 );
24     size_t n = member_[thread]->f_.Domain();
25     size_t m = member_[thread]->f_.Range();
26     //
27     // set version of sparsity for vector of all ones
28     vectorBool all_one(m);
29     for(size_t i = 0; i < m; i++)
30         all_one[i] = true;
31 
32     // set version of sparsity for n by n idendity matrix
33     vectorBool identity(n * n);
34     for(size_t j = 0; j < n; j++)
35     {   for(size_t i = 0; i < n; i++)
36             identity[ i * n + j ] = (i == j);
37     }
38 
39     // compute sparsity pattern for H(x) = sum_i f_i(x)^{(2)}
40     bool transpose  = false;
41     bool dependency = false;
42     member_[thread]->f_.ForSparseJac(n, identity, transpose, dependency);
43     member_[thread]->hes_sparse_bool_ = member_[thread]->f_.RevSparseHes(n, all_one, transpose);
44     CPPAD_ASSERT_UNKNOWN( member_[thread]->hes_sparse_bool_.size() == n * n );
45     //
46     // drop the forward sparsity results from f_
47     member_[thread]->f_.size_forward_bool(0);
48     CPPAD_ASSERT_UNKNOWN( member_[thread]->f_.size_forward_bool() == 0 );
49     CPPAD_ASSERT_UNKNOWN( member_[thread]->f_.size_forward_set() == 0 );
50 }
51 
52 } // END_CPPAD_NAMESPACE
53 # endif
54