Browse Source

fix NullReferenceException on session run with ITensorOrOperation signature

tags/v0.20
Pavel Šavara Haiping 5 years ago
parent
commit
13b1b63b4e
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)
{
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(


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

@@ -133,6 +133,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]
public void Autocast_Case1()


Loading…
Cancel
Save