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.

test_ops_merge.cc 2.7 kB

4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <vector>
  17. #include <memory>
  18. #include "common/common_test.h"
  19. #include "ops/merge.h"
  20. #include "ir/dtype/type.h"
  21. #include "ir/value.h"
  22. #include "abstract/dshape.h"
  23. #include "utils/tensor_construct_utils.h"
  24. namespace mindspore {
  25. namespace ops {
  26. class TestMerge : public UT::Common {
  27. public:
  28. TestMerge() {}
  29. void SetUp() {}
  30. void TearDown() {}
  31. };
  32. TEST_F(TestMerge, test_ops_merge1) {
  33. auto merge = std::make_shared<Merge>();
  34. merge->Init();
  35. auto input_x = TensorConstructUtils::CreateOnesTensor(kNumberTypeFloat32, std::vector<int64_t>{2, 4});
  36. auto input_y = TensorConstructUtils::CreateOnesTensor(kNumberTypeFloat32, std::vector<int64_t>{2, 4});
  37. MS_EXCEPTION_IF_NULL(input_x);
  38. MS_EXCEPTION_IF_NULL(input_y);
  39. std::vector<ValuePtr> inputs_ = {input_x, input_y};
  40. auto input = std::make_shared<ValueTuple>(inputs_);
  41. auto abstract = merge->Infer({input->ToAbstract()});
  42. MS_EXCEPTION_IF_NULL(abstract);
  43. auto shape_ptr = abstract->BuildShape();
  44. MS_EXCEPTION_IF_NULL(shape_ptr);
  45. EXPECT_EQ(shape_ptr->isa<abstract::TupleShape>(), true);
  46. auto shape = shape_ptr->cast<abstract::TupleShapePtr>();
  47. MS_EXCEPTION_IF_NULL(shape);
  48. auto shape_vec = shape->shape();
  49. EXPECT_EQ(shape_vec.size(), 2);
  50. auto shape1 = shape_vec[0]->cast<abstract::ShapePtr>()->shape();
  51. EXPECT_EQ(shape1.size(), 2);
  52. EXPECT_EQ(shape1[0], 2);
  53. EXPECT_EQ(shape1[1], 4);
  54. auto shape2 = shape_vec[1]->cast<abstract::ShapePtr>()->shape();
  55. EXPECT_EQ(shape2.size(), 1);
  56. EXPECT_EQ(shape2[0], 1);
  57. auto type_ptr = abstract->BuildType();
  58. MS_EXCEPTION_IF_NULL(type_ptr);
  59. auto type = type_ptr->cast<TuplePtr>();
  60. auto type_vec = type->elements();
  61. MS_EXCEPTION_IF_NULL(type_vec[0]);
  62. auto data_type1 = type_vec[0]->cast<TensorTypePtr>()->element();
  63. MS_EXCEPTION_IF_NULL(data_type1);
  64. EXPECT_EQ(data_type1->type_id(), kNumberTypeFloat32);
  65. auto data_type2 = type_vec[1]->cast<TensorTypePtr>()->element();
  66. MS_EXCEPTION_IF_NULL(data_type2);
  67. EXPECT_EQ(data_type2->type_id(), kNumberTypeInt32);
  68. }
  69. } // namespace ops
  70. } // namespace mindspore