Skip to content
Snippets Groups Projects
Commit 42174698 authored by Maxxhim's avatar Maxxhim
Browse files

add Substraction

parent b47b2617
Branches
No related tags found
No related merge requests found
...@@ -52,21 +52,21 @@ class Sub(_Function): ...@@ -52,21 +52,21 @@ class Sub(_Function):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__("Sub", x, y) super().__init__("Sub", x, y)
####################################################################### #######################################################################
# TODO: Implement the forward pass and put the result in self.result. # Implement the forward pass and put the result in self.result.
# The notbook provide you the formulas for this operation. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = None self.result = x.data - y.data
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
def _backward(self, grad): def _backward(self, grad):
####################################################################### #######################################################################
# TODO: Implement the derivative dx for this opetation and add the # Implement the derivative dx for this opetation and add the
# result of the chain rule on self.dx. # result of the chain rule on self.dx.
####################################################################### #######################################################################
self.dx = None self.dx = grad
self.dy = None self.dy = -grad
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
......
...@@ -169,9 +169,9 @@ class Variable: ...@@ -169,9 +169,9 @@ class Variable:
children = [] children = []
if not len(children): if not len(children):
####################################################################### #######################################################################
# TODO: Call the backward of the operation that has build this Variable # Call the backward of the operation that has build this Variable
####################################################################### #######################################################################
pass self.grad_fn.backward(self.grad, retain_graph)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment