Class: Micrograd::MulOp

Inherits:
Struct
  • Object
show all
Defined in:
lib/micrograd/op.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



18
19
20
# File 'lib/micrograd/op.rb', line 18

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



18
19
20
# File 'lib/micrograd/op.rb', line 18

def y
  @y
end

Instance Method Details

#backward(value) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/micrograd/op.rb', line 19

def backward(value)
  x.grad += y.data * value.grad
  y.grad += x.data * value.grad

  x.backward
  y.backward
end