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_logical_not.cc 2.5 kB

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