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.

dshape_test.cc 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <iostream>
  17. #include <memory>
  18. #include "common/common_test.h"
  19. #include "abstract/dshape.h"
  20. #include "utils/log_adapter.h"
  21. namespace mindspore {
  22. namespace abstract {
  23. class TestDShape : public UT::Common {
  24. public:
  25. Shape shp_1;
  26. Shape shp_2;
  27. Shape shp_3;
  28. Shape shp_4;
  29. NoShape shp_noshp_1;
  30. NoShape shp_noshp_2;
  31. TupleShape shp_tuple_1;
  32. TupleShape shp_tuple_2;
  33. TupleShape shp_tuple_3;
  34. TupleShape shp_tuple_4;
  35. TestDShape()
  36. : shp_1({1, 1}),
  37. shp_2({1, 1}),
  38. shp_3({1, 2}),
  39. shp_4({1}),
  40. shp_noshp_1(),
  41. shp_noshp_2(),
  42. shp_tuple_1({NoShape().Clone(), Shape({1, 1}).Clone()}),
  43. shp_tuple_2({NoShape().Clone(), Shape({1, 1, 1}).Clone()}),
  44. shp_tuple_3({NoShape().Clone(), Shape({1, 2, 1}).Clone()}),
  45. shp_tuple_4({NoShape().Clone()}) {}
  46. };
  47. TEST_F(TestDShape, EqualTest) {
  48. ASSERT_TRUE(shp_1 == shp_2);
  49. ASSERT_FALSE(shp_1 == shp_3);
  50. ASSERT_FALSE(shp_1 == shp_noshp_1);
  51. ASSERT_TRUE(shp_noshp_1 == shp_noshp_2);
  52. ASSERT_FALSE(shp_tuple_1 == shp_1);
  53. ASSERT_FALSE(shp_tuple_1 == shp_tuple_2);
  54. ASSERT_FALSE(shp_tuple_1 == shp_tuple_4);
  55. }
  56. TEST_F(TestDShape, ToString) {
  57. ASSERT_EQ(shp_3.ToString(), "(1, 2)");
  58. ASSERT_EQ(shp_noshp_1.ToString(), "NoShape");
  59. ASSERT_EQ(shp_tuple_2.ToString(), "TupleShape(NoShape, (1, 1, 1))");
  60. }
  61. TEST_F(TestDShape, Clone) {
  62. ASSERT_EQ(*shp_3.Clone(), shp_3);
  63. ASSERT_EQ(*shp_noshp_1.Clone(), shp_noshp_1);
  64. ASSERT_EQ(*shp_tuple_2.Clone(), shp_tuple_2);
  65. }
  66. } // namespace abstract
  67. } // namespace mindspore