• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/custom_extract_features.h"
18 #include "utils/check_convert_utils.h"
19 #include "abstract/primitive_infer_map.h"
20 #include "ops/op_utils.h"
21 
22 namespace mindspore {
23 namespace ops {
CustomExtractFeaturesInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)24 AbstractBasePtr CustomExtractFeaturesInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
25                                            const std::vector<AbstractBasePtr> &input_args) {
26   MS_EXCEPTION_IF_NULL(primitive);
27   MS_EXCEPTION_IF_NULL(input_args[0]);
28   // Infer type
29   auto output0_type = kInt32;
30   auto output1_type = kFloat32;
31 
32   // Infer shape
33   std::vector<int64_t> out_shape;
34   auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape];
35   auto string_num = input_shape[0];
36   if (string_num == 0) {
37     out_shape.push_back(1);
38   } else {
39     out_shape.push_back(string_num);
40   }
41 
42   auto output0 = std::make_shared<abstract::AbstractTensor>(output0_type, out_shape);
43   auto output1 = std::make_shared<abstract::AbstractTensor>(output1_type, out_shape);
44   AbstractBasePtrList output = {output0, output1};
45   return std::make_shared<abstract::AbstractTuple>(output);
46 }
47 REGISTER_PRIMITIVE_C(kNameCustomExtractFeatures, CustomExtractFeatures);
48 }  // namespace ops
49 }  // namespace mindspore
50