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.

ShapeTest.cs 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow.NumPy;
  3. using System;
  4. using System.Linq;
  5. using static Tensorflow.Binding;
  6. using Tensorflow;
  7. namespace TensorFlowNET.UnitTest.NumPy
  8. {
  9. [TestClass]
  10. public class ShapeTest : EagerModeTestBase
  11. {
  12. [Ignore]
  13. [TestMethod]
  14. public unsafe void ShapeGetLastElements()
  15. {
  16. // test code from function _CheckAtLeast3DImage
  17. // 之前的 _CheckAtLeast3DImage 有bug,现在通过测试,下面的代码是正确的
  18. // todo: shape["-3:"] 的写法,目前有bug,需要修复,单元测试等修复后再放开,暂时先忽略测试
  19. var image_shape = new Shape(new[] { 32, 64, 3 });
  20. var image_shape_4d = new Shape(new[] { 4, 64, 32, 3 });
  21. var image_shape_last_three_elements = new Shape(new[] {
  22. image_shape.dims[image_shape.dims.Length - 3],
  23. image_shape.dims[image_shape.dims.Length - 2],
  24. image_shape.dims[image_shape.dims.Length - 1]});
  25. var image_shape_last_three_elements2 = image_shape["-3:"];
  26. Assert.IsTrue(Equal(image_shape_last_three_elements.dims, image_shape_last_three_elements2.dims), "3dims get fail.");
  27. var image_shape_last_three_elements_4d = new Shape(new[] {
  28. image_shape_4d.dims[image_shape_4d.dims.Length - 3],
  29. image_shape_4d.dims[image_shape_4d.dims.Length - 2],
  30. image_shape_4d.dims[image_shape_4d.dims.Length - 1]});
  31. var image_shape_last_three_elements2_4d = image_shape_4d["-3:"];
  32. Assert.IsTrue(Equals(image_shape_last_three_elements_4d.dims, image_shape_last_three_elements2_4d.dims), "4dims get fail.");
  33. }
  34. }
  35. }