gather.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 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 v1
26  {
27  /// \brief Gather slices from axis of params according to indices
28  class NGRAPH_API Gather : public Op
29  {
30  public:
31  static const int64_t AXIS_NOT_SET_VALUE = std::numeric_limits<int64_t>::max();
32  static constexpr NodeTypeInfo type_info{"Gather", 1};
33  const NodeTypeInfo& get_type_info() const override { return type_info; }
34  Gather() = default;
35  /// \param params The tensor from which slices are gathered
36  /// \param indices Tensor with indexes to gather
37  /// \param axis The tensor is a dimension index to gather data from
38  Gather(const Output<Node>& params,
39  const Output<Node>& indices,
40  const Output<Node>& axis);
41 
42  bool visit_attributes(AttributeVisitor& visitor) override;
43  int64_t get_axis() const;
44 
45  void validate_and_infer_types() override;
46 
47  virtual std::shared_ptr<Node>
48  clone_with_new_inputs(const OutputVector& new_args) const override;
49 
50  bool evaluate(const HostTensorVector& outputs,
51  const HostTensorVector& inputs) const override;
52  bool evaluate_lower(const HostTensorVector& outputs) const override;
53  bool evaluate_upper(const HostTensorVector& outputs) const override;
54 
55  bool constant_fold(OutputVector& output_values,
56  const OutputVector& inputs_values) override;
57 
58  private:
59  static const int PARAMS;
60  static const int INDICES;
61  static const int AXIS;
62 
63  bool evaluate_gather(const HostTensorVector& outputs,
64  const HostTensorVector& inputs) const;
65  };
66  } // namespace v1
67  } // namespace op
68 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:71
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Root of all actual ops.
Definition: op.hpp:29
Gather slices from axis of params according to indices.
Definition: gather.hpp:29
const NodeTypeInfo & get_type_info() const override
Definition: gather.hpp:33
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
Gather(const Output< Node > &params, const Output< Node > &indices, const Output< Node > &axis)
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39