node_input.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 <cstring>
20 
21 #include "ngraph/descriptor/tensor.hpp"
22 #include "ngraph/partial_shape.hpp"
23 #include "ngraph/shape.hpp"
24 #include "ngraph/type/element_type.hpp"
25 
26 namespace ngraph
27 {
28  class Node;
29 
30  template <typename NodeType>
31  class Output;
32 
33  template <typename NodeType>
34  class Input
35  {
36  };
37 
38  /// \brief A handle for one of a node's inputs.
39  template <>
40  class NGRAPH_API Input<Node>
41  {
42  public:
43  /// \brief Constructs a Input.
44  /// \param node Pointer to the node for the input handle.
45  /// \param index The index of the input.
46  Input(Node* node, size_t index);
47 
48  /// \return A pointer to the node referenced by this input handle.
49  Node* get_node() const;
50  /// \return The index of the input referred to by this input handle.
51  size_t get_index() const;
52  /// \return The element type of the input referred to by this input handle.
53  const element::Type& get_element_type() const;
54  /// \return The shape of the input referred to by this input handle.
55  const Shape& get_shape() const;
56  /// \return The partial shape of the input referred to by this input handle.
58  /// \return A handle to the output that is connected to this input.
60  /// \return A reference to the tensor descriptor for this input.
61  descriptor::Tensor& get_tensor() const;
62  /// \return A shared pointer to the tensor descriptor for this input.
63  std::shared_ptr<descriptor::Tensor> get_tensor_ptr() const;
64  /// \return true if this input is relevant to its node's output shapes; else false.
66  /// \return true if this input is relevant to its node's output values; else false.
68 
69  /// \brief Replaces the source output of this input.
70  /// \param new_source_output A handle for the output that will replace this input's source.
71  void replace_source_output(const Output<Node>& new_source_output) const;
72 
73  bool operator==(const Input& other) const;
74  bool operator!=(const Input& other) const;
75  bool operator<(const Input& other) const;
76  bool operator>(const Input& other) const;
77  bool operator<=(const Input& other) const;
78  bool operator>=(const Input& other) const;
79 
80  private:
81  Node* const m_node;
82  const size_t m_index;
83  };
84 
85  /// \brief A handle for one of a node's inputs.
86  template <>
87  class NGRAPH_API Input<const Node>
88  {
89  public:
90  /// \brief Constructs a Input.
91  /// \param node Pointer to the node for the input handle.
92  /// \param index The index of the input.
93  Input(const Node* node, size_t index);
94 
95  /// \return A pointer to the node referenced by this input handle.
96  const Node* get_node() const;
97  /// \return The index of the input referred to by this input handle.
98  size_t get_index() const;
99  /// \return The element type of the input referred to by this input handle.
100  const element::Type& get_element_type() const;
101  /// \return The shape of the input referred to by this input handle.
102  const Shape& get_shape() const;
103  /// \return The partial shape of the input referred to by this input handle.
105  /// \return A handle to the output that is connected to this input.
107  /// \return A reference to the tensor descriptor for this input.
108  descriptor::Tensor& get_tensor() const;
109  /// \return A shared pointer to the tensor descriptor for this input.
110  std::shared_ptr<descriptor::Tensor> get_tensor_ptr() const;
111  /// \return true if this input is relevant to its node's output shapes; else false.
113  /// \return true if this input is relevant to its node's output values; else false.
115 
116  bool operator==(const Input& other) const;
117  bool operator!=(const Input& other) const;
118  bool operator<(const Input& other) const;
119  bool operator>(const Input& other) const;
120  bool operator<=(const Input& other) const;
121  bool operator>=(const Input& other) const;
122 
123  private:
124  const Node* const m_node;
125  const size_t m_index;
126  };
127 
128  NGRAPH_API std::ostream& operator<<(std::ostream& out, const Input<Node>& input);
129  NGRAPH_API std::ostream& operator<<(std::ostream& out, const Input<const Node>& input);
130 }
ngraph::Input< Node >::get_is_relevant_to_shapes
bool get_is_relevant_to_shapes() const
ngraph::Input< Node >::get_index
size_t get_index() const
ngraph::Input< Node >::get_element_type
const element::Type & get_element_type() const
ngraph::Input< Node >::get_tensor_ptr
std::shared_ptr< descriptor::Tensor > get_tensor_ptr() const
ngraph::PartialShape
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:46
ngraph::Input< Node >::get_tensor
descriptor::Tensor & get_tensor() const
ngraph::Input< Node >::Input
Input(Node *node, size_t index)
Constructs a Input.
ngraph::Input< const Node >::get_shape
const Shape & get_shape() const
ngraph::Input< const Node >::get_source_output
Output< Node > get_source_output() const
ngraph::Input< Node >::get_source_output
Output< Node > get_source_output() const
ngraph::Input< const Node >::get_tensor_ptr
std::shared_ptr< descriptor::Tensor > get_tensor_ptr() const
ngraph::Input< const Node >::get_element_type
const element::Type & get_element_type() const
ngraph::Input< Node >::get_shape
const Shape & get_shape() const
ngraph::Output< Node >
A handle for one of a node's outputs.
Definition: node_output.hpp:41
ngraph::Input< const Node >
A handle for one of a node's inputs.
Definition: node_input.hpp:88
ngraph::Input< const Node >::get_partial_shape
const PartialShape & get_partial_shape() const
ngraph::Input< const Node >::get_tensor
descriptor::Tensor & get_tensor() const
ngraph::Input< Node >::get_partial_shape
const PartialShape & get_partial_shape() const
ngraph::Input< const Node >::get_node
const Node * get_node() const
ngraph::Input< const Node >::get_is_relevant_to_values
bool get_is_relevant_to_values() const
ngraph::Shape
Shape for a tensor.
Definition: shape.hpp:31
ngraph::Input< const Node >::get_is_relevant_to_shapes
bool get_is_relevant_to_shapes() const
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::Input< Node >::replace_source_output
void replace_source_output(const Output< Node > &new_source_output) const
Replaces the source output of this input.
ngraph::Input< const Node >::get_index
size_t get_index() const
ngraph::Node
Definition: node.hpp:131
ngraph::Input< const Node >::Input
Input(const Node *node, size_t index)
Constructs a Input.
ngraph::Input
Definition: node_input.hpp:35
ngraph::Input< Node >::get_is_relevant_to_values
bool get_is_relevant_to_values() const
ngraph::Input< Node >::get_node
Node * get_node() const