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.

cast.cc 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * Copyright 2019-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 "src/ops/ops.h"
  17. #include "include/errorcode.h"
  18. #include "utils/log_adapter.h"
  19. #include "src/ir/tensor.h"
  20. namespace mindspore::lite {
  21. int Cast::InferShape(std::vector<tensor::Tensor *> inputs_, std::vector<tensor::Tensor *> outputs_) {
  22. MS_ASSERT(this->primitive != nullptr);
  23. auto input = inputs_.front();
  24. MS_ASSERT(input != nullptr);
  25. auto output = outputs_.front();
  26. MS_ASSERT(output != nullptr);
  27. if (inputs_.size() != kSingleNum || outputs_.size() != kSingleNum) {
  28. MS_LOG(ERROR) << "tensor number is error.";
  29. return RET_INPUT_TENSOR_ERROR;
  30. }
  31. auto cast_prim = this->primitive->value_as_Cast();
  32. MS_ASSERT(cast_prim != nullptr);
  33. if (input->data_type() != cast_prim->srcT()) {
  34. MS_LOG(ERROR) << "input dataType is error";
  35. return RET_INPUT_TENSOR_ERROR;
  36. }
  37. if (kSupportDataType.find(input->data_type()) == kSupportDataType.end()) {
  38. MS_LOG(ERROR) << "Unsupported input data type " << input->data_type();
  39. return RET_INPUT_TENSOR_ERROR;
  40. }
  41. if (cast_prim->dstT() != kNumberTypeFloat && cast_prim->dstT() != kNumberTypeFloat32) {
  42. MS_LOG(ERROR) << "Invalid output datatype " << cast_prim->dstT();
  43. return RET_INPUT_TENSOR_ERROR;
  44. }
  45. output->SetFormat(input->GetFormat());
  46. output->set_shape(input->shape());
  47. output->set_data_type(input->data_type());
  48. return RET_OK;
  49. }
  50. } // namespace mindspore::lite