Skip to content

Commit 40b170a

Browse files
authored
Skip adding parents if not needed (#922)
1 parent 7ba037d commit 40b170a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/model/nns/graph.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export default class ComputationalGraph {
142142
}
143143
let parentinfos = []
144144
if (!inputs) {
145-
if (this._nodes.length > 0) {
145+
if (layer.calc.length > 0 && this._nodes.length > 0) {
146146
parentinfos.push({
147147
index: this._nodes.length - 1,
148148
subscript: null,

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

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ describe('Computational Graph', () => {
185185
expect(graph.nodes[1].parents[0].subscript).toBeNull()
186186
})
187187

188+
test('no input', () => {
189+
const graph = new ComputationalGraph()
190+
graph.add(Layer.fromObject({ type: 'input', name: 'a' }))
191+
graph.add(Layer.fromObject({ type: 'const', value: 1 }))
192+
193+
expect(graph.nodes[1].parents).toHaveLength(0)
194+
})
195+
188196
test('string input', () => {
189197
const graph = new ComputationalGraph()
190198
graph.add(Layer.fromObject({ type: 'input' }), 'in')

0 commit comments

Comments
 (0)