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

Define mapfoldl/foldl for static arrays #750

Merged
merged 2 commits into from Mar 3, 2020
Merged

Conversation

tkf
Copy link
Member

@tkf tkf commented Feb 29, 2020

This PR includes some improvements discussed in #702 (comment):

  • Document how _InitialValue works and explain some idea behind it.
  • Use _InitialValue instead of passing around kw.data :: NamedTuple.
  • Use _InitialValue to collapse the foldl implementations with and without init into one.
  • Add mapfoldl and foldl on static arrays:
    1. Rename the reduce "kernels" _mapreduce to _mapfoldl.
    2. Add _mapreduce back as an alias to _mapfoldl.
    3. Define Base.mapfoldl and Base.foldl as a simple wrapper of _mapfoldl.

It's not a tiny diff but mostly all the changes are simple refactoring.

@tkf tkf mentioned this pull request Feb 29, 2020
2 tasks
@coveralls
Copy link

coveralls commented Feb 29, 2020

Coverage Status

Coverage decreased (-0.06%) to 82.397% when pulling cf9a190 on tkf:foldl into c808bdd on JuliaArrays:master.

@_inline_meta
@inbounds return $expr
if init === _InitialValue
expr = :(Base.reduce_first(op, $expr))
Copy link
Member Author

Choose a reason for hiding this comment

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

Base.reduce_first wasn't called before so sum(SA[true]) returned true; now it returns 1 :: Int. This is consistent with sum([true]).

Copy link
Member

@c42f c42f left a comment

Choose a reason for hiding this comment

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

Looks great to me!

src/mapreduce.jl Show resolved Hide resolved
@c42f c42f merged commit c52ac6a into JuliaArrays:master Mar 3, 2020
@c42f c42f added cleanup feature features and feature requests labels Mar 3, 2020
@tkf tkf deleted the foldl branch March 3, 2020 05:28
@c42f c42f mentioned this pull request May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup feature features and feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants