input.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <memory>
8 
9 #include "ngraph/descriptor/tensor.hpp"
10 
11 namespace ngraph
12 {
13  class Node;
14 
15  namespace descriptor
16  {
17  class Output;
18 
19  // Describes a tensor that is an input to an op, directly or indirectly via a tuple
20  class NGRAPH_API Input
21  {
22  friend class ngraph::Node;
23 
24  public:
25  /// \param node The node that owns this input
26  /// \param index The position of this this tensor in all input tensors
27  /// \param output The output that supplies a value for this input
28  Input(Node* node, size_t index, Output& output);
29  /// \brief Create an Input that is not connected to an output
30  /// \param node The node that owns this input
31  /// \param index The position of this this tensor in all input tensors
32  Input(Node* node, size_t index);
33  ~Input();
34 
35  /// \return the node that this is an input of
36  std::shared_ptr<Node> get_node() const;
37 
38  /// \return the raw pointer to the node that this is an input of
39  Node* get_raw_pointer_node() const { return m_node; }
40  /// \return the position within all supplied tensors of this input
41  size_t get_index() const { return m_index; }
42  /// \return the connected output
43  const Output& get_output() const { return *m_output; }
44  /// \return the connected output
45  Output& get_output() { return *m_output; }
46  /// \return true if an output is connected to the input.
47  bool has_output() const { return m_output != nullptr; }
48  /// \return the tensor of the connected output
49  const Tensor& get_tensor() const;
50 
51  /// \return the tensor of the connected output
53 
54  /// \brief Replace the current output that supplies a value for this input with output i
55  /// of node
56  void replace_output(std::shared_ptr<Node> node, size_t i);
57  /// \brief Replace the current output that supplies a value for this input with output
59  /// \brief Remove the output from this input. The node will not be valid until another
60  /// output is supplied.
61  void remove_output();
62 
63  /// \return true if the value of this input is relevant to the output shapes of the
64  /// corresponding node. (Usually this is false.)
65  ///
66  /// See Node::set_input_is_relevant_to_shape for more details.
67  bool get_is_relevant_to_shape() const { return m_is_relevant_to_shape; }
68  /// \return true if the value of this input is relevant to the output value of the
69  /// corresponding node. (Usually this is true.)
70  ///
71  /// See Node::set_input_is_relevant_to_value for more details.
72  bool get_is_relevant_to_value() const { return m_is_relevant_to_value; }
73 
74  protected:
75  /// \return the tensor for the connected output
76  std::shared_ptr<const Tensor> get_tensor_ptr() const;
77 
78  /// \return the tensor for the connected output
79  std::shared_ptr<Tensor> get_tensor_ptr();
80 
81  public:
82  /// \return the shape of the connected output
83  const Shape& get_shape() const;
84 
85  /// \return the partial shape of the connected output
87 
88  /// \return the element type of the connected output
90 
91  Input(const Input&) = default;
92  Input(Input&&) = default;
93  Input& operator=(const Input&) = default;
94 
95  protected:
96  // owner of an argument node (in lieu of m_arguments)
97  std::shared_ptr<Node> m_src_node;
98  Node* m_node; // The node we are an input for
99  size_t m_index; // Index into all input tensors
100  Output* m_output;
101 
102  private:
103  bool m_is_relevant_to_shape;
104  bool m_is_relevant_to_value;
105  };
106  } // namespace descriptor
107 } // namespace ngraph
Definition: node.hpp:127
Output< Node > output(size_t output_index)
Node & operator=(const Node &)
Assignment operator.
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:34
Shape for a tensor.
Definition: shape.hpp:19
Definition: input.hpp:21
const Output & get_output() const
Definition: input.hpp:43
std::shared_ptr< Node > get_node() const
void remove_output()
Remove the output from this input. The node will not be valid until another output is supplied.
const Tensor & get_tensor() const
const Shape & get_shape() const
Output & get_output()
Definition: input.hpp:45
const element::Type & get_element_type() const
Node * get_raw_pointer_node() const
Definition: input.hpp:39
Input(Node *node, size_t index, Output &output)
bool get_is_relevant_to_shape() const
Definition: input.hpp:67
std::shared_ptr< Tensor > get_tensor_ptr()
bool has_output() const
Definition: input.hpp:47
const PartialShape & get_partial_shape() const
Input(Node *node, size_t index)
Create an Input that is not connected to an output.
void replace_output(Output &output)
Replace the current output that supplies a value for this input with output.
size_t get_index() const
Definition: input.hpp:41
bool get_is_relevant_to_value() const
Definition: input.hpp:72
std::shared_ptr< const Tensor > get_tensor_ptr() const
void replace_output(std::shared_ptr< Node > node, size_t i)
Replace the current output that supplies a value for this input with output i of node.
Definition: output.hpp:32
Compile-time descriptor of a first-class value that is a tensor.
Definition: tensor.hpp:28
Definition: element_type.hpp:51
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16