Skip to content

Commit 9b5d57d

Browse files
authored
Not print undefined of toDot function (#906)
1 parent 6c69385 commit 9b5d57d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/model/nns/graph.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ export default class ComputationalGraph {
121121
let s = 'digraph g {\n'
122122
for (let i = 0; i < this._nodes.length; i++) {
123123
const node = this.nodes[i]
124-
s += ` l${i} [label="${node.layer.constructor.name}\\n${node.name}"];\n`
124+
const label = node.layer.constructor.name + (node.name ? `\\n${node.name}` : '')
125+
s += ` l${i} [label="${label}"];\n`
125126
for (const parent of node.parents) {
126127
s += ` l${parent.index} -> l${i};\n`
127128
}

tests/lib/model/nns/graph.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ describe('Computational Graph', () => {
158158
test('toDot', () => {
159159
const graph = new ComputationalGraph()
160160
graph.add(Layer.fromObject({ type: 'input' }))
161-
graph.add(Layer.fromObject({ type: 'tanh' }))
161+
graph.add(Layer.fromObject({ type: 'tanh' }), 't')
162162
expect(graph.toDot()).toBe(
163-
'digraph g {\n l0 [label="InputLayer\\nundefined"];\n l1 [label="TanhLayer\\nundefined"];\n l0 -> l1;\n}'
163+
'digraph g {\n l0 [label="InputLayer"];\n l1 [label="TanhLayer\\nt"];\n l0 -> l1;\n}'
164164
)
165165
})
166166

0 commit comments

Comments
 (0)