assign.hpp
1 //*****************************************************************************
2 // Copyright 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 "ngraph/op/op.hpp"
20 #include "ngraph/op/util/variable.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace v3
27  {
28  /// \brief Assign operation sets an input value to the variable with `variable_id`
29  class NGRAPH_API Assign : public Op
30  {
31  public:
32  static constexpr NodeTypeInfo type_info{"Assign", 3};
33  const NodeTypeInfo& get_type_info() const override { return type_info; }
34  Assign() = default;
35 
36  /// \brief Constructs an Assign operation.
37  ///
38  /// \param new_value Node that produces the input tensor.
39  /// \param variable_id identificator of the variable to be updated.
40  Assign(const Output<Node>& new_value, const std::string& variable_id);
41 
42  void validate_and_infer_types() override;
43 
44  std::shared_ptr<Node>
45  clone_with_new_inputs(const OutputVector& new_args) const override;
46 
47  bool visit_attributes(AttributeVisitor& visitor) override;
48 
49  std::string get_variable_id() { return m_variable_id; }
50  std::shared_ptr<ngraph::Variable> get_variable() { return m_variable; }
51  void set_variable_id(const std::string& variable_id)
52  {
53  m_variable_id = variable_id;
54  }
55  void set_variable(const std::shared_ptr<ngraph::Variable>& variable)
56  {
57  m_variable = variable;
58  }
59 
60  private:
61  std::string m_variable_id;
62  std::shared_ptr<ngraph::Variable> m_variable;
63  };
64  }
65  using v3::Assign;
66  }
67 }
ngraph::op::v3::Assign
Assign operation sets an input value to the variable with variable_id
Definition: assign.hpp:30
ngraph::op::v3::Assign::Assign
Assign(const Output< Node > &new_value, const std::string &variable_id)
Constructs an Assign operation.
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v3::Assign::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph::op::v3::Assign::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: assign.hpp:33
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29