• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ops/hashtable_lookup.h"
17 
18 #include <vector>
19 
20 #include "utils/check_convert_utils.h"
21 #include "ops/op_utils.h"
22 
23 namespace mindspore {
24 namespace ops {
HashtableLookupInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)25 AbstractBasePtr HashtableLookupInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
26                                      const std::vector<AbstractBasePtr> &input_args) {
27   MS_EXCEPTION_IF_NULL(primitive);
28   const int64_t input_num = 3;
29   auto op_name = primitive->name();
30   CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, op_name);
31   std::vector<int64_t> hits_shape;
32   auto input = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape];
33   (void)CheckAndConvertUtils::CheckInteger("logits size", SizeToLong(input.size()), kGreaterEqual, 1, op_name);
34   hits_shape.push_back(input[0]);
35 
36   auto value_type = input_args[kInputIndex2]->BuildType();
37   MS_EXCEPTION_IF_NULL(value_type);
38   auto tensor_type = value_type->cast<TensorTypePtr>();
39   MS_EXCEPTION_IF_NULL(tensor_type);
40   auto data_type = tensor_type->element();
41   std::vector<int64_t> value_shape;
42   auto output = std::make_shared<abstract::AbstractTensor>(data_type, value_shape);
43   auto hits = std::make_shared<abstract::AbstractTensor>(kInt8, hits_shape);
44   AbstractBasePtrList output1 = {output, hits};
45   return std::make_shared<abstract::AbstractTuple>(output1);
46 }
47 REGISTER_PRIMITIVE_C(kNameHashtableLookup, HashtableLookup);
48 }  // namespace ops
49 }  // namespace mindspore
50