From ab4eff6b64f0957e8005dfd13775d14a5a144e92 Mon Sep 17 00:00:00 2001 From: Banyc <36535895+Banyc@users.noreply.github.com> Date: Sun, 13 Dec 2020 20:37:33 +0800 Subject: [PATCH 1/2] Add test case for tf.transpose --- .../ManagedAPI/TensorOperate.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/TensorFlowNET.UnitTest/ManagedAPI/TensorOperate.cs b/test/TensorFlowNET.UnitTest/ManagedAPI/TensorOperate.cs index 99fc7e33e..99becb7f9 100644 --- a/test/TensorFlowNET.UnitTest/ManagedAPI/TensorOperate.cs +++ b/test/TensorFlowNET.UnitTest/ManagedAPI/TensorOperate.cs @@ -8,9 +8,19 @@ namespace TensorFlowNET.UnitTest.ManagedAPI [TestClass] public class TensorOperate { - [TestMethod] + [TestMethod, Ignore] public void TransposeTest() { + // https://www.tensorflow.org/api_docs/python/tf/transpose#for_example_2 + var x = tf.constant(new int[,] { + { 1, 2, 3 }, + { 4, 5, 6 } + }); + var transpose_x = tf.transpose(x); + Assert.IsTrue(Enumerable.SequenceEqual(new int[] { 1, 4 }, transpose_x[0].numpy().ToArray())); + Assert.IsTrue(Enumerable.SequenceEqual(new int[] { 2, 5 }, transpose_x[1].numpy().ToArray())); + Assert.IsTrue(Enumerable.SequenceEqual(new int[] { 3, 6 }, transpose_x[2].numpy().ToArray())); + var a = tf.constant(np.array(new[, , ,] { { { { 1, 11, 2, 22 } }, { { 3, 33, 4, 44 } } }, { { { 5, 55, 6, 66 } }, { { 7, 77, 8, 88 } } } })); var b = tf.transpose(a, new[] { 3, 1, 2, 0 }); From 9072c1f8a61c4c33253b8aefbfab879209ffebf6 Mon Sep 17 00:00:00 2001 From: Banyc <36535895+Banyc@users.noreply.github.com> Date: Sun, 13 Dec 2020 21:03:55 +0800 Subject: [PATCH 2/2] Add test case TypeMismatchedSliceAssign --- .../Basics/VariableTest.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/TensorFlowNET.UnitTest/Basics/VariableTest.cs b/test/TensorFlowNET.UnitTest/Basics/VariableTest.cs index c4bb47297..1d34009dd 100644 --- a/test/TensorFlowNET.UnitTest/Basics/VariableTest.cs +++ b/test/TensorFlowNET.UnitTest/Basics/VariableTest.cs @@ -83,6 +83,26 @@ public void SliceAssign() Assert.AreEqual(nd[2], x[2].numpy()); } + [TestMethod, Ignore] + public void TypeMismatchedSliceAssign() + { + NDArray intNd = new int[] + { + 1, -2, 3 + }; + NDArray doubleNd = new double[] + { + -5, 6, -7 + }; + var x = tf.Variable(doubleNd); + + var slice = x[":"]; + Assert.ThrowsException( + // this statement exit without throwing any exception but the "test execution summary" seems not able to detect that. + () => slice.assign(intNd) + ); + } + [TestMethod] public void Accumulation() {