Skip to content

Commit

Permalink
Merge pull request #2 from dantp-ai/solution/task-0-1
Browse files Browse the repository at this point in the history
Solution/task 0 1
  • Loading branch information
dantp-ai authored Feb 27, 2024
2 parents fbf9dc7 + a14dfa7 commit cb9298a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions minitorch/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def neg(x: float) -> float:
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.
raise NotImplementedError('Need to 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.
raise NotImplementedError('Need to implement for Task 0.1')
return float(x == y)


def max(x: float, y: float) -> float:
Expand Down Expand Up @@ -74,7 +74,7 @@ def sigmoid(x: float) -> float:
for stability.
"""
# TODO: Implement for Task 0.1.
raise NotImplementedError('Need to implement for Task 0.1')
raise NotImplementedError("Need to implement for Task 0.1")


def relu(x: float) -> float:
Expand All @@ -84,7 +84,7 @@ def relu(x: float) -> float:
(See https://en.wikipedia.org/wiki/Rectifier_(neural_networks) .)
"""
# TODO: Implement for Task 0.1.
raise NotImplementedError('Need to implement for Task 0.1')
return x if x > 0.0 else 0


EPS = 1e-6
Expand All @@ -103,26 +103,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.
raise NotImplementedError('Need to implement for Task 0.1')
raise NotImplementedError("Need to implement for Task 0.1")


def inv(x: float) -> float:
"$f(x) = 1/x$"
# TODO: Implement for Task 0.1.
if x != 0.:
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.
raise NotImplementedError('Need to implement for Task 0.1')
raise NotImplementedError("Need to implement for Task 0.1")


def relu_back(x: float, d: float) -> float:
r"If $f = relu$ compute $d \times f'(x)$"
# TODO: Implement for Task 0.1.
raise NotImplementedError('Need to implement for Task 0.1')
return d * (x > 0.0)


# ## Task 0.3
Expand All @@ -144,13 +144,13 @@ def map(fn: Callable[[float], float]) -> Callable[[Iterable[float]], Iterable[fl
new list
"""
# TODO: Implement for Task 0.3.
raise NotImplementedError('Need to implement for Task 0.3')
raise NotImplementedError("Need to implement for Task 0.3")


def negList(ls: Iterable[float]) -> Iterable[float]:
"Use `map` and `neg` to negate each element in `ls`"
# TODO: Implement for Task 0.3.
raise NotImplementedError('Need to implement for Task 0.3')
raise NotImplementedError("Need to implement for Task 0.3")


def zipWith(
Expand All @@ -170,13 +170,13 @@ def zipWith(
"""
# TODO: Implement for Task 0.3.
raise NotImplementedError('Need to implement for Task 0.3')
raise NotImplementedError("Need to implement for Task 0.3")


def addLists(ls1: Iterable[float], ls2: Iterable[float]) -> Iterable[float]:
"Add the elements of `ls1` and `ls2` using `zipWith` and `add`"
# TODO: Implement for Task 0.3.
raise NotImplementedError('Need to implement for Task 0.3')
raise NotImplementedError("Need to implement for Task 0.3")


def reduce(
Expand All @@ -195,16 +195,16 @@ def reduce(
fn(x_1, x_0)))`
"""
# TODO: Implement for Task 0.3.
raise NotImplementedError('Need to implement for Task 0.3')
raise NotImplementedError("Need to implement for Task 0.3")


def sum(ls: Iterable[float]) -> float:
"Sum up a list using `reduce` and `add`."
# TODO: Implement for Task 0.3.
raise NotImplementedError('Need to implement for Task 0.3')
raise NotImplementedError("Need to implement for Task 0.3")


def prod(ls: Iterable[float]) -> float:
"Product of a list using `reduce` and `mul`."
# TODO: Implement for Task 0.3.
raise NotImplementedError('Need to implement for Task 0.3')
raise NotImplementedError("Need to implement for Task 0.3")

0 comments on commit cb9298a

Please sign in to comment.