1#ifndef CPPAD_CG_SPARSE_FORJAC_HESSIAN_INCLUDED
2#define CPPAD_CG_SPARSE_FORJAC_HESSIAN_INCLUDED
43 template<
class Base,
class VectorSize>
51 size_t n =
fun.Domain();
52 size_t m =
fun.Range();
61 for (
size_t k = 0;
k <
K;
k++) {
74 "sparseForJacHessian: either r or c does not have "
75 "the same size as jac.")
79 "sparseForJacHessian: invalid value in work.")
80 for (
size_t k = 0;
k <
K;
k++) {
82 "sparseForJacHessian: invalid value in r.")
84 "sparseForJacHessian: invalid value in c.")
86 "sparseForJacHessian: invalid value in work.")
88 "sparseForJacHessian: invalid value in work.")
90 "sparseForJacHessian: invalid value in work.")
119 template<
class Base,
class VectorSize>
126 size_t n =
fun.Domain();
138 for (
size_t k = 0;
k <
K;
k++) {
146 "sparseForJacHessian: either r or c does not have the same size as ehs.")
150 "sparseForJacHessian: invalid value in work.")
151 for (
size_t k = 0;
k <
K;
k++) {
153 "sparseForJacHessian: invalid value in r.")
155 "sparseForJacHessian: invalid value in c.")
157 "sparseForJacHessian: invalid value in work.")
159 "sparseForJacHessian: invalid value in work.")
161 "sparseForJacHessian: invalid value in work.")
185 template<
class Base,
class VectorSize>
191 size_t n =
fun.Domain();
194 "sparseForJacHessian: invalid value in work.")
195 if (!
color.empty()) {
196 for (
size_t j = 0;
j <
n;
j++) {
198 "sparseForJacHessian: invalid value in work.")
214template<
class SparsityPattern>
220 using SparIter =
typename SparsityPattern::const_iterator;
225 for (
size_t i = 0;
i <
n;
i++) {
228 while (
j != sparsity.end()) {
236template<
class Base,
class VectorSet>
238 const VectorSet&
jac_p,
239 const VectorSet&
hes_p,
240 SparseForjacHessianWork&
work) {
247 using Set_type =
typename VectorSet::value_type;
248 using SparsityPattern =
typename local::sparse::internal_pattern<Set_type>::pattern_type;
249 using SparIter =
typename SparsityPattern::const_iterator;
251 size_t n =
fun.Domain();
252 size_t m =
fun.Range();
254 std::vector<size_t>& color =
work.color;
261 "sparseForJacHessian: invalid jacobian sparsity pattern dimension.")
277 std::vector<
size_t>& sort_col =
work.jac.sort_col;
291 "sparseForJacHessian: "
292 "a (row, col) pair is not in sparsity pattern.")
324 "sparseForJacHessian: a (row, col) pair is not in sparsity pattern.")
345 for (
c = 0;
c <=
j1;
c++)
490template<
class Base,
class VectorBase,
class VectorSet,
class VectorSize>
495 const VectorSet&
jac_p,
499 const VectorSet&
hes_p,
503 SparseForjacHessianWork&
work) {
504 std::vector<VectorBase>
vw(1);
505 std::vector<VectorBase>
vhes(1);
521template<
class Base,
class VectorBase,
class VectorVectorBase,
class VectorSet,
class VectorSize>
526 const VectorSet&
jac_p,
530 const VectorSet&
hes_p,
534 SparseForjacHessianWork&
work) {
538 size_t n =
fun.Domain();
539 size_t m =
fun.Range();
545 CPPADCG_ASSERT_KNOWN(
size_t(x.size()) ==
n,
546 "sparseForJacHessian: size of x not equal domain dimension for f.")
548 CPPADCG_ASSERT_KNOWN(
size_t(w.size()) ==
nH,
555 const std::vector<
size_t>& color =
work.color;
575 y =
fun.Forward(0, x);
602 if (color[
j1] ==
c) {
615 if (color[
j1] ==
c) {
639 if (color[
j1] ==
c) {
655 for (
size_t h = 0;
h <
nH;
h++) {
664 if (color[
j1] ==
c) {
size_t K
number elements in the user sparse Hessian
void clear()
inform CppAD that this information needs to be recomputed
std::vector< size_t > r_sort
version of user r array sorted by row or column
std::vector< size_t > k_sort
mapping from sorted array indices to user array indices
void prepare(const ADFun< Base > &fun, const VectorSize &row, const VectorSize &col)
std::vector< size_t > c_sort
version of user c array sorted by row or column
std::vector< size_t > sort_row
indices that sort the user arrays by row with the extra value K at the end
std::vector< size_t > user_row
version of user row array with the extra value m at end
void prepare(const ADFun< Base > &fun, const VectorSize &row, const VectorSize &col)
std::vector< size_t > sort_col
indices that sort the user arrays by column with the extra value K at the end
size_t K
number elements in the user sparse Jacobian
std::vector< size_t > user_col
version of user col array with the extra value n at end
void clear()
inform CppAD that this information needs to be recomputed
std::vector< size_t > color
results of the coloring algorithm
void clear()
inform CppAD that this information needs to be recomputed
bool GreaterThanZero(const cg::CG< Base > &x)