class DNN::Layers::Reshape

Public Class Methods

new(shape) click to toggle source
Calls superclass method DNN::Layers::Layer::new
# File lib/dnn/core/layers/basic_layers.rb, line 308
def initialize(shape)
  super()
  @shape = shape
end

Public Instance Methods

_backward_cpu(dy) click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 337
def _backward_cpu(dy)
  dy.reshape(dy.shape[0], *@input_shape)
end
_backward_gpu(dy) click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 345
def _backward_gpu(dy)
  dy.flatten.reshape(dy.shape[0], *@input_shape)
end
_forward_cpu(x) click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 333
def _forward_cpu(x)
  x.reshape(x.shape[0], *@output_shape)
end
_forward_gpu(x) click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 341
def _forward_gpu(x)
  x.flatten.reshape(x.shape[0], *@output_shape)
end
backward_node(dy) click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 325
def backward_node(dy)
  if DNN.use_cumo?
    _backward_gpu(dy)
  else
    _backward_cpu(dy)
  end
end
compute_output_shape() click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 313
def compute_output_shape
  @shape
end
forward_node(x) click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 317
def forward_node(x)
  if DNN.use_cumo?
    _forward_gpu(x)
  else
    _forward_cpu(x)
  end
end
load_hash(hash) click to toggle source
# File lib/dnn/core/layers/basic_layers.rb, line 353
def load_hash(hash)
  initialize(hash[:shape])
end
to_hash() click to toggle source
Calls superclass method DNN::Layers::Layer#to_hash
# File lib/dnn/core/layers/basic_layers.rb, line 349
def to_hash
  super(shape: @shape)
end