Skip to content

Commit 0938eab

Browse files
pcaspersjenkins
authored andcommitted
QPR-12028 more structured ssa form output (csv)
1 parent 541d273 commit 0938eab

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

QuantExt/qle/ad/ssaform.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::string getLabel(const ComputationGraph& g, const std::size_t i, const bool
3232
if (l != g.labels().end() && includeLabels) {
3333
for (auto tmp = l->second.begin(); tmp != l->second.end(); ++tmp) {
3434
label = label + (tmp == l->second.begin() ? "[" : "") + *tmp +
35-
(tmp != std::next(l->second.end(), -1) ? "," : "]");
35+
(tmp != std::next(l->second.end(), -1) ? ";" : "]");
3636
}
3737
}
3838
return label;
@@ -41,26 +41,30 @@ std::string getLabel(const ComputationGraph& g, const std::size_t i, const bool
4141

4242
template <class T>
4343
std::string ssaForm(const ComputationGraph& g, const std::vector<std::string>& opCodeLabels,
44-
const std::vector<T>& values) {
44+
const std::vector<T>& values, const std::vector<T>& values2) {
4545

4646
std::ostringstream os;
4747

4848
for (std::size_t i = 0; i < g.size(); ++i) {
4949

50-
os << i << ": " << getLabel(g, i);
50+
os << i << "," << getLabel(g, i);
5151

52+
os << ",";
5253
if (!g.predecessors(i).empty()) {
53-
os << " = ";
5454
os << (opCodeLabels.size() > g.opId(i) ? opCodeLabels[g.opId(i)] : "???") << "(";
5555
for (std::size_t j = 0; j < g.predecessors(i).size(); ++j) {
5656
auto p = g.predecessors(i)[j];
57-
os << getLabel(g, p, false) << (j < g.predecessors(i).size() - 1 ? ", " : "");
57+
os << getLabel(g, p, false) << (j < g.predecessors(i).size() - 1 ? ";" : "");
5858
}
5959
os << ")";
6060
}
6161

6262
if (values.size() > i) {
63-
os << " -> " << values[i];
63+
os << "," << values[i];
64+
}
65+
66+
if (values2.size() > i) {
67+
os << "," << values2[i];
6468
}
6569

6670
os << "\n";
@@ -70,8 +74,8 @@ std::string ssaForm(const ComputationGraph& g, const std::vector<std::string>& o
7074
}
7175

7276
template std::string ssaForm(const ComputationGraph& g, const std::vector<std::string>& opCodeLabels,
73-
const std::vector<double>& values);
77+
const std::vector<double>& values, const std::vector<double>& values2);
7478
template std::string ssaForm(const ComputationGraph& g, const std::vector<std::string>& opCodeLabels,
75-
const std::vector<RandomVariable>& values);
79+
const std::vector<RandomVariable>& values, const std::vector<RandomVariable>& values2);
7680

7781
} // namespace QuantExt

QuantExt/qle/ad/ssaform.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ namespace QuantExt {
3030

3131
template <class T = double>
3232
std::string ssaForm(const ComputationGraph& g, const std::vector<std::string>& opCodeLabels,
33-
const std::vector<T>& values = {});
34-
33+
const std::vector<T>& values = {}, const std::vector<T>& values2 = {});
3534
}

0 commit comments

Comments
 (0)