|
| 1 | +using FluentAssertions; |
| 2 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 3 | +using NumSharp; |
| 4 | +using System.Linq; |
| 5 | +using Tensorflow; |
| 6 | +using static Tensorflow.Binding; |
| 7 | + |
| 8 | +namespace Tensorflow.UnitTest.TF_API |
| 9 | +{ |
| 10 | + [TestClass] |
| 11 | + public class TensorOperate |
| 12 | + { |
| 13 | + [TestMethod] |
| 14 | + public void TransposeTest() |
| 15 | + { |
| 16 | + var a = tf.constant(np.array(new[, , ,] { { { { 1, 11, 2, 22 } }, { { 3, 33, 4, 44 } } }, |
| 17 | + { { { 5, 55, 6, 66 } }, { { 7, 77, 8, 88 } } } })); |
| 18 | + var b = tf.transpose(a, new[] { 3, 1, 2, 0 }); |
| 19 | + var transpose_a = tf.constant(np.array(new[, , ,] { { { { 1, 5 } }, { { 3, 7 } } }, |
| 20 | + { { { 11, 55 } }, { { 33, 77 } } }, { { { 2, 6 } }, { { 4, 8 } } }, |
| 21 | + { { { 22, 66 } }, { { 44, 88 } } } })); |
| 22 | + Assert.IsTrue(Enumerable.SequenceEqual(new[] { 4, 2, 1, 2 }, b.shape)); |
| 23 | + Assert.IsTrue(Enumerable.SequenceEqual(transpose_a.numpy().ToArray<int>(), b.numpy().ToArray<int>())); |
| 24 | + } |
| 25 | + |
| 26 | + |
| 27 | + } |
| 28 | +} |
0 commit comments