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 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef ENABLE_ANDROID
  21. #include "utils/log_adapter.h"
  22. #else
  23. #include "mindspore/lite/src/common/log_adapter.h"
  24. #endif
  25. namespace mindspore {
  26. namespace dataset {
  27. Execute::Execute(std::shared_ptr<TensorOperation> op) : op_(std::move(op)) {}
  28. std::shared_ptr<tensor::MSTensor> Execute::operator()(std::shared_ptr<tensor::MSTensor> input) {
  29. // Build the op
  30. if (op_ == nullptr) {
  31. MS_LOG(ERROR) << "Input TensorOperation is not valid";
  32. return nullptr;
  33. }
  34. std::shared_ptr<Tensor> de_input = std::dynamic_pointer_cast<tensor::DETensor>(input)->tensor();
  35. if (de_input == nullptr) {
  36. MS_LOG(ERROR) << "Input Tensor is not valid";
  37. return nullptr;
  38. }
  39. std::shared_ptr<TensorOp> transform = op_->Build();
  40. std::shared_ptr<Tensor> de_output;
  41. Status rc = transform->Compute(de_input, &de_output);
  42. if (rc.IsError()) {
  43. // execution failed
  44. MS_LOG(ERROR) << "Operation execution failed : " << rc.ToString();
  45. return nullptr;
  46. }
  47. return std::make_shared<tensor::DETensor>(std::move(de_output));
  48. }
  49. std::shared_ptr<dataset::Tensor> Execute::operator()(std::shared_ptr<dataset::Tensor> input) {
  50. // Build the op
  51. if (op_ == nullptr) {
  52. MS_LOG(ERROR) << "Input TensorOperation is not valid";
  53. return nullptr;
  54. }
  55. if (input == nullptr) {
  56. MS_LOG(ERROR) << "Input Tensor is not valid";
  57. return nullptr;
  58. }
  59. // will add validate params once API is set
  60. std::shared_ptr<TensorOp> transform = op_->Build();
  61. std::shared_ptr<Tensor> de_output;
  62. Status rc = transform->Compute(input, &de_output);
  63. if (rc.IsError()) {
  64. // execution failed
  65. MS_LOG(ERROR) << "Operation execution failed : " << rc.ToString();
  66. return nullptr;
  67. }
  68. return de_output;
  69. }
  70. } // namespace dataset
  71. } // namespace mindspore