Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Relay] Add foldr1 #2928

Merged
merged 2 commits into from
Apr 1, 2019
Merged

[Relay] Add foldr1 #2928

merged 2 commits into from
Apr 1, 2019

Conversation

lixiaoquan
Copy link
Contributor

@joshpoll Thanks for your suggestion about this issue, could you please review?

Copy link
Contributor

@joshpoll joshpoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. I would suggest using reduceR or reduceRight instead of foldr1. See elm-community/list-extra#15.

cc @MarisaKirisame @wweic

@@ -142,6 +142,29 @@ def define_list_foldr(self):
self.mod[self.foldr] = Function([f, bv, av],
Match(av, [nil_case, cons_case]), b, [a, b])

def define_list_foldr1(self):
"""Defines a right-way fold over an un-empty list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Defines a right-way fold over an un-empty list.
"""Defines a right-way fold over a nonempty list.

@MarisaKirisame
Copy link
Contributor

I'd say foldr1 is better as we already have foldr, and it is more consistent. LGTM.

@joshpoll
Copy link
Contributor

Languages that use reduce also have fold. I also think foldr1 makes the function feel "second class" even though in many instances it's the right function to use instead of foldr. foldr2 is also often commonly defined, yet has little relation to foldr1.

@joshpoll
Copy link
Contributor

Additionally, TF already has specialized versions of reduce like reduce_sum, reduce_mean, and reduce_any.

@MarisaKirisame
Copy link
Contributor

@joshpoll it is indeed second class, and foldr should be used when able, as it err on some input. generally speaking it is better to use total function (see https://wiki.haskell.org/Avoiding_partial_functions).
I try to search for foldr2, and the top result is a 5line gist with no comment, can you give some ref for foldr2?
also, reduce often is used when the function in distributed setting ala mapreduce, while fold is only used for structural recursion. Hence, i think it is better to keep it as foldr1.

Co-Authored-By: lixiaoquan <radioheads@163.com>
@lixiaoquan
Copy link
Contributor Author

@joshpoll I've applied your change, do you think it is OK to keep the function name as foldr1?

@tqchen tqchen merged commit 7cc9240 into apache:master Apr 1, 2019
wweic pushed a commit to wweic/tvm that referenced this pull request Apr 7, 2019
wweic pushed a commit to wweic/tvm that referenced this pull request Apr 7, 2019
wweic pushed a commit to wweic/tvm that referenced this pull request Apr 8, 2019
wweic pushed a commit to wweic/tvm that referenced this pull request Apr 10, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants