37 bool cacheSparsities_;
40 std::map<size_t, CppAD::vector<std::set<size_t> > > hess_;
62 this->
option(CppAD::atomic_base<CGB>::set_sparsity_enum);
70 template <
class ADVector>
75 template<
class VectorSize>
76 inline void setCustomSparseJacobianElements(
const VectorSize& row,
78 custom_jac_ = CustomPosition(fun_.Range(), fun_.Domain(), row, col);
81 template<
class VectorSet>
82 inline void setCustomSparseJacobianElements(
const VectorSet& elements) {
83 custom_jac_ = CustomPosition(fun_.Range(), fun_.Domain(), elements);
86 template<
class VectorSize>
87 inline void setCustomSparseHessianElements(
const VectorSize& row,
89 size_t n = fun_.Domain();
90 custom_hess_ = CustomPosition(
n,
n, row, col);
93 template<
class VectorSet>
94 inline void setCustomSparseHessianElements(
const VectorSet& elements) {
95 size_t n = fun_.Domain();
96 custom_hess_ = CustomPosition(
n,
n, elements);
99 bool for_sparse_jac(
size_t q,
103 return for_sparse_jac(
q,
r, s);
106 bool for_sparse_jac(
size_t q,
111 if (cacheSparsities_ || custom_jac_.isFilterDefined()) {
112 size_t n = fun_.Domain();
113 size_t m = fun_.Range();
114 if (!custom_jac_.isFullDefined()) {
115 custom_jac_.setFullElements(jacobianForwardSparsitySet<std::vector<std::set<size_t> > >(fun_));
116 fun_.size_forward_set(0);
119 for (
size_t i = 0;
i < s.size();
i++) {
122 CppAD::cg::multMatrixMatrixSparsity(custom_jac_.getFullElements(),
r, s, m,
n,
q);
124 s = fun_.ForSparseJac(
q,
r);
125 fun_.size_forward_set(0);
131 bool rev_sparse_jac(
size_t q,
135 return rev_sparse_jac(
q,
rt,
st);
138 bool rev_sparse_jac(
size_t q,
143 if (cacheSparsities_ || custom_jac_.isFilterDefined()) {
144 size_t n = fun_.Domain();
145 size_t m = fun_.Range();
146 if (!custom_jac_.isFullDefined()) {
147 custom_jac_.setFullElements(jacobianReverseSparsitySet<std::vector<std::set<size_t> > >(fun_));
150 for (
size_t i = 0;
i <
st.size();
i++) {
153 CppAD::cg::multMatrixMatrixSparsityTrans(
rt, custom_jac_.getFullElements(),
st, m,
n,
q);
155 st = fun_.RevSparseJac(
q,
rt,
true);
169 return rev_sparse_hes(
vx, s,
t,
q,
r,
u, v);
181 if (cacheSparsities_ || custom_jac_.isFilterDefined() || custom_hess_.isFilterDefined()) {
182 size_t n = fun_.Domain();
183 size_t m = fun_.Range();
185 for (
size_t i = 0;
i <
n;
i++) {
189 if (!custom_jac_.isFullDefined()) {
190 custom_jac_.setFullElements(jacobianSparsitySet<std::vector<std::set<size_t> > >(fun_));
192 const std::vector<std::set<size_t> >&
jacSparsity = custom_jac_.getFullElements();
198 CppAD::cg::multMatrixTransMatrixSparsity(
jacSparsity,
u, v, m,
n,
q);
202 for (
size_t i = 0;
i < m;
i++) {
210 if (!custom_hess_.isFullDefined()) {
211 custom_hess_.setFullElements(hessianSparsitySet<std::vector<std::set<size_t> > >(fun_));
213 const std::vector<std::set<size_t> >&
sF2 = custom_hess_.getFullElements();
214 CppAD::cg::multMatrixTransMatrixSparsity(
sF2,
r, v,
n,
n,
q);
217 for (
size_t i = 0;
i < m;
i++) {
219 const auto itH = hess_.find(
i);
221 if (
itH == hess_.end()) {
224 custom_hess_.filter(
hi);
237 for (
size_t i = 0;
i < m;
i++) {
245 size_t m = fun_.Range();
246 size_t n = fun_.Domain();
248 t = fun_.RevSparseJac(1, s);
253 for (
size_t i = 0;
i < m;
i++) {
258 fun_.ForSparseJac(
q,
r);
259 v = fun_.RevSparseHes(
q,
set_s,
true);
261 for (
size_t i = 0;
i <
n;
i++) {
262 for (
size_t j :
a[
i]) {
268 fun_.size_forward_set(0);
279 CppAD::cg::zeroOrderDependency(fun_,
vx,
vy);
294 fun_.capacity_order(0);
312 fun_.Forward(
p,
txcg);
317 fun_.capacity_order(0);
337 CPPADCG_ASSERT_KNOWN(
from[
i].isValueDefined(),
"No value defined")
bool rev_sparse_hes(const CppAD::vector< bool > &vx, const CppAD::vector< bool > &s, CppAD::vector< bool > &t, size_t q, const CppAD::vector< std::set< size_t > > &r, const CppAD::vector< std::set< size_t > > &u, CppAD::vector< std::set< size_t > > &v) override