1#ifndef CPPAD_CG_LOOP_FREE_MODEL_INCLUDED
2#define CPPAD_CG_LOOP_FREE_MODEL_INCLUDED
33 using VectorSet = std::vector<std::set<size_t> >;
43 std::map<size_t, size_t> dependentOrig2Local;
74 hessSparsity_(
false) {
75 CPPADCG_ASSERT_KNOWN(
fun !=
nullptr,
"fun cannot be null")
89 inline size_t getTapeDependentCount()
const {
93 inline size_t getTemporaryDependentCount()
const {
97 inline size_t getTapeIndependentCount()
const {
98 return fun_->Domain();
109 inline size_t getLocalDependentIndex(
size_t origI)
const {
110 return dependentOrig2Local.at(
origI);
113 inline void evalJacobianSparsity() {
120 inline const VectorSet& getJacobianSparsity()
const {
124 inline void evalHessianSparsity() {
125 if (!hessSparsity_) {
127 size_t m =
fun_->Range();
128 size_t n =
fun_->Domain();
131 std::set<size_t>
eqs;
133 for (
size_t i = 0;
i <
mo;
i++)
142 for (
size_t i =
mo;
i < m;
i++)
149 hessSparsity_ =
true;
153 inline const VectorSet& getHessianTempEqsSparsity()
const {
154 CPPADCG_ASSERT_UNKNOWN(hessSparsity_)
158 inline const VectorSet& getHessianOrigEqsSparsity()
const {
159 CPPADCG_ASSERT_UNKNOWN(hessSparsity_)
174 const std::set<size_t>& iterations,
188 if (value.isIdenticalZero())
237 const std::vector<CGB>& x,
238 std::vector<CGB>&
temps,
242 using namespace CppAD::cg::loops;
244 CPPADCG_ASSERT_UNKNOWN(hessSparsity_)
247 size_t m = getTapeDependentCount();
248 size_t n =
fun_->Domain();
256 std::vector<std::set<size_t> > noLoopEvalHessTempsSparsity(
n);
261 addMatrixSparsity(
info.noLoopEvalHessTempsSparsity, noLoopEvalHessTempsSparsity);
264 generateSparsityIndexes(noLoopEvalHessTempsSparsity,
hesRow,
hesCol);
271 const std::vector<IterEquationGroup<Base> >&
eqGroups =
loop->getEquationsGroups();
285 if (
posK !=
nullptr) {
292 for (
size_t tapeI : group.
tapeI) {
293 const map<size_t, CGB>& row =
info.dyiDzk[tapeI];
294 typename map<size_t, CGB>::const_iterator
itCol = row.find(
posK->tape);
295 if (
itCol != row.end()) {
308 *
info.iterationIndexOp);
319 std::vector<map<size_t, CGB> >
dyDx;
321 getJacobianSparsity(),
325 noLoopEvalHessTempsSparsity,
330 map<size_t, map<size_t, CGB> >
dzDx;
349 const std::vector<CGB>& w,
352 std::vector<CGB>& hess) {
354 using namespace CppAD::cg::loops;
356 CPPADCG_ASSERT_UNKNOWN(hessSparsity_)
358 std::vector<CGB>
wNoLoop(getTapeDependentCount());
364 std::vector<size_t> row, col;
378 work.color_method =
"cppad.general";
382 for (
size_t el = 0;
el < row.size();
el++) {
386 for (
size_t itE : locations)
std::set< size_t > tapeI
equations indexes in tape of the loop model
std::set< size_t > iterations
iterations which only have these equations defined
const std::vector< size_t > & getOrigDependentIndexes() const
VectorSet jacTapeSparsity_
std::map< size_t, std::map< size_t, CGB > > calculateJacobianHessianUsedByLoops(CodeHandler< Base > &handler, std::map< LoopModel< Base > *, loops::HessianWithLoopsInfo< Base > > &loopHessInfo, const std::vector< CGB > &x, std::vector< CGB > &temps, const VectorSet &noLoopEvalJacSparsity, bool individualColoring)
std::vector< size_t > dependentIndexes_
VectorSet hessTapeTempSparsity_
VectorSet hessTapeOrigEqSparsity_
LoopFreeModel(ADFun< CGB > *fun, const std::vector< size_t > &dependentOrigIndexes)
void calculateHessian4OrignalEquations(const std::vector< CGB > &x, const std::vector< CGB > &w, const VectorSet &noLoopEvalHessSparsity, const std::vector< std::map< size_t, std::set< size_t > > > &noLoopEvalHessLocations, std::vector< CGB > &hess)
CG< Base > createConditionalOperation(CodeHandler< Base > &handler, const std::set< size_t > &iterations, size_t iterCount, const CG< Base > &value, IndexOperationNode< Base > &iterationIndexOp)
bool GreaterThanZero(const cg::CG< Base > &x)