Last active
August 7, 2019 13:09
-
-
Save d3lm/6155ffee32fa3d0ad1fba632d7a6e389 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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