Skip to content

Commit 13b1b63

Browse files
Pavel ŠavaraOceania2018
authored andcommitted
fix NullReferenceException on session run with ITensorOrOperation signature
1 parent 8a2782c commit 13b1b63

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎src/TensorFlowNET.Core/Sessions/BaseSession.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public virtual NDArray run(Tensor fetche, params FeedItem[] feed_dict)
6565

6666
public virtual NDArray run(ITensorOrOperation fetche, params FeedItem[] feed_dict)
6767
{
68-
return _run(fetche, feed_dict)[0];
68+
var results = _run(fetche, feed_dict);
69+
return fetche is Tensor ? results[0] : null;
6970
}
7071

7172
public virtual (NDArray, NDArray, NDArray, NDArray, NDArray) run(

‎test/TensorFlowNET.UnitTest/SessionTest.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ public void Eval_LargeString_Scalar()
133133
}
134134
}
135135
}
136+
137+
[TestMethod]
138+
public void Autocast_Case0()
139+
{
140+
var sess = tf.Session().as_default();
141+
ITensorOrOperation operation = tf.global_variables_initializer();
142+
// the cast to ITensorOrOperation is essential for the test of this method signature
143+
var ret = sess.run(operation);
144+
145+
ret.Should().BeNull();
146+
}
136147

137148
[TestMethod]
138149
public void Autocast_Case1()

0 commit comments

Comments
 (0)