Loading [MathJax]/extensions/tex2jax.js
Prev
Next
Index->
contents
reference
index
search
external
Up->
CppAD
AD
ADValued
atomic
atomic_four
atomic_four_example
atomic_four_mat_mul
atomic_four_mat_mul_implement
atomic_four_mat_mul_hes_sparsity.hpp
atomic_four_example-> atomic_four_get_started.cpp atomic_four_norm_sq.cpp atomic_four_forward.cpp atomic_four_dynamic.cpp atomic_four_vector atomic_four_mat_mul atomic_four_lin_ode
atomic_four_mat_mul-> atomic_four_mat_mul_implement atomic_four_mat_mul_forward.cpp atomic_four_mat_mul_reverse.cpp atomic_four_mat_mul_sparsity.cpp atomic_four_mat_mul_rev_depend.cpp atomic_four_mat_mul_identical_zero.cpp
atomic_four_mat_mul_implement-> atomic_four_mat_mul.hpp atomic_four_mat_mul_set.hpp atomic_four_mat_mul_get.hpp atomic_four_mat_mul_base_mat_mul.hpp atomic_four_mat_mul_for_type.hpp atomic_four_mat_mul_forward.hpp atomic_four_mat_mul_reverse.hpp atomic_four_mat_mul_jac_sparsity.hpp atomic_four_mat_mul_hes_sparsity.hpp atomic_four_mat_mul_rev_depend.hpp
atomic_four_mat_mul_hes_sparsity.hpp
Headings->
Purpose
Example
Source
@(@\newcommand{\W}[1]{ \; #1 \; }
\newcommand{\R}[1]{ {\rm #1} }
\newcommand{\B}[1]{ {\bf #1} }
\newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} }
\newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} }
\newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} }
\newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@This is cppad-20221105 documentation . Here is a link to its
current documentation
.
Atomic Matrix Multiply Jacobian Sparsity Pattern: Example Implementation
Purpose
The hes_sparsity
routine overrides the virtual functions
used by the atomic_four base class for Jacobian sparsity calculations; see
hes_sparsity
.
Example
The file atomic_four_mat_mul_sparsity.cpp
contains an example and test using this operator.
Source
# include <cppad/example/atomic_four/mat_mul/mat_mul.hpp>
namespace CppAD { // BEGIN_CPPAD_NAMESPACE
//
// hes_sparsity override
template < class Base >
bool atomic_mat_mul< Base>:: 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 )
{
// n_left, n_middle, n_right
size_t n_left, n_middle, n_right;
get ( call_id, n_left, n_middle, n_right);
//
// n
size_t n = select_x. size ();
//
// check sizes
# ifndef NDEBUG
size_t m = select_y. size ();
assert ( n == n_middle * ( n_left + n_right ) );
assert ( m == n_left * n_right );
# endif
//
// offset
size_t offset = n_left * n_middle;
//
// pattern_out
pattern_out. resize ( n, n, 0 );
for ( size_t i = 0 ; i < n_left; ++ i)
{ for ( size_t j = 0 ; j < n_right; ++ j)
{ size_t ij = i * n_right + j; // C_{i,j} = y[ij]
if ( select_y[ ij] ) for ( size_t k = 0 ; k < n_middle; ++ k)
{ size_t ik = i * n_middle + k; // A_{i,k} = x[ik]
size_t kj = offset + k * n_right + j; // B_{k,j} = x[kj]
if ( select_x[ ik] & select_x[ kj] )
{ // an (ik, kj) pair can only occur once in this loop
pattern_out. push_back ( ik, kj);
pattern_out. push_back ( kj, ik);
}
}
}
}
# ifndef NDEBUG
// sorting checks hat there are no duplicate entries
pattern_out. row_major ();
# endif
//
return true ;
}
} // END_CPPAD_NAMESPACE
Input File: include/cppad/example/atomic_four/mat_mul/hes_sparsity.hpp