Skip to content

Instantly share code, notes, and snippets.

@d3lm
Last active August 7, 2019 13:09
Show Gist options
  • Save d3lm/6155ffee32fa3d0ad1fba632d7a6e389 to your computer and use it in GitHub Desktop.
Save d3lm/6155ffee32fa3d0ad1fba632d7a6e389 to your computer and use it in GitHub Desktop.
class add(BinaryOperation):
"""
Computes a + b, element-wise
"""
def forward(self, a, b):
return a + b
def backward(self, upstream_grad):
raise NotImplementedError
class multiply(BinaryOperation):
"""
Computes a * b, element-wise
"""
def forward(self, a, b):
return a * b
def backward(self, upstream_grad):
raise NotImplementedError
class divide(BinaryOperation):
"""
Returns the true division of the inputs, element-wise
"""
def forward(self, a, b):
return np.true_divide(a, b)
def backward(self, upstream_grad):
raise NotImplementedError
class matmul(BinaryOperation):
"""
Multiplies matrix a by matrix b, producing a * b
"""
def forward(self, a, b):
return a.dot(b)
def backward(self, upstream_grad):
raise NotImplementedError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment