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

summing an empty iterator #7465

Closed
getzdan opened this issue Jun 30, 2014 · 0 comments
Closed

summing an empty iterator #7465

getzdan opened this issue Jun 30, 2014 · 0 comments

Comments

@getzdan
Copy link
Contributor

getzdan commented Jun 30, 2014

summing an empty iterator using sum() returns error instead of zero(eltype()).

discussion on google-groups: https://groups.google.com/forum/#!topic/julia-users/xLde2t7PsgU

suggested fix by Mauro:

Modifying mapflodl in reduce.jl would make sum work:

function mapfoldl(f, op, itr) 
    i = start(itr) 
    if done(itr, i) 
       return Base.mr_empty(f, op, eltype(itr)) 
        # instead of: error("Argument is empty.") 
    end 
    (x, i) = next(itr, i) 
    v0 = evaluate(f, x) 
    mapfoldl_impl(f, op, v0, itr, i) 
end 
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

No branches or pull requests

1 participant