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.Indexing.Test.cs 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 ArrayIndexingTest : EagerModeTestBase
  15. {
  16. [TestMethod]
  17. public void int_params()
  18. {
  19. var x = np.arange(24).reshape((2, 3, 4));
  20. x[1, 2, 3] = 1;
  21. var y = x[1, 2, 3];
  22. Assert.AreEqual(y.shape, Shape.Scalar);
  23. Assert.AreEqual(y, 1);
  24. x[0, 0] = new[] { 3, 1, 1, 2 };
  25. y = x[0, 0];
  26. Assert.AreEqual(y.shape, 4);
  27. Assert.AreEqual(y, new[] { 3, 1, 1, 2 });
  28. y = x[0];
  29. Assert.AreEqual(y.shape, (3, 4));
  30. var z = np.arange(12).reshape((3, 4));
  31. x[1] = z;
  32. Assert.AreEqual(x[1], z);
  33. }
  34. [TestMethod]
  35. public void slice_params()
  36. {
  37. var x = np.arange(12).reshape((3, 4));
  38. var y = x[new Slice(0, 1), new Slice(2)];
  39. Assert.AreEqual(y.shape, (1, 2));
  40. Assert.AreEqual(y, np.array(new[] { 2, 3 }).reshape((1, 2)));
  41. }
  42. [TestMethod]
  43. public void slice_string_params()
  44. {
  45. var x = np.arange(12).reshape((3, 4));
  46. var y = x[Slice.ParseSlices("0:1,2:")];
  47. Assert.AreEqual(y.shape, (1, 2));
  48. Assert.AreEqual(y, np.array(new[] { 2, 3 }).reshape((1, 2)));
  49. }
  50. }
  51. }