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

Use reverse iteration protocol in mapfoldr_impl #24833

Closed
wants to merge 2 commits into from

Conversation

YingboMa
Copy link
Contributor

This PR addresses the issue #24823. I replace the getindex and endof by the reverse iteration protocol in the function mapfoldr_impl.

@@ -96,16 +96,16 @@ foldl(op, itr) = mapfoldl(identity, op, itr)

## foldr & mapfoldr

function mapfoldr_impl(f, op, v0, itr, i::Integer)
function mapfoldr_impl(f, op, v0, itr_r, i)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for tackling this! I was wondering if there is any difference between mapreduce and mapfoldr_impl?

mapfoldr(f, op, v0, itr) = mapreduce(f, op, v0 , Iterators.reverse(itr))

should be equivalent.

Copy link
Member

Choose a reason for hiding this comment

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

Two problems with this.

  1. mapreduce doesn't define its associativity — it is allowed to associate however it wants.
  2. even if you use mapfoldl, you are assuming that op is commutative as well as associative. foldr changes associativity, but does not commute operands.

@stevengj
Copy link
Member

Maybe add a test case for something that fails in 0.6, i.e. for an iterator that is reversible but not indexable.

For example,

@test foldr(Pair, 0, Iterators.filter(iseven, 1:6)) === foldr(Pair, 0, 2:2:6) === (2=>(4=>(6=>0)))

@stevengj stevengj added the needs tests Unit tests are required for this change label Nov 29, 2017
@stevengj stevengj removed the needs tests Unit tests are required for this change label Nov 29, 2017
@KristofferC
Copy link
Member

@nanosoldier runbenchmarks(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@stevengj
Copy link
Member

stevengj commented Nov 30, 2017

The performance regressions reported by Nanosoldier can't possibly be real; they are in lots of functions (e.g. transpose!) that have nothing to do with this PR. It seems that Nanosoldier is still not working properly?

@KristofferC
Copy link
Member

This noise level is nothing out of the ordinary. Benchmarks looks good to me.

@stevengj
Copy link
Member

stevengj commented Nov 30, 2017

±45% noise, with ±25% on dozens of benchmarks, is far worse than it used to be. It makes nanosoldier almost useless except to catch truly enormous regressions.

@YingboMa YingboMa closed this Aug 20, 2018
@YingboMa YingboMa deleted the myb/mapfoldr branch August 20, 2018 21:56
@stevengj
Copy link
Member

Why was this closed?

@StefanKarpinski
Copy link
Member

Unclear. @YingboMa?

@YingboMa
Copy link
Contributor Author

Oops sorry, I thought that this PR wasn't planned to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants