From 47e9510b049949065c19e219f6f11f41bf8742db Mon Sep 17 00:00:00 2001 From: ishii-norimi Date: Sun, 23 Feb 2025 15:47:56 +0900 Subject: [PATCH] Skip adding parents if not needed --- lib/model/nns/graph.js | 2 +- tests/lib/model/nns/graph.test.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/model/nns/graph.js b/lib/model/nns/graph.js index ce7fe7b0a..faee7ce43 100644 --- a/lib/model/nns/graph.js +++ b/lib/model/nns/graph.js @@ -142,7 +142,7 @@ export default class ComputationalGraph { } let parentinfos = [] if (!inputs) { - if (this._nodes.length > 0) { + if (layer.calc.length > 0 && this._nodes.length > 0) { parentinfos.push({ index: this._nodes.length - 1, subscript: null, diff --git a/tests/lib/model/nns/graph.test.js b/tests/lib/model/nns/graph.test.js index d9d1bd845..d25c6ce7c 100644 --- a/tests/lib/model/nns/graph.test.js +++ b/tests/lib/model/nns/graph.test.js @@ -185,6 +185,14 @@ describe('Computational Graph', () => { expect(graph.nodes[1].parents[0].subscript).toBeNull() }) + test('no input', () => { + const graph = new ComputationalGraph() + graph.add(Layer.fromObject({ type: 'input', name: 'a' })) + graph.add(Layer.fromObject({ type: 'const', value: 1 })) + + expect(graph.nodes[1].parents).toHaveLength(0) + }) + test('string input', () => { const graph = new ComputationalGraph() graph.add(Layer.fromObject({ type: 'input' }), 'in')