• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/where.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 
25 namespace mindspore {
26 namespace ops {
27 
28 class TestWhere : public UT::Common {
29  public:
TestWhere()30   TestWhere() {}
SetUp()31   void SetUp() {}
TearDown()32   void TearDown() {}
33 };
34 
TEST_F(TestWhere,test_ops_where1)35 TEST_F(TestWhere, test_ops_where1) {
36   //  auto where = std::make_shared<Where>();
37   //  where->Init();
38   //  auto inputs0 = TensorConstructUtils::CreateOnesTensor(kNumberTypeInt64, std::vector<int64_t>{2, 3});
39   //  auto inputs1 = TensorConstructUtils::CreateOnesTensor(kNumberTypeInt64, std::vector<int64_t>{2, 3});
40   //  MS_EXCEPTION_IF_NULL(inputs0);
41   //  MS_EXCEPTION_IF_NULL(inputs1);
42   //  auto abstract = where->Infer({inputs0->ToAbstract(), inputs1->ToAbstract()});
43   //  MS_EXCEPTION_IF_NULL(abstract);
44   //  EXPECT_EQ(abstract->isa<abstract::AbstractTensor>(), true);
45   //  auto shape_ptr = abstract->BuildShape();
46   //  MS_EXCEPTION_IF_NULL(shape_ptr);
47   //  EXPECT_EQ(shape_ptr->isa<abstract::Shape>(), true);
48   //  auto shape = shape_ptr->cast<abstract::ShapePtr>();
49   //  MS_EXCEPTION_IF_NULL(shape);
50   //  auto shape_vec = shape->shape();
51   //  EXPECT_EQ(shape_vec.size(), 2);
52   //  EXPECT_EQ(shape_vec[0], 2);
53   //  EXPECT_EQ(shape_vec[1], 3);
54   //  auto type = abstract->BuildType();
55   //  MS_EXCEPTION_IF_NULL(type);
56   //  EXPECT_EQ(type->isa<TensorType>(), true);
57   //  auto tensor_type = type->cast<TensorTypePtr>();
58   //  MS_EXCEPTION_IF_NULL(tensor_type);
59   //  auto data_type = tensor_type->element();
60   //  MS_EXCEPTION_IF_NULL(data_type);
61   //  EXPECT_EQ(data_type->type_id(), kNumberTypeInt64);
62 }
63 
TEST_F(TestWhere,test_ops_where2)64 TEST_F(TestWhere, test_ops_where2) {
65   auto where = std::make_shared<Where>();
66   where->Init();
67   auto inputs0 = TensorConstructUtils::CreateOnesTensor(kNumberTypeInt64, std::vector<int64_t>{1});
68   auto inputs1 = TensorConstructUtils::CreateOnesTensor(kNumberTypeInt64, std::vector<int64_t>{4});
69   auto inputs2 = TensorConstructUtils::CreateOnesTensor(kNumberTypeInt64, std::vector<int64_t>{1});
70   MS_EXCEPTION_IF_NULL(inputs0);
71   MS_EXCEPTION_IF_NULL(inputs1);
72   MS_EXCEPTION_IF_NULL(inputs2);
73   auto abstract = where->Infer({inputs0->ToAbstract(), inputs1->ToAbstract(), inputs2->ToAbstract()});
74   MS_EXCEPTION_IF_NULL(abstract);
75   EXPECT_EQ(abstract->isa<abstract::AbstractTensor>(), true);
76   auto shape_ptr = abstract->BuildShape();
77   MS_EXCEPTION_IF_NULL(shape_ptr);
78   EXPECT_EQ(shape_ptr->isa<abstract::Shape>(), true);
79   auto shape = shape_ptr->cast<abstract::ShapePtr>();
80   MS_EXCEPTION_IF_NULL(shape);
81   auto shape_vec = shape->shape();
82   EXPECT_EQ(shape_vec.size(), 1);
83   EXPECT_EQ(shape_vec[0], 4);
84   auto type = abstract->BuildType();
85   MS_EXCEPTION_IF_NULL(type);
86   EXPECT_EQ(type->isa<TensorType>(), true);
87   auto tensor_type = type->cast<TensorTypePtr>();
88   MS_EXCEPTION_IF_NULL(tensor_type);
89   auto data_type = tensor_type->element();
90   MS_EXCEPTION_IF_NULL(data_type);
91   EXPECT_EQ(data_type->type_id(), kNumberTypeInt64);
92 }
93 
94 }  // namespace ops
95 }  // namespace mindspore
96