Class: RubyZero::Core::Functions::Pow

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, #initialize, #inspect, plot

Constructor Details

This class inherits a constructor from RubyZero::Core::Functions::Function

Instance Method Details

#backward(dy) ⇒ Object



65
66
67
68
# File 'lib/rubyzero/core/functions/operators.rb', line 65

def backward(dy) 
    x1, x2 = @inputs
    return dy * x2 * x1 ** (x2 - 1), dy * x1 ** x2 * Log.new().call(x1)
end

#forward(x1, x2) ⇒ Object



60
61
62
63
64
# File 'lib/rubyzero/core/functions/operators.rb', line 60

def forward(x1, x2)
    new_arr = x1.data ** x2.data
    new_t = RubyZero::Core::Tensor.new(new_arr, device: x1.device)
    return new_t
end