Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / ir / OperandIndexSequence.cc
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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/OperandIndexSequence.h"
18
19 #include <algorithm>
20 #include <sstream>
21
22 namespace onert
23 {
24 namespace ir
25 {
26
27 OperandIndexSequence::OperandIndexSequence(std::initializer_list<OperandIndex> list) : _vec(list)
28 {
29   // DO NOTHING
30 }
31
32 OperandIndexSequence::OperandIndexSequence(std::initializer_list<int32_t> list)
33 {
34   for (auto &&val : list)
35   {
36     _vec.emplace_back(static_cast<uint32_t>(val));
37   }
38 }
39
40 OperandIndexSequence::OperandIndexSequence(std::initializer_list<uint32_t> list)
41 {
42   for (auto &&val : list)
43   {
44     _vec.emplace_back(val);
45   }
46 }
47
48 bool OperandIndexSequence::contains(const OperandIndex &index) const
49 {
50   return std::find(_vec.begin(), _vec.end(), index) != _vec.end();
51 }
52
53 void OperandIndexSequence::replace(const OperandIndex &from, const OperandIndex &to)
54 {
55   std::replace(_vec.begin(), _vec.end(), from, to);
56 }
57
58 bool OperandIndexSequence::operator==(const OperandIndexSequence &other) const
59 {
60   return _vec == other._vec;
61 }
62
63 OperandIndexSequence OperandIndexSequence::operator+(const OperandIndexSequence &other) const
64 {
65   OperandIndexSequence ret = *this;
66   ret.append(other);
67   return ret;
68 }
69
70 std::ostream &operator<<(std::ostream &o, const OperandIndexSequence &operand_seq)
71 {
72   std::string delimeter;
73   for (const auto &ind : operand_seq._vec)
74   {
75     o << delimeter << ind;
76     delimeter = ',';
77   }
78   return o;
79 }
80
81 } // namespace ir
82 } // namespace onert