Skip to content

Commit

Permalink
Remove todos
Browse files Browse the repository at this point in the history
  • Loading branch information
dantp-ai committed Feb 29, 2024
1 parent 904d1c4 commit 72f04ff
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions minitorch/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,48 @@

def mul(x: float, y: float) -> float:
"$f(x, y) = x * y$"
# TODO: Implement for Task 0.1.
return x * y


def id(x: float) -> float:
"$f(x) = x$"
# TODO: Implement for Task 0.1.

return x


def add(x: float, y: float) -> float:
"$f(x, y) = x + y$"
# TODO: Implement for Task 0.1.

return x + y


def neg(x: float) -> float:
"$f(x) = -x$"
# TODO: Implement for Task 0.1.

return -x


def lt(x: float, y: float) -> float:
"$f(x) =$ 1.0 if x is less than y else 0.0"
# TODO: Implement for Task 0.1.

return float(x < y)


def eq(x: float, y: float) -> float:
"$f(x) =$ 1.0 if x is equal to y else 0.0"
# TODO: Implement for Task 0.1.

return float(x == y)


def max(x: float, y: float) -> float:
"$f(x) =$ x if x is greater than y else y"
# TODO: Implement for Task 0.1.

return x if x >= y else y


def is_close(x: float, y: float) -> float:
"$f(x) = |x - y| < 1e-2$"
# TODO: Implement for Task 0.1.

if x >= y:
return x - y <= 1e-2
else:
Expand All @@ -73,7 +72,7 @@ def sigmoid(x: float) -> float:
for stability.
"""
# TODO: Implement for Task 0.1.

return (1.0 / (1.0 + math.exp(-x))) if x >= 0 else math.exp(x) / (1 + math.exp(x))


Expand All @@ -83,7 +82,7 @@ def relu(x: float) -> float:
(See https://en.wikipedia.org/wiki/Rectifier_(neural_networks) .)
"""
# TODO: Implement for Task 0.1.

return x if x > 0.0 else 0


Expand All @@ -102,26 +101,26 @@ def exp(x: float) -> float:

def log_back(x: float, d: float) -> float:
r"If $f = log$ as above, compute $d \times f'(x)$"
# TODO: Implement for Task 0.1.

return d / x


def inv(x: float) -> float:
"$f(x) = 1/x$"
# TODO: Implement for Task 0.1.

if x != 0.0:
return 1 / x


def inv_back(x: float, d: float) -> float:
r"If $f(x) = 1/x$ compute $d \times f'(x)$"
# TODO: Implement for Task 0.1.

return -(x ** (-2)) * d


def relu_back(x: float, d: float) -> float:
r"If $f = relu$ compute $d \times f'(x)$"
# TODO: Implement for Task 0.1.

return d * (x > 0.0)


Expand Down

0 comments on commit 72f04ff

Please sign in to comment.