1 /**
2 * Copyright 2020-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
17 #include "ops/floor.h"
18 #include <string>
19 #include <algorithm>
20 #include <memory>
21 #include <set>
22 #include <vector>
23 #include "utils/check_convert_utils.h"
24 #include "abstract/primitive_infer_map.h"
25
26 namespace mindspore {
27 namespace ops {
28 namespace {
InferShape(const std::vector<AbstractBasePtr> & input_args)29 abstract::ShapePtr InferShape(const std::vector<AbstractBasePtr> &input_args) {
30 auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape];
31 return std::make_shared<abstract::Shape>(in_shape);
32 }
33
InferType(const PrimitivePtr & prim,const std::vector<AbstractBasePtr> & input_args)34 TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
35 const std::set<TypePtr> valid_types = {kFloat16, kFloat32, kFloat64};
36 std::map<std::string, TypePtr> types;
37 (void)types.emplace("x", input_args[0]->BuildType());
38 return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name());
39 }
40 } // namespace
FloorInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)41 AbstractBasePtr FloorInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
42 const std::vector<AbstractBasePtr> &input_args) {
43 MS_EXCEPTION_IF_NULL(primitive);
44 const int64_t input_num = 1;
45 CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name());
46 return std::make_shared<abstract::AbstractTensor>(InferType(primitive, input_args), InferShape(input_args));
47 }
48 REGISTER_PRIMITIVE_C(kNameFloor, Floor);
49 } // namespace ops
50 } // namespace mindspore
51