Skip to content

Commit 10ed768

Browse files
Dorokhovmigueldeicaza
authored andcommitted
Test for TanhGrad
1 parent 6eb4124 commit 10ed768

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/TensorFlowSharp.Tests.CSharp/MathTests.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
26
using TensorFlow;
37
using Xunit;
48

59
namespace TensorFlowSharp.Tests.CSharp
610
{
711
public class MathTests
812
{
13+
[Fact]
14+
public void Should_CalculateTanhGrad_Correctly ()
15+
{
16+
using (TFGraph graph = new TFGraph ())
17+
using (TFSession session = new TFSession (graph))
18+
{
19+
20+
TFOutput x = graph.Const (new TFTensor (0.7));
21+
TFOutput y = graph.Tanh (x);
22+
TFOutput dy = graph.Const (new TFTensor (new [] { 1.0 }));
23+
TFOutput grad = graph.TanhGrad (y, dy);
24+
25+
TFTensor [] result = session.Run (new TFOutput [] { }, new TFTensor [] { }, new [] { grad });
26+
27+
double value = (double)result [0].GetValue ();
28+
Assert.Equal (0.634739589982459, value, 15);
29+
}
30+
}
31+
932
private static IEnumerable<object []> reduceMeanData ()
1033
{
1134
// Example from https://www.tensorflow.org/api_docs/python/tf/reduce_mean
@@ -48,6 +71,5 @@ public void Should_ReduceMean (double [,] input, int? axis, object expected)
4871
}
4972
}
5073
}
51-
5274
}
5375
}

0 commit comments

Comments
 (0)