Class: RubyZero::Core::Functions::DivScalar

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

Instance Attribute Summary

Attributes inherited from Function

#inputs, #output

Instance Method Summary collapse

Methods inherited from Function

#call, #inspect, plot

Constructor Details

#initialize(scalar) ⇒ DivScalar

Returns a new instance of DivScalar.



86
87
88
# File 'lib/rubyzero/core/functions/operators.rb', line 86

def initialize(scalar)
    @scalar = scalar
end

Instance Method Details

#backward(dy) ⇒ Object



94
95
96
# File 'lib/rubyzero/core/functions/operators.rb', line 94

def backward(dy)
    return [dy / @scalar]
end

#forward(x1) ⇒ Object



89
90
91
92
93
# File 'lib/rubyzero/core/functions/operators.rb', line 89

def forward(x1)
    new_arr = x1.data / @scalar
    new_t = RubyZero::Core::Tensor.new(new_arr, device: x1.device)
    return new_t
end