Class: Chainer::Functions::Array::Assign
- Inherits:
-
Chainer::FunctionNode
- Object
- Chainer::FunctionNode
- Chainer::Functions::Array::Assign
- Defined in:
- lib/chainer/functions/array/select_item.rb
Instance Attribute Summary
Attributes inherited from Chainer::FunctionNode
Instance Method Summary collapse
- #backward(indexes, gy) ⇒ Object
- #forward(inputs) ⇒ Object
-
#initialize(shape, dtype, t) ⇒ Assign
constructor
A new instance of Assign.
Methods inherited from Chainer::FunctionNode
#apply, #backward_accumulate, #forward_cpu, #get_retained_inputs, #get_retained_outputs, #label, #output_data, #retain_inputs, #retain_outputs, #unchain
Constructor Details
#initialize(shape, dtype, t) ⇒ Assign
Returns a new instance of Assign.
48 49 50 51 52 |
# File 'lib/chainer/functions/array/select_item.rb', line 48 def initialize(shape, dtype, t) @shape = shape @dtype = dtype @t = t.data end |
Instance Method Details
#backward(indexes, gy) ⇒ Object
66 67 68 |
# File 'lib/chainer/functions/array/select_item.rb', line 66 def backward(indexes, gy) SelectItem.new.apply([gy[0], @t]) end |
#forward(inputs) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/chainer/functions/array/select_item.rb', line 54 def forward(inputs) gx = @dtype.zeros(*@shape) # TODO: gx[six.moves.range(self.t.size), self.t] = inputs[0] # binding.pry @t.size.times.each do |i| gx[i, @t[i]] = inputs[0][i] end [gx] end |