Class: RubyZero::Core::Functions::MulScalar

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) ⇒ MulScalar

Returns a new instance of MulScalar.



72
73
74
# File 'lib/rubyzero/core/functions/operators.rb', line 72

def initialize(scalar)
    @scalar = scalar
end

Instance Method Details

#backward(dy) ⇒ Object



80
81
82
# File 'lib/rubyzero/core/functions/operators.rb', line 80

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

#forward(x1) ⇒ Object



75
76
77
78
79
# File 'lib/rubyzero/core/functions/operators.rb', line 75

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