-
Notifications
You must be signed in to change notification settings - Fork 37
/
PrintGraph.php
45 lines (45 loc) · 1.06 KB
/
PrintGraph.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
function print_graph($g) {
foreach ($g->operations() as $op) {
echo $op->name() . ": " . $op->type() . ", " . $op->device() . "\n";
$count = $op->numInputs();
for ($i = 0; $i < $count; $i++) {
$in = $op->input($i);
$out = $in->producer();
echo " in_$i: " . $in->typeName($i) .
", from " . $out->op()->name() . "/out_" . $out->index() . "\n";
}
$count = $op->numOutputs();
for ($i = 0; $i < $count; $i++) {
$out = $op->output($i);
$num = $out->numConsumers();
$s = "";
if ($num) {
$inputs = $out->consumers();
$s = ", to (";
$first = true;
foreach ($inputs as $in) {
if (!$first) {
$s .= ", ";
} else {
$first = false;
}
$s .= $in->op()->name() ."/" . $in->index();
}
$s .= ")";
}
echo " out_$i: " . $out->typeName($i) . "$s\n";
}
$i = 0;
foreach($op->controlInputs() as $ctl) {
$i++;
echo " ctl_in_$i: " . $ctl->name() . "\n";
}
$i = 0;
foreach($op->controlOutputs() as $ctl) {
$i++;
echo " ctl_out_$i: " . $ctl->name() . "\n";
}
}
echo "\n";
}