output.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 <memory>
20 #include <string>
21 #include <unordered_set>
22 #include <vector>
23 
24 #include "ngraph/descriptor/input.hpp"
25 #include "ngraph/descriptor/tensor.hpp"
26 #include "ngraph/node_output.hpp"
27 
28 namespace ngraph
29 {
30  // The forward declaration of Node is needed here because Node has a deque of
31  // Outputs, and Output is an incomplete type at this point. STL containers of
32  // incomplete type have undefined behavior according to the C++11 standard, and
33  // in practice including node.hpp here was causing compilation errors on some
34  // systems (namely macOS).
35  class Node;
36 
37  namespace descriptor
38  {
39  // Describes an output tensor of an op
40  class NGRAPH_API Output
41  {
42  public:
43  Output()
44  : m_node(nullptr)
45  , m_index(0)
46  , m_tensor(nullptr)
47  , m_inputs()
48  {
49  }
50 
51  /// \param node Node that owns this output.
52  /// \param index Position of the output tensor in all output tensors
53  /// \param tensor The tensor where the value will be written
54  Output(Node* node, size_t index, const std::shared_ptr<Tensor>& tensor);
55 
56  std::shared_ptr<Node> get_node() const;
57  size_t get_index() const { return m_index; }
58  ngraph::Output<Node> get_output() const;
59  std::shared_ptr<Tensor> get_tensor_ptr() const { return m_tensor; }
60  void set_tensor_ptr(const std::shared_ptr<Tensor>& tensor) { m_tensor = tensor; }
61  void add_input(Input* input);
62  void remove_input(Input* input);
63  const std::vector<Input*>& get_inputs() const { return m_inputs; }
64  Tensor& get_tensor() const;
65 
66  /// \return the shape of the output
67  const Shape& get_shape() const;
68 
69  /// \return the partial shape of the output
71 
72  /// \return the element type of the output
74 
75  Output(const Output&) = default;
76  Output(Output&&) = default;
77  Output& operator=(const Output&) = default;
78 
79  protected:
80  Node* m_node;
81  size_t m_index;
82  std::shared_ptr<Tensor> m_tensor;
83  std::vector<Input*> m_inputs;
84  };
85  }
86 }
Definition: node.hpp:132
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:46
Shape for a tensor.
Definition: shape.hpp:31
Definition: output.hpp:41
Output(Node *node, size_t index, const std::shared_ptr< Tensor > &tensor)
const PartialShape & get_partial_shape() const
const Shape & get_shape() const
const element::Type & get_element_type() const
Definition: element_type.hpp:61
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28