1 #ifndef CPPAD_CG_LANGUAGE_DOT_INDEX_PATTERNS_INCLUDED 2 #define CPPAD_CG_LANGUAGE_DOT_INDEX_PATTERNS_INCLUDED 23 inline void LanguageDot<Base>::generateNames4RandomIndexPatterns(
const std::set<RandomIndexPattern*>& randomPatterns) {
24 std::ostringstream os;
26 std::set<std::string> usedNames;
30 for (RandomIndexPattern* ip : randomPatterns) {
31 if (!ip->getName().empty()) {
32 usedNames.insert(ip->getName());
38 for (RandomIndexPattern* ip : randomPatterns) {
39 if (ip->getName().empty()) {
43 os << _C_STATIC_INDEX_ARRAY << c;
47 }
while (usedNames.find(name) != usedNames.end());
57 const std::set<RandomIndexPattern*>& randomPatterns) {
58 if (randomPatterns.empty())
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 auto& 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++) {
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 <<
":[";
118 for (ity2z = it->second.begin(); ity2z != it->second.end(); ++ity2z) {
119 if (ity2z->first != y) {
120 while (ity2z->first != y) {
121 if (y > 0) os <<
", ";
127 if (y > 0) os <<
", ";
141 indexPattern2String(os, ip,{&index});
148 std::stringstream ss;
149 switch (ip.getType()) {
150 case IndexPatternType::Linear:
152 CPPADCG_ASSERT_KNOWN(indexes.size() == 1,
"Invalid number of indexes")
153 const auto& lip = static_cast<const LinearIndexPattern&> (ip);
154 linearIndexPattern2String(os, lip, *indexes[0]);
157 case IndexPatternType::Sectioned:
159 CPPADCG_ASSERT_KNOWN(indexes.size() == 1,
"Invalid number of indexes")
160 const auto* lip = static_cast<const SectionedIndexPattern*> (&ip);
161 const std::map<size_t, IndexPattern*>& sections = lip->getLinearSections();
162 size_t sSize = sections.size();
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++) {
169 size_t xStart = its->first;
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")
183 const auto& pip = static_cast<const Plane2DIndexPattern&> (ip);
184 bool useParens = pip.getPattern1() !=
nullptr && pip.getPattern2() !=
nullptr;
186 if (useParens) os <<
"(";
188 if (pip.getPattern1() !=
nullptr)
189 indexPattern2String(os, *pip.getPattern1(), *indexes[0]);
191 if (useParens) os <<
") + (";
193 if (pip.getPattern2() !=
nullptr)
194 indexPattern2String(os, *pip.getPattern2(), *indexes.back());
196 if (useParens) os <<
")";
200 case IndexPatternType::Random1D:
202 CPPADCG_ASSERT_KNOWN(indexes.size() == 1,
"Invalid number of indexes")
203 const auto& rip = static_cast<const Random1DIndexPattern&> (ip);
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")
211 const auto& rip = static_cast<const Random2DIndexPattern&> (ip);
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);
228 long dy = lip.getLinearSlopeDy();
229 long dx = lip.getLinearSlopeDx();
230 long b = lip.getLinearConstantTerm();
231 long xOffset = lip.getXOffset();
239 os <<
" -" << xOffset <<
")";
const std::string * getName() const
void printRandomIndexPatternDeclaration(std::ostringstream &os, const std::set< RandomIndexPattern *> &randomPatterns)