variable_value.hpp
1 // Copyright (C) 2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <ngraph/runtime/host_tensor.hpp>
8 #include <utility>
9 
10 namespace ngraph
11 {
12  /// VariableValue stores data and state (reset flag) for a Variable,
13  /// and provides an interface for changing them.
14  class NGRAPH_API VariableValue
15  {
16  public:
17  /// \brief Constructs an uninitialized VariableValue.
18  VariableValue() = default;
19 
20  /// \brief Constructor for VariableValue.
21  /// \param value The data for Variable.
22  explicit VariableValue(HostTensorPtr value)
23  : m_value(std::move(value))
24  {
25  }
26 
27  /// \brief Constructor for VariableValue.
28  /// \param value Data for Variable.
29  /// \param reset The current state of the reset flag.
30  VariableValue(HostTensorPtr value, bool reset)
31  : m_reset(reset)
32  , m_value(std::move(value))
33  {
34  }
35 
36  /// \brief Sets the reset flag to a new state.
37  /// \param reset The new state of the reset flag.
38  void set_reset(bool reset) { m_reset = reset; }
39 
40  /// \brief Returns the current reset flag state.
41  bool get_reset() const { return m_reset; }
42 
43  /// \brief Returns the current stored data.
44  const HostTensorPtr& get_value() const { return m_value; }
45 
46  /// \brief Sets new values for Variable.
47  /// \param value New data for Variable.
48  void set_value(const HostTensorPtr& value) { m_value = value; }
49 
50  private:
51  bool m_reset = true;
52  HostTensorPtr m_value;
53  };
54  using VariableValuePtr = std::shared_ptr<VariableValue>;
55 } // namespace ngraph
Definition: variable_value.hpp:15
void set_reset(bool reset)
Sets the reset flag to a new state.
Definition: variable_value.hpp:38
VariableValue(HostTensorPtr value, bool reset)
Constructor for VariableValue.
Definition: variable_value.hpp:30
bool get_reset() const
Returns the current reset flag state.
Definition: variable_value.hpp:41
VariableValue()=default
Constructs an uninitialized VariableValue.
VariableValue(HostTensorPtr value)
Constructor for VariableValue.
Definition: variable_value.hpp:22
void set_value(const HostTensorPtr &value)
Sets new values for Variable.
Definition: variable_value.hpp:48
const HostTensorPtr & get_value() const
Returns the current stored data.
Definition: variable_value.hpp:44
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16