class Chainer::Function

Attributes

inputs[R]
output_data[RW]
outputs[R]
owned_node[RW]
rank[R]
retain_after_backward[R]

Public Class Methods

new() click to toggle source
# File lib/chainer/function.rb, line 8
def initialize
  @rank = 0
end

Public Instance Methods

backward(inputs, grad_outputs) click to toggle source
# 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) click to toggle source
# File lib/chainer/function.rb, line 81
def backward_cpu(inputs, grad_outputs)
  return [nil] * inputs.size
end
backward_gpu(inputs, grad_outputs) click to toggle source
# File lib/chainer/function.rb, line 85
def backward_gpu(inputs, grad_outputs)
  return [nil] * inputs.size
end
call(*inputs) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/chainer/function.rb, line 64
def forward_cpu(inputs)
  raise NotImplementedError
end
forward_gpu(inputs) click to toggle source
# File lib/chainer/function.rb, line 68
def forward_gpu(inputs)
  raise NotImplementedError
end
label() click to toggle source
# File lib/chainer/function.rb, line 51
def label
  self.class.to_s
end
node() click to toggle source
# 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
retain_inputs(indexes) click to toggle source
# File lib/chainer/function.rb, line 89
def retain_inputs(indexes)
  @input_indexes_to_retain = indexes
end
retain_outputs(indexes, retain_after_backward: false) click to toggle source
# File lib/chainer/function.rb, line 93
def retain_outputs(indexes, retain_after_backward: false)
  node.retain_outputs(indexes)
end