• 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/logical_not.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 namespace {
29 template <typename T>
SetTensorData(void * data,T num,size_t data_length)30 void SetTensorData(void *data, T num, size_t data_length) {
31   MS_EXCEPTION_IF_NULL(data);
32   auto tensor_data = reinterpret_cast<T *>(data);
33   MS_EXCEPTION_IF_NULL(tensor_data);
34   for (size_t index = 0; index < data_length; ++index) {
35     *tensor_data = num;
36     ++tensor_data;
37   }
38 }
39 }  // namespace
40 
41 class TestLogicalNot : public UT::Common {
42  public:
TestLogicalNot()43   TestLogicalNot() {}
SetUp()44   void SetUp() {}
TearDown()45   void TearDown() {}
46 };
47 
TEST_F(TestLogicalNot,test_ops_logical_not1)48 TEST_F(TestLogicalNot, test_ops_logical_not1) {
49   auto logical_not = std::make_shared<LogicalNot>();
50   logical_not->Init();
51   auto tensor = std::make_shared<tensor::Tensor>(kNumberTypeBool, std::vector<int64_t>{3});
52   MS_EXCEPTION_IF_NULL(tensor);
53   auto mem_size = IntToSize(tensor->ElementsNum());
54   SetTensorData<bool>(tensor->data_c(), true, mem_size);
55   auto abstract = logical_not->Infer({tensor->ToAbstract()});
56   MS_EXCEPTION_IF_NULL(abstract);
57   EXPECT_EQ(abstract->isa<abstract::AbstractTensor>(), true);
58   auto shape_ptr = abstract->BuildShape();
59   MS_EXCEPTION_IF_NULL(shape_ptr);
60   EXPECT_EQ(shape_ptr->isa<abstract::Shape>(), true);
61   auto shape = shape_ptr->cast<abstract::ShapePtr>();
62   MS_EXCEPTION_IF_NULL(shape);
63   auto shape_vec = shape->shape();
64   auto type = abstract->BuildType();
65   MS_EXCEPTION_IF_NULL(type);
66   EXPECT_EQ(type->isa<TensorType>(), true);
67   auto tensor_type = type->cast<TensorTypePtr>();
68   MS_EXCEPTION_IF_NULL(tensor_type);
69   auto data_type = tensor_type->element();
70   MS_EXCEPTION_IF_NULL(data_type);
71   EXPECT_EQ(data_type->type_id(), kNumberTypeBool);
72   EXPECT_EQ(shape_vec.size(), 1);
73   EXPECT_EQ(shape_vec[0], 3);
74 }
75 
76 }  // namespace ops
77 }  // namespace mindspore
78