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.

mask_test.cc 2.3 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 <memory>
  17. #include <string>
  18. #include "dataset/core/client.h"
  19. #include "common/common.h"
  20. #include "gtest/gtest.h"
  21. #include "securec.h"
  22. #include "dataset/core/tensor.h"
  23. #include "dataset/core/cv_tensor.h"
  24. #include "dataset/core/data_type.h"
  25. #include "dataset/util/de_error.h"
  26. #include "dataset/kernels/data/mask_op.h"
  27. #include "dataset/kernels/data/data_utils.h"
  28. using namespace mindspore::dataset;
  29. namespace py = pybind11;
  30. class MindDataTestMaskOp : public UT::Common {
  31. public:
  32. MindDataTestMaskOp() {}
  33. void SetUp() { GlobalInit(); }
  34. };
  35. TEST_F(MindDataTestMaskOp, Basics) {
  36. std::shared_ptr<Tensor> t;
  37. Tensor::CreateTensor(&t, std::vector<uint32_t>({1, 2, 3, 4, 5, 6}));
  38. std::shared_ptr<Tensor> v;
  39. Tensor::CreateTensor(&v, std::vector<uint32_t>({3}), TensorShape::CreateScalar());
  40. std::shared_ptr<MaskOp> op = std::make_shared<MaskOp>(RelationalOp::kEqual, v, DataType(DataType::DE_UINT16));
  41. std::shared_ptr<Tensor> out;
  42. ASSERT_TRUE(op->Compute(t, &out).IsOk());
  43. op = std::make_shared<MaskOp>(RelationalOp::kNotEqual, v, DataType(DataType::DE_UINT16));
  44. ASSERT_TRUE(op->Compute(t, &out).IsOk());
  45. op = std::make_shared<MaskOp>(RelationalOp::kLessEqual, v, DataType(DataType::DE_UINT16));
  46. ASSERT_TRUE(op->Compute(t, &out).IsOk());
  47. op = std::make_shared<MaskOp>(RelationalOp::kLess, v, DataType(DataType::DE_UINT16));
  48. ASSERT_TRUE(op->Compute(t, &out).IsOk());
  49. op = std::make_shared<MaskOp>(RelationalOp::kGreaterEqual, v, DataType(DataType::DE_UINT16));
  50. ASSERT_TRUE(op->Compute(t, &out).IsOk());
  51. op = std::make_shared<MaskOp>(RelationalOp::kGreater, v, DataType(DataType::DE_UINT16));
  52. ASSERT_TRUE(op->Compute(t, &out).IsOk());
  53. }