axis_set.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <cstddef>
8 #include <ostream>
9 #include <set>
10 #include <vector>
11 
12 #include "ngraph/attribute_adapter.hpp"
13 #include "ngraph/ngraph_visibility.hpp"
14 
15 namespace ngraph
16 {
17  /// \brief A set of axes.
18  class AxisSet : public std::set<size_t>
19  {
20  public:
21  NGRAPH_API AxisSet();
22 
23  NGRAPH_API AxisSet(const std::initializer_list<size_t>& axes);
24 
25  NGRAPH_API AxisSet(const std::set<size_t>& axes);
26 
27  NGRAPH_API AxisSet(const std::vector<size_t>& axes);
28 
29  NGRAPH_API AxisSet(const AxisSet& axes);
30 
31  NGRAPH_API AxisSet& operator=(const AxisSet& v);
32 
33  NGRAPH_API AxisSet& operator=(AxisSet&& v) noexcept;
34 
35  NGRAPH_API std::vector<int64_t> to_vector() const;
36  };
37 
38  template <>
39  class NGRAPH_API AttributeAdapter<AxisSet> : public ValueAccessor<std::vector<int64_t>>
40  {
41  public:
43  : m_ref(value)
44  {
45  }
46 
47  const std::vector<int64_t>& get() override;
48  void set(const std::vector<int64_t>& value) override;
49  static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<AxisSet>", 0};
50  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
51  operator AxisSet&() { return m_ref; }
52 
53  protected:
54  AxisSet& m_ref;
55  std::vector<int64_t> m_buffer;
56  bool m_buffer_valid{false};
57  };
58 
59  NGRAPH_API
60  std::ostream& operator<<(std::ostream& s, const AxisSet& axis_set);
61 } // namespace ngraph
void set(const std::vector< int64_t > &value) override
Sets the value.
const std::vector< int64_t > & get() override
Returns the value.
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:161
A set of axes.
Definition: axis_set.hpp:19
Provides access to an attribute of type AT as a value accessor type VAT.
Definition: attribute_adapter.hpp:49
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27