Skip to content

Commit

Permalink
Merge pull request #1 from dantp-ai/solution/task-0-1
Browse files Browse the repository at this point in the history
Implement basic operators
  • Loading branch information
dantp-ai authored Feb 25, 2024
2 parents 7d35d59 + aacfe10 commit fbf9dc7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions minitorch/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
def mul(x: float, y: float) -> float:
"$f(x, y) = x * y$"
# TODO: Implement for Task 0.1.
raise NotImplementedError('Need to implement for Task 0.1')
return x * y


def id(x: float) -> float:
"$f(x) = x$"
# TODO: Implement for Task 0.1.
raise NotImplementedError('Need to 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.
raise NotImplementedError('Need to implement for Task 0.1')
return x + y


def neg(x: float) -> float:
"$f(x) = -x$"
# TODO: Implement for Task 0.1.
raise NotImplementedError('Need to implement for Task 0.1')
return -x


def lt(x: float, y: float) -> float:
Expand All @@ -49,13 +49,16 @@ def eq(x: float, y: float) -> float:
def max(x: float, y: float) -> float:
"$f(x) =$ x if x is greater than y else y"
# TODO: Implement for Task 0.1.
raise NotImplementedError('Need to 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.
raise NotImplementedError('Need to implement for Task 0.1')
if x >= y:
return x - y <= 1e-2
else:
return y - x <= 1e-2


def sigmoid(x: float) -> float:
Expand Down Expand Up @@ -106,7 +109,8 @@ def log_back(x: float, d: float) -> float:
def inv(x: float) -> float:
"$f(x) = 1/x$"
# TODO: Implement for Task 0.1.
raise NotImplementedError('Need to implement for Task 0.1')
if x != 0.:
return 1 / x


def inv_back(x: float, d: float) -> float:
Expand Down

0 comments on commit fbf9dc7

Please sign in to comment.