axis_set.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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 #pragma once
18 
19 #include <cstddef>
20 #include <ostream>
21 #include <set>
22 #include <vector>
23 
24 #include "ngraph/attribute_adapter.hpp"
25 #include "ngraph/ngraph_visibility.hpp"
26 
27 namespace ngraph
28 {
29  /// \brief A set of axes.
30  class AxisSet : public std::set<size_t>
31  {
32  public:
33  NGRAPH_API AxisSet();
34 
35  NGRAPH_API AxisSet(const std::initializer_list<size_t>& axes);
36 
37  NGRAPH_API AxisSet(const std::set<size_t>& axes);
38 
39  NGRAPH_API AxisSet(const std::vector<size_t>& axes);
40 
41  NGRAPH_API AxisSet(const AxisSet& axes);
42 
43  NGRAPH_API AxisSet& operator=(const AxisSet& v);
44 
45  NGRAPH_API AxisSet& operator=(AxisSet&& v) noexcept;
46 
47  NGRAPH_API std::vector<int64_t> to_vector() const;
48  };
49 
50  template <>
51  class NGRAPH_API AttributeAdapter<AxisSet> : public ValueAccessor<std::vector<int64_t>>
52  {
53  public:
55  : m_ref(value)
56  {
57  }
58 
59  const std::vector<int64_t>& get() override;
60  void set(const std::vector<int64_t>& value) override;
61  static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<AxisSet>", 0};
62  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
63  operator AxisSet&() { return m_ref; }
64  protected:
65  AxisSet& m_ref;
66  std::vector<int64_t> m_buffer;
67  bool m_buffer_valid{false};
68  };
69 
70  NGRAPH_API
71  std::ostream& operator<<(std::ostream& s, const AxisSet& axis_set);
72 }
ngraph::AxisSet
A set of axes.
Definition: axis_set.hpp:31
ngraph::ValueAccessor
Provides access to an attribute of type AT as a value accessor type VAT.
Definition: attribute_adapter.hpp:61
ngraph::DiscreteTypeInfo
Definition: type.hpp:39
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::AttributeAdapter
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:170
ngraph::AttributeAdapter< AxisSet >::get
const std::vector< int64_t > & get() override
Returns the value.
ngraph::AttributeAdapter< AxisSet >::set
void set(const std::vector< int64_t > &value) override
Sets the value.