Browse Source

fix NullReferenceException on session run with ITensorOrOperation signature

pull/543/head
Pavel Šavara 5 years ago
parent
commit
5f69186ad6
2 changed files with 13 additions and 1 deletions
  1. +2
    -1
      src/TensorFlowNET.Core/Sessions/BaseSession.cs
  2. +11
    -0
      test/TensorFlowNET.UnitTest/SessionTest.cs

+ 2
- 1
src/TensorFlowNET.Core/Sessions/BaseSession.cs View File

@@ -65,7 +65,8 @@ namespace Tensorflow


public virtual NDArray run(ITensorOrOperation fetche, params FeedItem[] feed_dict) public virtual NDArray run(ITensorOrOperation fetche, params FeedItem[] feed_dict)
{ {
return _run(fetche, feed_dict)[0];
var results = _run(fetche, feed_dict);
return fetche is Tensor ? results[0] : null;
} }


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


+ 11
- 0
test/TensorFlowNET.UnitTest/SessionTest.cs View File

@@ -132,6 +132,17 @@ namespace TensorFlowNET.UnitTest
} }
} }
} }
[TestMethod]
public void Autocast_Case0()
{
var sess = tf.Session().as_default();
ITensorOrOperation operation = tf.global_variables_initializer();
// the cast to ITensorOrOperation is essential for the test of this method signature
var ret = sess.run(operation);

ret.Should().BeNull();
}


[TestMethod] [TestMethod]
public void Autocast_Case1() public void Autocast_Case1()


Loading…
Cancel
Save