• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
3  *
4  * Copyright 2019 Huawei Technologies Co., Ltd
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef MINDSPORE_CORE_ABSTRACT_UTILS_H_
20 #define MINDSPORE_CORE_ABSTRACT_UTILS_H_
21 
22 #include <vector>
23 #include <utility>
24 #include <memory>
25 #include <string>
26 #include "abstract/abstract_value.h"
27 #include "utils/any.h"
28 #include "utils/misc.h"
29 #include "utils/shape_utils.h"
30 
31 namespace mindspore {
32 namespace abstract {
33 ValuePtr ValueJoin(const ValuePtr &value1, const ValuePtr &value2);
34 TypePtr TypeJoin(const TypePtr &type1, const TypePtr &type2);
35 ShapePtr ShapeJoin(const ShapePtr &shape1, const ShapePtr &shape2);
36 
37 AbstractBasePtr AbstractJoin(const AbstractBasePtrList &args_spec_list);
38 AbstractBasePtrList AbstractJoin(const AbstractBasePtrList &spec1, const AbstractBasePtrList &spec2);
39 
40 // Return an abstract value for the sensitivity of x.
41 // The sensitivity of a function is an Env
42 // The sensitivity of J(x) is x
43 // else self.Clone;
44 AbstractBasePtr SensitivityTransform(const AbstractBasePtr &spec);
45 
46 TypePtr CheckTypeList(const TypePtr &predicate, const TypePtrList &args_type_list);
47 
48 bool CheckType(const TypePtr &expected_type, const TypePtr &x);
49 
50 int64_t GetPositiveAxis(int64_t axis_value, size_t increment);
51 
52 ShapeVector BroadcastShape(ShapeVector shpx, ShapeVector shpy);
53 
54 MS_CORE_API size_t TypeIdSize(const TypeId data_type);
55 size_t ShapeSize(const std::vector<size_t> &shape);
56 
57 // Get broadcasted shape for binary element-wise operation
58 ShapePtr GetBroadcastShape(const std::string &op, const AbstractTensorPtr &tensor_x, const AbstractTensorPtr &tensor_y);
59 
60 // Check dynamic shape routine
61 void CheckMinMaxShape(const ShapeVector &shape, ShapeVector *min_shape, ShapeVector *max_shape);
62 
63 // Get 3rd argument for UnsortedSegmentOps' inferImpl function
64 int64_t GetUnsortedSegmentOpScalarArg(const AbstractBasePtrList &args_spec_list, const std::string &op_name);
65 AbstractBasePtr MakeAbstract(const BaseShapePtr &base_shape, const TypePtr &type);
66 AbstractBasePtr MakeMonadAbstract(const MonadTypePtr &type);
67 AbstractBasePtr MakeAbstractTensor(const ShapePtr &shape, const TypePtr &type);
68 }  // namespace abstract
69 }  // namespace mindspore
70 #endif  // MINDSPORE_CORE_ABSTRACT_UTILS_H_
71