You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

TensorOperate.cs 1.0 kB

12345678910111213141516171819202122232425262728
  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. namespace Tensorflow.UnitTest.TF_API
  8. {
  9. [TestClass]
  10. public class TensorOperate
  11. {
  12. [TestMethod]
  13. public void TransposeTest()
  14. {
  15. var a = tf.constant(np.array(new[, , ,] { { { { 1, 11, 2, 22 } }, { { 3, 33, 4, 44 } } },
  16. { { { 5, 55, 6, 66 } }, { { 7, 77, 8, 88 } } } }));
  17. var b = tf.transpose(a, new[] { 3, 1, 2, 0 });
  18. var transpose_a = tf.constant(np.array(new[, , ,] { { { { 1, 5 } }, { { 3, 7 } } },
  19. { { { 11, 55 } }, { { 33, 77 } } }, { { { 2, 6 } }, { { 4, 8 } } },
  20. { { { 22, 66 } }, { { 44, 88 } } } }));
  21. Assert.IsTrue(Enumerable.SequenceEqual(new[] { 4, 2, 1, 2 }, b.shape));
  22. Assert.IsTrue(Enumerable.SequenceEqual(transpose_a.numpy().ToArray<int>(), b.numpy().ToArray<int>()));
  23. }
  24. }
  25. }