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.

execute.cc 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "minddata/dataset/include/execute.h"
  17. #include "minddata/dataset/include/de_tensor.h"
  18. #include "minddata/dataset/include/tensor.h"
  19. #include "minddata/dataset/kernels/tensor_op.h"
  20. namespace mindspore {
  21. namespace dataset {
  22. namespace api {
  23. Execute::Execute(const std::shared_ptr<TensorOperation> &op) : op_(std::move(op)) {}
  24. std::shared_ptr<tensor::MSTensor> Execute::operator()(std::shared_ptr<tensor::MSTensor> input){
  25. // Build the op
  26. if (op_ == nullptr) {
  27. MS_LOG(ERROR) << "Input TensorOperation is not valid";
  28. return nullptr;
  29. }
  30. std::shared_ptr<Tensor> de_input = std::dynamic_pointer_cast<tensor::DETensor>(input)->tensor();
  31. if (de_input == nullptr) {
  32. MS_LOG(ERROR) << "Input Tensor is not valid";
  33. return nullptr;
  34. }
  35. std::shared_ptr<TensorOp> transform = op_->Build();
  36. std::shared_ptr<Tensor> de_output;
  37. Status rc = transform->Compute(de_input, &de_output);
  38. if (rc.IsError()) {
  39. // execution failed
  40. MS_LOG(ERROR) << "Operation execution failed : " << rc.ToString();
  41. return nullptr;
  42. }
  43. return std::make_shared<tensor::DETensor>(std::move(de_output));
  44. }
  45. } // namespace api
  46. } // namespace dataset
  47. } // namespace mindspore