Class: Chainer::Function
- Inherits:
-
Object
show all
- Defined in:
- lib/chainer/function.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Function.
8
9
10
|
# File 'lib/chainer/function.rb', line 8
def initialize
@rank = 0
end
|
Instance Attribute Details
Returns the value of attribute inputs.
5
6
7
|
# File 'lib/chainer/function.rb', line 5
def inputs
@inputs
end
|
#output_data ⇒ Object
Returns the value of attribute output_data.
6
7
8
|
# File 'lib/chainer/function.rb', line 6
def output_data
@output_data
end
|
#outputs ⇒ Object
Returns the value of attribute outputs.
5
6
7
|
# File 'lib/chainer/function.rb', line 5
def outputs
@outputs
end
|
#owned_node ⇒ Object
Returns the value of attribute owned_node.
6
7
8
|
# File 'lib/chainer/function.rb', line 6
def owned_node
@owned_node
end
|
#rank ⇒ Object
Returns the value of attribute rank.
5
6
7
|
# File 'lib/chainer/function.rb', line 5
def rank
@rank
end
|
#retain_after_backward ⇒ Object
Returns the value of attribute retain_after_backward.
5
6
7
|
# File 'lib/chainer/function.rb', line 5
def retain_after_backward
@retain_after_backward
end
|
Instance Method Details
#backward(inputs, grad_outputs) ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/chainer/function.rb', line 72
def backward(inputs, grad_outputs)
xm = Chainer.get_array_module(*(inputs + grad_outputs))
if xm == Cumo
backward_gpu(inputs, grad_outputs)
else
backward_cpu(inputs, grad_outputs)
end
end
|
#backward_cpu(inputs, grad_outputs) ⇒ Object
81
82
83
|
# File 'lib/chainer/function.rb', line 81
def backward_cpu(inputs, grad_outputs)
return [nil] * inputs.size
end
|
#backward_gpu(inputs, grad_outputs) ⇒ Object
85
86
87
|
# File 'lib/chainer/function.rb', line 85
def backward_gpu(inputs, grad_outputs)
return [nil] * inputs.size
end
|
#call(*inputs) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/chainer/function.rb', line 12
def call(*inputs)
node = self.node
node.function = self
node.weak_function = nil
@node = WeakRef.new(node)
@owned_node = nil
ret = node.apply(inputs)
ret.size == 1 ? ret[0] : ret
end
|
#forward(inputs) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/chainer/function.rb', line 55
def forward(inputs)
xm = Chainer.get_array_module(*inputs)
if xm == Cumo
forward_gpu(inputs)
else
forward_cpu(inputs)
end
end
|
#forward_cpu(inputs) ⇒ Object
64
65
66
|
# File 'lib/chainer/function.rb', line 64
def forward_cpu(inputs)
raise NotImplementedError
end
|
#forward_gpu(inputs) ⇒ Object
68
69
70
|
# File 'lib/chainer/function.rb', line 68
def forward_gpu(inputs)
raise NotImplementedError
end
|
#label ⇒ Object
51
52
53
|
# File 'lib/chainer/function.rb', line 51
def label
self.class.to_s
end
|
#node ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/chainer/function.rb', line 33
def node
noderef = @node
nd = noderef ? noderef.__getobj__ : @owned_node
return nd if nd
nd = FunctionAdapter.new(self)
@owned_node = nd
nd
end
|
89
90
91
|
# File 'lib/chainer/function.rb', line 89
def retain_inputs(indexes)
@input_indexes_to_retain = indexes
end
|
#retain_outputs(indexes, retain_after_backward: false) ⇒ Object
93
94
95
|
# File 'lib/chainer/function.rb', line 93
def retain_outputs(indexes, retain_after_backward: false)
node.retain_outputs(indexes)
end
|