Class: Chainer::VariableNode
- Inherits:
-
Object
- Object
- Chainer::VariableNode
- Defined in:
- lib/chainer/variable_node.rb
Instance Attribute Summary collapse
-
#creator ⇒ Object
Returns the value of attribute creator.
-
#data ⇒ Object
Returns the value of attribute data.
-
#dtype ⇒ Object
readonly
Returns the value of attribute dtype.
-
#grad ⇒ Object
Returns the value of attribute grad.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#requires_grad ⇒ Object
Returns the value of attribute requires_grad.
-
#shape ⇒ Object
readonly
Returns the value of attribute shape.
-
#variable ⇒ Object
Returns the value of attribute variable.
Instance Method Summary collapse
-
#initialize(variable:, name:, grad: nil) ⇒ VariableNode
constructor
A new instance of VariableNode.
- #label ⇒ Object
- #retain_data ⇒ Object
- #set_data_type(data) ⇒ Object
- #set_grad_with_check(g, func, var) ⇒ Object
- #unchain ⇒ Object
Constructor Details
#initialize(variable:, name:, grad: nil) ⇒ VariableNode
Returns a new instance of VariableNode.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/chainer/variable_node.rb', line 6 def initialize(variable: , name:, grad: nil) @variable = WeakRef.new(variable) @creator = nil @data = nil @rank = 0 @name = name @requires_grad = variable.requires_grad set_data_type(variable.data) @grad = grad end |
Instance Attribute Details
#creator ⇒ Object
Returns the value of attribute creator.
4 5 6 |
# File 'lib/chainer/variable_node.rb', line 4 def creator @creator end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/chainer/variable_node.rb', line 4 def data @data end |
#dtype ⇒ Object (readonly)
Returns the value of attribute dtype.
3 4 5 |
# File 'lib/chainer/variable_node.rb', line 3 def dtype @dtype end |
#grad ⇒ Object
Returns the value of attribute grad.
4 5 6 |
# File 'lib/chainer/variable_node.rb', line 4 def grad @grad end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/chainer/variable_node.rb', line 4 def name @name end |
#rank ⇒ Object
Returns the value of attribute rank.
4 5 6 |
# File 'lib/chainer/variable_node.rb', line 4 def rank @rank end |
#requires_grad ⇒ Object
Returns the value of attribute requires_grad.
4 5 6 |
# File 'lib/chainer/variable_node.rb', line 4 def requires_grad @requires_grad end |
#shape ⇒ Object (readonly)
Returns the value of attribute shape.
3 4 5 |
# File 'lib/chainer/variable_node.rb', line 3 def shape @shape end |
#variable ⇒ Object
Returns the value of attribute variable.
4 5 6 |
# File 'lib/chainer/variable_node.rb', line 4 def variable @variable end |
Instance Method Details
#label ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/chainer/variable_node.rb', line 36 def label if @shape.nil? || @shape.empty? @dtype.to_s else "(#{@shape.join(', ')}), #{@dtype.to_s}" end end |
#retain_data ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/chainer/variable_node.rb', line 48 def retain_data if @variable.nil? raise "cannot retain variable data: the variable has been already released" else @variable.data end end |
#set_data_type(data) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/chainer/variable_node.rb', line 56 def set_data_type(data) if data.nil? @dtype = nil @shape = nil else @dtype = data.class @shape = data.shape end end |
#set_grad_with_check(g, func, var) ⇒ Object
66 67 68 69 |
# File 'lib/chainer/variable_node.rb', line 66 def set_grad_with_check(g, func, var) Utils::Variable.check_grad_type(func, var, g) @grad = g end |
#unchain ⇒ Object
44 45 46 |
# File 'lib/chainer/variable_node.rb', line 44 def unchain @creator = nil end |