gather.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 "ngraph/op/op.hpp"
20 
21 namespace ngraph
22 {
23  namespace op
24  {
25  namespace v0
26  {
27  /// \brief Gather slices from axis of params according to indices
28  class NGRAPH_DEPRECATED(
29  "This operation is deprecated and will be removed soon. "
30  "Use v1::Gather instead of it.") NGRAPH_API Gather : public Op
31  {
32  NGRAPH_SUPPRESS_DEPRECATED_START
33  public:
34  static constexpr NodeTypeInfo type_info{"Gather", 0};
35  const NodeTypeInfo& get_type_info() const override { return type_info; }
36  Gather() = default;
37  /// \param params The tensor from which slices are gathered
38  /// \param indices Index tensor: Data type must be `element::i32` or `element::i64`
39  /// \param axis Axis in params to gather
40  Gather(const Output<Node>& params, const Output<Node>& indices, size_t axis = 0);
41 
42  void validate_and_infer_types() override;
43 
44  size_t get_axis() const { return m_axis; }
45  void set_axis(size_t axis) { m_axis = axis; }
46  virtual std::shared_ptr<Node>
47  clone_with_new_inputs(const OutputVector& new_args) const override;
48  bool evaluate(const HostTensorVector& outputs,
49  const HostTensorVector& inputs) const override;
50 
51  protected:
52  size_t m_axis;
53  NGRAPH_SUPPRESS_DEPRECATED_END
54  };
55  }
56 
57  namespace v1
58  {
59  /// \brief Gather slices from axis of params according to indices
60  class NGRAPH_API Gather : public Op
61  {
62  public:
63  static const int64_t AXIS_NOT_SET_VALUE = std::numeric_limits<int64_t>::max();
64  static constexpr NodeTypeInfo type_info{"Gather", 1};
65  const NodeTypeInfo& get_type_info() const override { return type_info; }
66  Gather() = default;
67  /// \param params The tensor from which slices are gathered
68  /// \param indices Tensor with indexes to gather
69  /// \param axis The tensor is a dimension index to gather data from
70  Gather(const Output<Node>& params,
71  const Output<Node>& indices,
72  const Output<Node>& axis);
73 
74  bool visit_attributes(AttributeVisitor& visitor) override;
75  int64_t get_axis() const;
76 
77  void validate_and_infer_types() override;
78 
79  virtual std::shared_ptr<Node>
80  clone_with_new_inputs(const OutputVector& new_args) const override;
81 
82  bool evaluate(const HostTensorVector& outputs,
83  const HostTensorVector& inputs) const override;
84  };
85  }
86 
87  // latest stable opset version
88  NGRAPH_SUPPRESS_DEPRECATED_START
89  using v0::Gather;
90  NGRAPH_SUPPRESS_DEPRECATED_END
91  }
92 }
ngraph::op::v1::Gather
Gather slices from axis of params according to indices.
Definition: gather.hpp:61
ngraph::op::v1::Gather::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: gather.hpp:65
ngraph::op::v1::Gather::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v1::Gather::Gather
Gather(const Output< Node > &params, const Output< Node > &indices, const Output< Node > &axis)
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29