Class: RubyZero::Core::Functions::Reshape

Inherits:
Function
  • Object
show all
Defined in:
lib/rubyzero/core/functions/tensor_functions.rb

Instance Attribute Summary

Attributes inherited from Function

#inputs, #output

Instance Method Summary collapse

Methods inherited from Function

#call, #inspect, plot

Constructor Details

#initialize(shape) ⇒ Reshape

Returns a new instance of Reshape.



3
4
5
# File 'lib/rubyzero/core/functions/tensor_functions.rb', line 3

def initialize(shape)
    @dist_shape = shape
end

Instance Method Details

#backward(dy) ⇒ Object



12
13
14
# File 'lib/rubyzero/core/functions/tensor_functions.rb', line 12

def backward(dy)
    return [dy.reshape(@prev_shape)]
end

#forward(x1) ⇒ Object



6
7
8
9
10
11
# File 'lib/rubyzero/core/functions/tensor_functions.rb', line 6

def forward(x1)
    new_arr = x1.data.reshape(@dist_shape)
    @prev_shape = x1.shape
    new_t = RubyZero::Core::Tensor.new(new_arr, device: x1.device)
    return new_t
end