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.3 kB

1234567891011121314151617181920212223242526272829303132333435
  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. [TestMethod]
  25. public void InitTensorTest()
  26. {
  27. var a = tf.constant(new NDArray(new[, ,] { { { 1 }, { 2 }, { 3 } }, { { 4 }, { 5 }, { 6 } } }));
  28. var b = tf.constant(new[, ,] { { { 1 }, { 2 }, { 3 } }, { { 4 }, { 5 }, { 6 } } });
  29. //Test Result : a is OK , and b is error .
  30. }
  31. }
  32. }