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_op.cc 1.6 kB

5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 "dataset/kernels/data/mask_op.h"
  17. #include "dataset/core/tensor.h"
  18. #include "dataset/kernels/tensor_op.h"
  19. namespace mindspore {
  20. namespace dataset {
  21. Status MaskOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
  22. IO_CHECK(input, output);
  23. std::shared_ptr<Tensor> temp_output;
  24. CHECK_FAIL_RETURN_UNEXPECTED(type_.IsNumeric(), "Cannot generate a string mask. Type should be numeric.");
  25. RETURN_IF_NOT_OK(Mask(input, &temp_output, value_, op_));
  26. // cast the output to the the required type. Skip casting if type_ is bool.
  27. if (type_ != DataType::DE_BOOL) {
  28. RETURN_IF_NOT_OK(cast_->Compute(temp_output, output));
  29. } else {
  30. *output = std::move(temp_output);
  31. }
  32. return Status::OK();
  33. }
  34. Status MaskOp::OutputType(const std::vector<DataType> &inputs, std::vector<DataType> &outputs) {
  35. RETURN_IF_NOT_OK(TensorOp::OutputType(inputs, outputs));
  36. outputs[0] = type_;
  37. return Status::OK();
  38. }
  39. } // namespace dataset
  40. } // namespace mindspore