|
| 1 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 2 | +using Tensorflow; |
| 3 | +using Tensorflow.NumPy; |
| 4 | +using TensorFlow; |
| 5 | +using static Tensorflow.Binding; |
| 6 | +using static Tensorflow.KerasApi; |
| 7 | + |
| 8 | +namespace TensorFlow.Kernel.UnitTest |
| 9 | +{ |
| 10 | + [TestClass] |
| 11 | + public class concat_op_test |
| 12 | + { |
| 13 | + [TestMethod] |
| 14 | + public void testConcatEmpty() |
| 15 | + { |
| 16 | + var t1 = tf.constant(new int[] { }); |
| 17 | + var t2 = tf.constant(new int[] { }); |
| 18 | + var c = array_ops.concat(new[] { t1, t2 }, 0); |
| 19 | + var expected = np.array(new int[] { }); |
| 20 | + Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>())); |
| 21 | + } |
| 22 | + |
| 23 | + [TestMethod] |
| 24 | + public void testConcatNegativeAxis() |
| 25 | + { |
| 26 | + var t1 = tf.constant(new int[,] {{ 1, 2, 3 }, { 4, 5, 6 } }); |
| 27 | + var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } }); |
| 28 | + var c = array_ops.concat(new[] { t1, t2 }, -2); |
| 29 | + var expected = np.array(new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } }); |
| 30 | + Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>())); |
| 31 | + |
| 32 | + c = array_ops.concat(new[] { t1, t2 }, -1); |
| 33 | + expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } }); |
| 34 | + Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), c.numpy().ToArray<int>())); |
| 35 | + } |
| 36 | + |
| 37 | + [TestMethod] |
| 38 | + [DataRow(TF_DataType.TF_INT32)] |
| 39 | + [DataRow(TF_DataType.TF_INT64)] |
| 40 | + [DataRow(TF_DataType.TF_UINT32)] |
| 41 | + [DataRow(TF_DataType.TF_UINT64)] |
| 42 | + public void testConcatDtype(TF_DataType dtype) |
| 43 | + { |
| 44 | + var t1 = tf.constant(new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }, dtype: dtype); |
| 45 | + var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } }, dtype: dtype); |
| 46 | + var c = array_ops.concat(new[] { t1, t2 }, 1); |
| 47 | + var expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } }); |
| 48 | + Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), tf.cast(c, TF_DataType.TF_INT32).numpy().ToArray<int>())); |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | + [TestMethod] |
| 53 | + [DataRow(TF_DataType.TF_INT32)] |
| 54 | + [DataRow(TF_DataType.TF_INT64)] |
| 55 | + public void testConcatAxisType(TF_DataType dtype) |
| 56 | + { |
| 57 | + var t1 = tf.constant(new int[,] { { 1, 2, 3 }, {4, 5, 6 } }); |
| 58 | + var t2 = tf.constant(new int[,] { { 7, 8, 9 }, { 10, 11, 12 } }); |
| 59 | + var c = array_ops.concat(new[] { t1, t2 }, tf.constant(1, dtype: dtype)); |
| 60 | + var expected = np.array(new int[,] { { 1, 2, 3, 7, 8, 9 }, { 4, 5, 6, 10, 11, 12 } }); |
| 61 | + Assert.IsTrue(Enumerable.SequenceEqual(expected.ToArray<int>(), tf.cast(c, TF_DataType.TF_INT32).numpy().ToArray<int>())); |
| 62 | + } |
| 63 | + |
| 64 | + } |
| 65 | +} |
0 commit comments