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.

log1p.cc 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright 2021 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 "ops/log1p.h"
  17. #include <memory>
  18. #include <set>
  19. #include "ops/op_utils.h"
  20. #include "utils/check_convert_utils.h"
  21. #include "utils/tensor_construct_utils.h"
  22. #include "abstract/primitive_infer_map.h"
  23. namespace mindspore {
  24. namespace ops {
  25. // log1p
  26. namespace {
  27. abstract::ShapePtr Log1pInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
  28. MS_EXCEPTION_IF_NULL(primitive);
  29. auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape());
  30. auto in_shape = shape_map[kShape];
  31. auto min_shape = shape_map[kMinShape];
  32. auto max_shape = shape_map[kMaxShape];
  33. return std::make_shared<abstract::Shape>(in_shape, min_shape, max_shape);
  34. }
  35. TypePtr Log1pInferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
  36. MS_EXCEPTION_IF_NULL(prim);
  37. auto prim_name = prim->name();
  38. // check
  39. std::set<TypePtr> valid_index_types = {kFloat16, kFloat32};
  40. auto x_type =
  41. CheckAndConvertUtils::CheckTensorTypeValid("x", input_args[0]->BuildType(), valid_index_types, prim_name);
  42. return x_type;
  43. }
  44. } // namespace
  45. AbstractBasePtr Log1pInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
  46. const std::vector<AbstractBasePtr> &input_args) {
  47. MS_EXCEPTION_IF_NULL(primitive);
  48. auto abs = std::make_shared<abstract::AbstractTensor>(Log1pInferType(primitive, input_args),
  49. Log1pInferShape(primitive, input_args));
  50. return abs;
  51. }
  52. REGISTER_PRIMITIVE_EVAL_IMPL(Log1p, prim::kPrimLog1p, Log1pInfer, nullptr, true);
  53. } // namespace ops
  54. } // namespace mindspore