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