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

Add map! method with single array param when source and dest are the same #30071

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kim366
Copy link
Contributor

@kim366 kim366 commented Nov 18, 2018

julia> arr = [1,2,3];

julia> map!(x -> 2x, arr)
ERROR: BoundsError: attempt to access ()
  at index [1]
Stacktrace:
 [1] map_n!(::getfield(Main, Symbol("##3#4")), ::Array{Int64,1}, ::Tuple{}) at ./abstractarray.jl:2032
 [2] map!(::getfield(Main, Symbol("##3#4")), ::Array{Int64,1}) at ./abstractarray.jl:2057
 [3] top-level scope at none:0

This code produces a very non-descriptive error and the attempt is clear. Instead, map!(x -> 2x, arr, arr) has to be used, which is not obvious (especially when comparing with map). This PR adds a method to map! that accepts this input and maps in the same array.

@Sacha0
Copy link
Member

Sacha0 commented Nov 18, 2018

Ref. #19721. Best!

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.

2 participants