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.

Array.Sorting.Test.cs 1.3 kB

4 years ago
2 years ago
2 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Tensorflow;
  7. using Tensorflow.NumPy;
  8. namespace TensorFlowNET.UnitTest.NumPy
  9. {
  10. /// <summary>
  11. /// https://numpy.org/doc/stable/user/basics.indexing.html
  12. /// </summary>
  13. [TestClass]
  14. public class ArraySortingTest : EagerModeTestBase
  15. {
  16. /// <summary>
  17. /// https://numpy.org/doc/stable/reference/generated/numpy.argsort.html
  18. /// </summary>
  19. [TestMethod]
  20. public void argsort()
  21. {
  22. var x = np.array(new[] { 3, 1, 2 });
  23. var ind = np.argsort(x);
  24. Assert.AreEqual(ind, new[] { 1, 2, 0 });
  25. var y = np.array(new[,] { { 0, 3 }, { 2, 2 } });
  26. ind = np.argsort(y, axis: 0);
  27. Assert.AreEqual(ind[0], new[] { 0, 1 });
  28. Assert.AreEqual(ind[1], new[] { 1, 0 });
  29. }
  30. /// <summary>
  31. /// https://numpy.org/doc/stable/reference/generated/numpy.sort.html
  32. /// </summary>
  33. [TestMethod]
  34. public void sort()
  35. {
  36. var x = np.array(new int[] { 3, 1, 2 });
  37. var sorted = np.sort(x);
  38. // Assert.IsTrue(sorted.ToArray<int>() is [1, 2, 3]);
  39. }
  40. }
  41. }