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