Browse Source

Add test case for tf.reduce_sum(..., axis = ...)

pull/917/head
Alexander Mishunin 3 years ago
parent
commit
8bcdc780aa
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      test/TensorFlowNET.Graph.UnitTest/GradientTest/GradientTest.cs

+ 18
- 0
test/TensorFlowNET.Graph.UnitTest/GradientTest/GradientTest.cs View File

@@ -175,6 +175,24 @@ namespace TensorFlowNET.UnitTest.Gradient
new[] { -1.0, 1.0 }); new[] { -1.0, 1.0 });
} }


[TestMethod]
public void testReduceSumGradients()
{
var x = tf.placeholder(tf.float64, shape: new Shape(1, 1));
var m = tf.broadcast_to(x, new Shape(2, 3));
var g0 = tf.gradients(tf.reduce_sum(m), x)[0];
var g1 = tf.gradients(tf.reduce_sum(m, axis: 0), x)[0];
var g2 = tf.gradients(tf.reduce_sum(m, axis: 1), x)[0];

using (var session = tf.Session())
{
var (r0, r1, r2) = session.run((g0, g1, g2), new FeedItem(x, 1.0));
self.assertFloat64Equal(6.0, r0[0], $"tf.reduce_sum(...)");
self.assertFloat64Equal(2.0, r1[0], $"tf.reduce_sum(..., axis = 0)");
self.assertFloat64Equal(3.0, r2[0], $"tf.reduce_sum(..., axis = 1)");
}
}

[TestMethod] [TestMethod]
public void testTanhGradient() public void testTanhGradient()
{ {


Loading…
Cancel
Save