• 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 "ir/cell.h"
18 
19 #include <utility>
20 #include <map>
21 #include <algorithm>
22 
23 #include "abstract/abstract_value.h"
24 
25 namespace mindspore {
26 using mindspore::abstract::AbstractFunction;
27 
ToAbstract()28 abstract::AbstractBasePtr Cell::ToAbstract() { return nullptr; }
29 
operator ==(const Value & other) const30 bool Cell::operator==(const Value &other) const {
31   if (other.isa<Cell>()) {
32     auto other_prim = static_cast<const Cell &>(other);
33     return *this == other_prim;
34   } else {
35     return false;
36   }
37 }
38 
operator ==(const Cell & other) const39 bool Cell::operator==(const Cell &other) const {
40   if (name() != other.name()) {
41     return false;
42   }
43   if (attrs_.size() != other.attrs_.size()) {
44     return false;
45   }
46   auto all = std::all_of(attrs_.begin(), attrs_.end(), [&other](const std::pair<std::string, ValuePtr> &item) -> bool {
47     if (item.second == nullptr) {
48       return false;
49     }
50     auto iter = other.attrs_.find(item.first);
51     if (iter == other.attrs_.end()) {
52       return false;
53     }
54     MS_EXCEPTION_IF_NULL(iter->second);
55     return *item.second == *iter->second;
56   });
57   return all;
58 }
59 
GetAttrString() const60 std::string Cell::GetAttrString() const {
61   std::ostringstream buffer;
62   bool begin = true;
63   buffer << "{" << std::endl;
64   for (auto &attr : attrs_) {
65     if (!begin) {
66       buffer << ", " << std::endl;
67     } else {
68       begin = false;
69     }
70     buffer << attr.first << ":" << attr.second->ToString();
71   }
72   buffer << "}";
73   return buffer.str();
74 }
75 
ToString() const76 std::string Cell::ToString() const {
77   std::ostringstream buffer;
78   buffer << "Cell " << name();
79   return buffer.str();
80 }
81 
DelAttr(const std::string & name)82 void Cell::DelAttr(const std::string &name) { attrs_.erase(name); }
83 }  // namespace mindspore
84