atomic_four_hes_sparsity

View page source

Atomic Function Hessian Sparsity Patterns

Syntax

Preferred

ok = afun . hes_sparsity ( call_id ,
      ident_zero_x , select_x , select_y , pattern_out
)

Deprecated 2022-05-16

ok = afun . hes_sparsity ( call_id ,
      select_x , select_y , pattern_out
)

Prototype

template <class Base>
bool atomic_four<Base>::hes_sparsity(
   size_t                                  call_id      ,
   const vector<bool>&                     ident_zero_x ,
   const vector<bool>&                     select_x     ,
   const vector<bool>&                     select_y     ,
   sparse_rc< vector<size_t> >&            pattern_out  )

Implementation

This function must be defined if afun is used to define an ADFun object f , and Hessian sparsity patterns are computed for f .

Base

See Base .

vector

is the CppAD_vector template class.

call_id

See call_id .

ident_zero_x

This can sometimes be used to create more efficient sparsity patterns. If you do not see a way to do this, you can just ignore it. This argument has size equal to the number of arguments to this atomic function; i.e. the size of ax . If ident_zero_x [ j ] is true, the argument ax [ j ] is a constant parameter that is identically zero. An identically zero value times any other value can be treated as being identically zero.

select_x

This argument has size equal to the number of arguments to this atomic function; i.e. the size of ax . It specifies which domain components are included in the calculation of pattern_out . If select_x [ j ] is false, then there will be no indices k such that either of the following hold:

      pattern_out . row ()[ k ] == j
      pattern_out . col ()[ k ] == j

.

select_y

This argument has size equal to the number of results to this atomic function; i.e. the size of ay . It specifies which range component functions \(g_i (x)\) are included in of pattern_out .

pattern_out

This input value of pattern_out does not matter. Upon return it is the union, with respect to i such that select_y [ i ] is true, of the sparsity pattern for Hessian of \(g_i (x)\). To be specific, there are non-negative indices r , c , and k such that

      pattern_out . row ()[ k ] == r
      pattern_out . col ()[ k ] == c

if and only if there exists an index i such that, select_y [ i ] is true, select_x [ r ] is true, select_x [ c ] is true, and

\[\partial_{x(r)} \partial_{x(c)} g_i(x)\]

is possibly non-zero. Note that the sparsity pattern should be symmetric.

ok

If this calculation succeeded, ok is true. Otherwise it is false.

Example

The following is an example hes_sparsity definition taken from atomic_four_norm_sq.cpp :

      // Use deprecated version of this callback to test that is still works
      // (missing the ident_zero_x argument).
      bool hes_sparsity(
         size_t                                     call_id     ,
         // const CppAD::vector<bool>&              ident_zero_x,
         const CppAD::vector<bool>&                 select_x    ,
         const CppAD::vector<bool>&                 select_y    ,
         CppAD::sparse_rc< CppAD::vector<size_t> >& pattern_out ) override
      {  size_t n = select_x.size();
# ifndef NDEBUG
         size_t m = select_y.size();
         assert( call_id == 0 );
         assert( m == 1 );
# endif
         // nnz
         size_t nnz = 0;
         if( select_y[0] )
         {  for(size_t j = 0; j < n; ++j)
            {  if( select_x[j] )
                  ++nnz;
            }
         }
         // pattern_out
         pattern_out.resize(n, n, nnz);
         size_t k = 0;
         if( select_y[0] )
         {  for(size_t j = 0; j < n; ++j)
            {  if( select_x[j] )
                  pattern_out.set(k++, j, j);
            }
         }
         return true;
      }