1 /** 2 * Copyright 2019-2022 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 #ifndef MINDSPORE_CCSRC_FRONTEND_OPERATOR_COMPOSITE_LIST_OPERATION_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_OPERATOR_COMPOSITE_LIST_OPERATION_H_ 19 20 #include <string> 21 #include <memory> 22 #include <vector> 23 24 #include "ir/meta_func_graph.h" 25 26 namespace mindspore { 27 // namespace to support composite operators definition 28 namespace prim { 29 class ListAppend : public MetaFuncGraph { 30 public: ListAppend(const std::string & name)31 explicit ListAppend(const std::string &name) : MetaFuncGraph(name) {} 32 ~ListAppend() override = default; 33 MS_DECLARE_PARENT(ListAppend, MetaFuncGraph) 34 FuncGraphPtr GenerateFuncGraph(const abstract::AbstractBasePtrList &args_list) override; 35 friend std::ostream &operator<<(std::ostream &os, const ListAppend &list_append) { 36 os << list_append.name_; 37 return os; 38 } 39 friend bool operator==(const ListAppend &lhs, const ListAppend &rhs) { return lhs.name_ == rhs.name_; } 40 }; 41 using ListAppendPtr = std::shared_ptr<ListAppend>; 42 43 class ListInsert : public MetaFuncGraph { 44 public: ListInsert(const std::string & name)45 explicit ListInsert(const std::string &name) : MetaFuncGraph(name) {} 46 ~ListInsert() override = default; 47 MS_DECLARE_PARENT(ListInsert, MetaFuncGraph) 48 FuncGraphPtr GenerateFuncGraph(const abstract::AbstractBasePtrList &args_list) override; 49 friend std::ostream &operator<<(std::ostream &os, const ListInsert &list_insert) { 50 os << list_insert.name_; 51 return os; 52 } 53 friend bool operator==(const ListInsert &lhs, const ListInsert &rhs) { return lhs.name_ == rhs.name_; } 54 }; 55 using ListInsertPtr = std::shared_ptr<ListInsert>; 56 57 class ListPop : public MetaFuncGraph { 58 public: ListPop(const std::string & name)59 explicit ListPop(const std::string &name) : MetaFuncGraph(name) {} 60 ~ListPop() override = default; 61 MS_DECLARE_PARENT(ListPop, MetaFuncGraph) 62 FuncGraphPtr GenerateFuncGraph(const abstract::AbstractBasePtrList &a_list) override; 63 friend std::ostream &operator<<(std::ostream &os, const ListPop &list_pop) { 64 os << list_pop.name_; 65 return os; 66 } 67 friend bool operator==(const ListPop &lhs, const ListPop &rhs) { return lhs.name_ == rhs.name_; } 68 }; 69 using ListPopPtr = std::shared_ptr<ListPop>; 70 71 class ListClear : public MetaFuncGraph { 72 public: ListClear(const std::string & name)73 explicit ListClear(const std::string &name) : MetaFuncGraph(name) {} 74 ~ListClear() override = default; 75 MS_DECLARE_PARENT(ListClear, MetaFuncGraph) 76 FuncGraphPtr GenerateFuncGraph(const abstract::AbstractBasePtrList &a_list) override; 77 friend std::ostream &operator<<(std::ostream &os, const ListClear &list_clear) { 78 os << list_clear.name_; 79 return os; 80 } 81 friend bool operator==(const ListClear &lhs, const ListClear &rhs) { return lhs.name_ == rhs.name_; } 82 }; 83 using ListClearPtr = std::shared_ptr<ListClear>; 84 85 class ListExtend : public MetaFuncGraph { 86 public: ListExtend(const std::string & name)87 explicit ListExtend(const std::string &name) : MetaFuncGraph(name) {} 88 ~ListExtend() override = default; 89 MS_DECLARE_PARENT(ListExtend, MetaFuncGraph) 90 FuncGraphPtr GenerateFuncGraph(const abstract::AbstractBasePtrList &a_list) override; 91 friend std::ostream &operator<<(std::ostream &os, const ListExtend &list_extend) { 92 os << list_extend.name_; 93 return os; 94 } 95 friend bool operator==(const ListExtend &lhs, const ListExtend &rhs) { return lhs.name_ == rhs.name_; } 96 97 private: 98 static void AddNodeToElems(const AbstractBasePtr &arg, const FuncGraphPtr &ret, std::vector<AnfNodePtr> *elems); 99 }; 100 using ListExtendPtr = std::shared_ptr<ListExtend>; 101 102 class ListReverse : public MetaFuncGraph { 103 public: ListReverse(const std::string & name)104 explicit ListReverse(const std::string &name) : MetaFuncGraph(name) {} 105 ~ListReverse() override = default; 106 MS_DECLARE_PARENT(ListReverse, MetaFuncGraph) 107 FuncGraphPtr GenerateFuncGraph(const abstract::AbstractBasePtrList &a_list) override; 108 friend std::ostream &operator<<(std::ostream &os, const ListReverse &list_reverse) { 109 os << list_reverse.name_; 110 return os; 111 } 112 friend bool operator==(const ListReverse &lhs, const ListReverse &rhs) { return lhs.name_ == rhs.name_; } 113 }; 114 using ListReversePtr = std::shared_ptr<ListReverse>; 115 } // namespace prim 116 } // namespace mindspore 117 118 #endif // MINDSPORE_CCSRC_FRONTEND_OPERATOR_COMPOSITE_LIST_OPERATION_H_ 119