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

sum(f, op, a; dims) unexpectedly applies f to zero element #26488

Closed
martinholters opened this issue Mar 16, 2018 · 0 comments
Closed

sum(f, op, a; dims) unexpectedly applies f to zero element #26488

martinholters opened this issue Mar 16, 2018 · 0 comments
Labels
arrays [a, r, r, a, y, s] bug Indicates an unexpected problem or unintended behavior

Comments

@martinholters
Copy link
Member

Julia 0.6:

julia> sum(x -> x+1, [1], 1)
1-element Array{Int64,1}:
 2

Julia 0.7:

julia> sum(x -> x+1, [1], dims=1) # should give same result according to deprecation
1-element Array{Int64,1}:
 3

I think the problem is that mapreduce with a dims keyword arg applies f to the implied v0:

julia> mapreduce(x -> (println(x); x+1), +, [1], dims=1)
0
1
1-element Array{Int64,1}:
 3

Compare to

julia> mapreduce(x -> (println(x); x+1), +, [1])
1  # output from println
2  # return value
@mbauman mbauman added bug Indicates an unexpected problem or unintended behavior arrays [a, r, r, a, y, s] labels Mar 16, 2018
mbauman added a commit that referenced this issue Mar 19, 2018
This is a symptom of the good old how-to-allocate-a-result-array-of-an-arbitrary-transform-of-its-elements problem. Eventually it'd be nice to solve this with `collect` of a lazy implementation, but for now this papers over the egregious problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants