Skip to content

Commit

Permalink
Implement zipWith and addWith
Browse files Browse the repository at this point in the history
  • Loading branch information
dantp-ai committed Mar 5, 2024
1 parent d687388 commit c220469
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions minitorch/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,16 @@ def zipWith(
applying fn(x, y) on each pair of elements.
"""
# TODO: Implement for Task 0.3.
raise NotImplementedError("Need to implement for Task 0.3")

def new_fn(ls1: Iterable[float], ls2: Iterable[float]) -> Iterable[float]:
return [fn(ls1[i], ls2[i]) for i in range(len(ls1))]

return new_fn


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")
return zipWith(add)(ls1, ls2)


def reduce(
Expand Down

0 comments on commit c220469

Please # to comment.