1#ifndef CPPAD_CG_LANGUAGE_DOT_INDEX_PATTERNS_INCLUDED
2#define CPPAD_CG_LANGUAGE_DOT_INDEX_PATTERNS_INCLUDED
23inline void LanguageDot<Base>::generateNames4RandomIndexPatterns(
const std::set<RandomIndexPattern*>&
randomPatterns) {
24 std::ostringstream os;
31 if (!
ip->getName().empty()) {
39 if (
ip->getName().empty()) {
43 os << _C_STATIC_INDEX_ARRAY <<
c;
61 _code <<
"subgraph index {" << _endline;
62 _code <<
" rank=same" << _endline;
64 os <<
"idx_" <<
ip->getName() <<
"[label=\"";
65 if (
ip->getType() == IndexPatternType::Random1D) {
70 const std::map<size_t, size_t>&
x2y =
ip1->getValues();
72 std::vector<size_t>
y(
x2y.rbegin()->first + 1);
73 for (
const std::pair<size_t, size_t>&
p :
x2y)
74 y[
p.first] =
p.second;
76 printStaticIndexArray(os,
ip->getName(),
y);
78 CPPADCG_ASSERT_UNKNOWN(
ip->getType() == IndexPatternType::Random2D);
83 printStaticIndexMatrix(os,
ip->getName(),
ip2->getValues());
89 _code <<
"}" << _endline;
94 const std::string& name,
95 const std::vector<size_t>& values) {
97 for (
size_t i = 0;
i < values.size();
i++) {
106void LanguageDot<Base>::printStaticIndexMatrix(std::ostringstream& os,
107 const std::string& name,
108 const std::map<
size_t, std::map<size_t, size_t> >& values) {
109 std::map<size_t, std::map<size_t, size_t> >::const_iterator
it;
110 std::map<size_t, size_t>::const_iterator
ity2z;
113 for (
it = values.begin();
it != values.end(); ++
it) {
114 if (
it != values.begin())
115 os <<
it->first <<
",\\n";
116 os <<
it->first <<
":[";
120 while (
ity2z->first !=
y) {
121 if (
y > 0) os <<
", ";
127 if (
y > 0) os <<
", ";
138inline void LanguageDot<Base>::indexPattern2String(std::ostream& os,
139 const IndexPattern&
ip,
141 indexPattern2String(os,
ip,{&index});
145inline void LanguageDot<Base>::indexPattern2String(std::ostream& os,
146 const IndexPattern&
ip,
148 std::stringstream
ss;
149 switch (
ip.getType()) {
150 case IndexPatternType::Linear:
152 CPPADCG_ASSERT_KNOWN(indexes.size() == 1,
"Invalid number of indexes")
154 linearIndexPattern2String(os,
lip, *indexes[0]);
157 case IndexPatternType::Sectioned:
159 CPPADCG_ASSERT_KNOWN(indexes.size() == 1,
"Invalid number of indexes")
163 CPPADCG_ASSERT_UNKNOWN(
sSize > 1);
165 std::map<
size_t, IndexPattern*>::const_iterator
its =
sections.begin();
166 for (
size_t s = 0; s <
sSize - 1; s++) {
167 const IndexPattern*
lp =
its->second;
171 os << (*indexes[0]->getName()) <<
" < " <<
xStart <<
")? ";
172 indexPattern2String(os, *
lp, *indexes[0]);
175 indexPattern2String(os, *
its->second, *indexes[0]);
180 case IndexPatternType::Plane2D:
182 CPPADCG_ASSERT_KNOWN(indexes.size() >= 1,
"Invalid number of indexes")
184 bool useParens =
pip.getPattern1() !=
nullptr &&
pip.getPattern2() !=
nullptr;
188 if (
pip.getPattern1() !=
nullptr)
189 indexPattern2String(os, *
pip.getPattern1(), *indexes[0]);
193 if (
pip.getPattern2() !=
nullptr)
194 indexPattern2String(os, *
pip.getPattern2(), *indexes.back());
200 case IndexPatternType::Random1D:
202 CPPADCG_ASSERT_KNOWN(indexes.size() == 1,
"Invalid number of indexes")
204 CPPADCG_ASSERT_KNOWN(!
rip.getName().empty(), "
Invalid name
for array")
205 os <<
rip.getName() << "[" << (*indexes[0]->getName()) << "]";
208 case IndexPatternType::Random2D:
210 CPPADCG_ASSERT_KNOWN(indexes.size() == 2,
"Invalid number of indexes")
212 CPPADCG_ASSERT_KNOWN(!
rip.getName().empty(), "
Invalid name
for array")
213 os <<
rip.getName() <<
214 "[" << (*indexes[0]->getName()) << "]"
215 "[" << (*indexes[1]->getName()) << "]";
219 CPPADCG_ASSERT_UNKNOWN(
false);
225inline void LanguageDot<Base>::linearIndexPattern2String(std::ostream& os,
227 const OperationNode<Base>& index) {
228 long dy =
lip.getLinearSlopeDy();
229 long dx =
lip.getLinearSlopeDx();
230 long b =
lip.getLinearConstantTerm();
237 os << (*index.getName());
void printRandomIndexPatternDeclaration(std::ostringstream &os, const std::set< RandomIndexPattern * > &randomPatterns)
bool GreaterThanZero(const cg::CG< Base > &x)