• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/hsigmoid.h"
17 #include <string>
18 #include <set>
19 #include <map>
20 
21 namespace mindspore {
22 namespace ops {
23 namespace {
InferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)24 abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
25   MS_EXCEPTION_IF_NULL(primitive);
26   for (const auto &item : input_args) {
27     MS_EXCEPTION_IF_NULL(item);
28   }
29   auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape];
30   return std::make_shared<abstract::Shape>(in_shape);
31 }
32 
InferType(const PrimitivePtr & prim,const std::vector<AbstractBasePtr> & input_args)33 TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
34   if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr &a) { return a == nullptr; })) {
35     MS_LOG(EXCEPTION) << "nullptr";
36   }
37   std::map<std::string, TypePtr> types;
38   const std::set<TypePtr> valid_types = {kInt8, kInt16, kInt32, kInt64, kFloat16, kFloat32};
39   (void)types.emplace("input_x", input_args[0]->BuildType());
40   return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name());
41 }
42 }  // namespace
HSigmoidInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)43 AbstractBasePtr HSigmoidInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
44                               const std::vector<AbstractBasePtr> &input_args) {
45   return std::make_shared<abstract::AbstractTensor>(InferType(primitive, input_args),
46                                                     InferShape(primitive, input_args)->shape());
47 }
48 }  // namespace ops
49 }  // namespace mindspore
50