Skip to content

Commit b5f357a

Browse files
committed
fix set_shape.
1 parent 9264a19 commit b5f357a

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/TensorFlowNET.Core/Tensors/Tensor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ public int[] _shape_tuple()
155155
/// </summary>
156156
public virtual void set_shape(TensorShape shape)
157157
{
158-
// this.shape = shape.rank >= 0 ? shape.dims : null;
159-
throw new NotImplementedException("");
158+
this.shape = shape.rank >= 0 ? shape : null;
160159
}
161160

162161
/// <summary>

test/TensorFlowNET.Graph.UnitTest/GradientTest/GradientTest.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public class GradientTest : GraphModeTestBase
1414
[TestMethod]
1515
public void BroadcastToGrad()
1616
{
17-
var graph = tf.Graph().as_default();
18-
1917
var x = tf.constant(2, dtype: dtypes.float32);
2018
var y = tf.broadcast_to(x, (2, 4, 3));
2119
var grad = tf.gradients(y, x);
@@ -30,8 +28,6 @@ public void BroadcastToGrad()
3028
[TestMethod]
3129
public void CumsumGrad()
3230
{
33-
var graph = tf.Graph().as_default();
34-
3531
var x = tf.constant(2, dtype: dtypes.float32);
3632
var y = tf.broadcast_to(x, (2, 4, 3));
3733
var z = tf.cumsum(y, axis: 1);
@@ -47,7 +43,6 @@ public void CumsumGrad()
4743
[TestMethod, Ignore]
4844
public void testGradients()
4945
{
50-
var g = tf.Graph().as_default();
5146
var inp = tf.constant(1.0, shape: new[] { 32, 100 }, name: "in");
5247
var w = tf.constant(1.0, shape: new[] { 100, 10 }, name: "w");
5348
var b = tf.Variable(1.0, shape: new[] { 10 }, name: "b");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Tensorflow;
23
using static Tensorflow.Binding;
34

45
namespace TensorFlowNET.UnitTest
56
{
67
public class GraphModeTestBase : PythonTest
78
{
9+
protected Graph graph;
810
[TestInitialize]
911
public void TestInit()
1012
{
1113
tf.compat.v1.disable_eager_execution();
14+
graph = tf.Graph().as_default();
15+
}
16+
17+
[TestCleanup]
18+
public void TestClean()
19+
{
20+
graph.Exit();
1221
}
1322
}
1423
}

test/TensorFlowNET.Graph.UnitTest/NameScopeTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void NestedNameScope()
3838
Assert.AreEqual("scope1/Const_1:0", const3.name);
3939
});
4040

41-
g.Dispose();
41+
g.Exit();
4242

4343
Assert.AreEqual("", g._name_stack);
4444
}
@@ -70,7 +70,7 @@ public void NestedNameScope_Using()
7070
Assert.AreEqual("scope1/Const_1:0", const3.name);
7171
};
7272

73-
g.Dispose();
73+
g.Exit();
7474

7575
Assert.AreEqual("", g._name_stack);
7676
}

0 commit comments

Comments
 (0)