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
17 #include "ops/round.h"
18 #include "ops/op_utils.h"
19 #include "utils/check_convert_utils.h"
20 #include "abstract/primitive_infer_map.h"
21
22 namespace mindspore {
23 namespace ops {
24 namespace {
InferShape(const std::vector<AbstractBasePtr> & input_args)25 abstract::ShapePtr InferShape(const std::vector<AbstractBasePtr> &input_args) {
26 auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape];
27 return std::make_shared<abstract::Shape>(x_shape);
28 }
29
InferType(const PrimitivePtr & prim,const std::vector<AbstractBasePtr> & input_args)30 TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
31 MS_EXCEPTION_IF_NULL(input_args[0]);
32 auto infer_type = input_args[0]->BuildType();
33 return CheckAndConvertUtils::CheckTensorTypeValid("x", infer_type, common_valid_types, prim->name());
34 }
35 } // namespace
36
RoundInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)37 AbstractBasePtr RoundInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
38 const std::vector<AbstractBasePtr> &input_args) {
39 return std::make_shared<abstract::AbstractTensor>(InferType(primitive, input_args), InferShape(input_args)->shape());
40 }
41 REGISTER_PRIMITIVE_C(kNameRound, Round);
42 } // namespace ops
43 } // namespace mindspore
44