class Chainer::Functions::Array::Reshape
Reshapes an input array without copy.
Public Class Methods
new(shape)
click to toggle source
# File lib/chainer/functions/array/reshape.rb, line 6 def initialize(shape) @shape = shape end
reshape(x, shape)
click to toggle source
# File lib/chainer/functions/array/reshape.rb, line 10 def self.reshape(x, shape) return Chainer::Variable.as_variable(x) if x.shape == shape return self.new(shape).apply([x]).first end
Public Instance Methods
backward(indexes, grad_outputs)
click to toggle source
# File lib/chainer/functions/array/reshape.rb, line 21 def backward(indexes, grad_outputs) gx = grad_outputs.first [Reshape.reshape(gx, @inputs.first.shape)] end
forward(inputs)
click to toggle source
# File lib/chainer/functions/array/reshape.rb, line 15 def forward(inputs) x = inputs.first new_shape = @shape.map { |s| s == -1 ? nil : s } [x.reshape(*new_shape)] end