{"action":"created","comment":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/comments/77737609","id":77737609,"diff_hunk":"@@ -228,19 +247,46 @@ function broadcast_t(f, ::Type{Any}, As...)\n     keeps, Idefaults = map_newindexer(shape, As)\n     st = start(iter)\n     I, st = next(iter, st)\n-    val = f([ As[i][newindex(I, keeps[i], Idefaults[i])] for i=1:nargs ]...)\n+    val = f(( _broadcast_getindex(As[i], newindex(I, keeps[i], Idefaults[i])) for i=1:nargs )...)\n     B = similar(Array{typeof(val)}, shape)\n     B[I] = val\n     return _broadcast!(f, B, keeps, Idefaults, As, Val{nargs}, iter, st, 1)\n end\n \n-@inline broadcast_t(f, T, As...) = broadcast!(f, similar(Array{T}, broadcast_shape(As...)), As...)\n+@inline broadcast_t(f, T, As...) = broadcast!(f, similar(Array{T}, broadcast_indices(As...)), As...)\n+\n+@generated function broadcast_tup{AT,nargs,n}(f, As::AT, ::Type{Val{nargs}}, ::Type{Val{n}})\n+    quote\n+        ntuple(n -> (@ncall $nargs f i->_broadcast_getindex(As[i], n)), Val{n})\n+    end\n+end\n+\n+function broadcast_c(f, ::Type{Tuple}, As...)\n+    shape = broadcast_indices(As...)\n+    check_broadcast_indices(shape, As...)\n+    n = length(shape[1])\n+    nargs = length(As)\n+    return broadcast_tup(f, As, Val{nargs}, Val{n})\n+end\n+broadcast_c(f, ::Type{Any}, a...) = f(a...)\n+broadcast_c(f, ::Type{Array}, As...) = broadcast_t(f, promote_eltype_op(f, As...), As...)\n \n \"\"\"\n     broadcast(f, As...)\n \n-Broadcasts the arrays `As` to a common size by expanding singleton dimensions, and returns\n-an array of the results `f(as...)` for each position.\n+Broadcasts the arrays, tuples and/or scalars `As` to a container of the\n+appropriate type and dimensions. In this context, anything that is not a\n+subtype of `AbstractArray` or `Tuple` is considered a scalar. The resulting\n+container is stablished by the following rules:\n+\n+- If all the arguments are scalars, it returns a scalar.\n+- If the arguments are tuples and zero or more scalars, it returns a tuple.\n+- If there is at least an array in the arguments, it returns an array\n+  (and treats tuples as 1-dimensional arrays) expanding singleton dimensions.\n+\n+A special syntax exists for broadcasting: `f.(args...)` is equivalent to\n+`broadcast(f, args...)`, and nested `f.(g.(args...))` calls are fused into a\n+single broadcast loop.","path":"base/broadcast.jl","position":204,"original_position":204,"commit_id":"a1bfe10a19997c89e03a0838c3bada39cfe931a6","original_commit_id":"a1bfe10a19997c89e03a0838c3bada39cfe931a6","user":{"login":"stevengj","id":2913679,"avatar_url":"https://avatars.githubusercontent.com/u/2913679?v=3","gravatar_id":"","url":"https://api.github.com/users/stevengj","html_url":"https://github.com/stevengj","followers_url":"https://api.github.com/users/stevengj/followers","following_url":"https://api.github.com/users/stevengj/following{/other_user}","gists_url":"https://api.github.com/users/stevengj/gists{/gist_id}","starred_url":"https://api.github.com/users/stevengj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevengj/subscriptions","organizations_url":"https://api.github.com/users/stevengj/orgs","repos_url":"https://api.github.com/users/stevengj/repos","events_url":"https://api.github.com/users/stevengj/events{/privacy}","received_events_url":"https://api.github.com/users/stevengj/received_events","type":"User","site_admin":false},"body":"You need to run `./julia doc/genstdlib.jl` to update the manual with this docstring.\r\n\r\nAlso, there is a manual section on broadcasting, and it would be good to include an example acting on strings or similar, e.g. `string.([\"one\",\"two\",\"three\",\"four\"],':',1:4)`.","created_at":"2016-09-06T23:31:24Z","updated_at":"2016-09-06T23:31:24Z","html_url":"https://github.com/JuliaLang/julia/pull/16986#discussion_r77737609","pull_request_url":"https://api.github.com/repos/JuliaLang/julia/pulls/16986","_links":{"self":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/comments/77737609"},"html":{"href":"https://github.com/JuliaLang/julia/pull/16986#discussion_r77737609"},"pull_request":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/16986"}}},"pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/16986","id":74245990,"html_url":"https://github.com/JuliaLang/julia/pull/16986","diff_url":"https://github.com/JuliaLang/julia/pull/16986.diff","patch_url":"https://github.com/JuliaLang/julia/pull/16986.patch","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/16986","number":16986,"state":"open","locked":false,"title":"Generalize broadcast to handle tuples and scalars","user":{"login":"pabloferz","id":8410335,"avatar_url":"https://avatars.githubusercontent.com/u/8410335?v=3","gravatar_id":"","url":"https://api.github.com/users/pabloferz","html_url":"https://github.com/pabloferz","followers_url":"https://api.github.com/users/pabloferz/followers","following_url":"https://api.github.com/users/pabloferz/following{/other_user}","gists_url":"https://api.github.com/users/pabloferz/gists{/gist_id}","starred_url":"https://api.github.com/users/pabloferz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabloferz/subscriptions","organizations_url":"https://api.github.com/users/pabloferz/orgs","repos_url":"https://api.github.com/users/pabloferz/repos","events_url":"https://api.github.com/users/pabloferz/events{/privacy}","received_events_url":"https://api.github.com/users/pabloferz/received_events","type":"User","site_admin":false},"body":"This addresses #16966 and should also help a little with ~~#4883 and~~ #16285.\r\n\r\n**EDITED:** Here is a little demo tested locally (also, needs #17389 to work properly)\r\n\r\n```\r\njulia> parse.(Int, [\"1\", \"2\"])\r\n2-element Array{Int64,1}:\r\n 1\r\n 2\r\n\r\njulia> convert.(Float32, [1,2])\r\n2-element Array{Float32,1}:\r\n 1.0\r\n 2.0\r\n\r\njulia> trunc.((Int,), [1.2, 3.4])\r\n2-element Array{Int64,1}:\r\n 1\r\n 3\r\n\r\njulia> ceil.(UInt8, [1.2 3.4; 5.6 6.7])\r\n2×2 Array{UInt8,2}:\r\n 0x02  0x04\r\n 0x06  0x07\r\n\r\njulia> abs.((1, -2))\r\n(1,2)\r\n\r\njulia> broadcast(+, 1.0, (0, -2.0))\r\n(1.0,-1.0)\r\n\r\njulia> broadcast(+, 1.0, (0, -2.0), [1])\r\n2-element Array{Float64,1}:\r\n 2.0\r\n 0.0\r\n\r\njulia> broadcast(*, [\"Look\", \"I'm\", \"...with\"], \" \", [\"ma'\", \"broadcasting\", \"scalars\"], \"!\")\r\n3-element Array{String,1}:\r\n \"Look ma'!\"        \r\n \"I'm broadcasting!\"\r\n\"...with scalars!\"\r\n```\r\n\r\nI just have a question though, can the following be written in a form that would make it pure? Or is it pure? (I have not completely clear the concept of pureness).\r\n\r\n`promote_eltype_op{T}(op, Ts::AbstractArray{DataType}, ::AbstractArray{T}) = typejoin([promote_op(op, S, T) for S in Ts]...)`\r\n\r\nTODO:\r\n\r\n- [x] Tests pass\r\n- [x] Add tests\r\n- [ ] Check performance\r\n- [x] Docs","created_at":"2016-06-17T13:54:35Z","updated_at":"2016-09-06T23:31:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"263d0b02e9bd3a5973f01aeb2013f9faccac69c0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/JuliaLang/julia/pulls/16986/commits","review_comments_url":"https://api.github.com/repos/JuliaLang/julia/pulls/16986/comments","review_comment_url":"https://api.github.com/repos/JuliaLang/julia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/16986/comments","statuses_url":"https://api.github.com/repos/JuliaLang/julia/statuses/a1bfe10a19997c89e03a0838c3bada39cfe931a6","head":{"label":"pabloferz:pz/broadcast","ref":"pz/broadcast","sha":"a1bfe10a19997c89e03a0838c3bada39cfe931a6","user":{"login":"pabloferz","id":8410335,"avatar_url":"https://avatars.githubusercontent.com/u/8410335?v=3","gravatar_id":"","url":"https://api.github.com/users/pabloferz","html_url":"https://github.com/pabloferz","followers_url":"https://api.github.com/users/pabloferz/followers","following_url":"https://api.github.com/users/pabloferz/following{/other_user}","gists_url":"https://api.github.com/users/pabloferz/gists{/gist_id}","starred_url":"https://api.github.com/users/pabloferz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabloferz/subscriptions","organizations_url":"https://api.github.com/users/pabloferz/orgs","repos_url":"https://api.github.com/users/pabloferz/repos","events_url":"https://api.github.com/users/pabloferz/events{/privacy}","received_events_url":"https://api.github.com/users/pabloferz/received_events","type":"User","site_admin":false},"repo":{"id":36888587,"name":"julia","full_name":"pabloferz/julia","owner":{"login":"pabloferz","id":8410335,"avatar_url":"https://avatars.githubusercontent.com/u/8410335?v=3","gravatar_id":"","url":"https://api.github.com/users/pabloferz","html_url":"https://github.com/pabloferz","followers_url":"https://api.github.com/users/pabloferz/followers","following_url":"https://api.github.com/users/pabloferz/following{/other_user}","gists_url":"https://api.github.com/users/pabloferz/gists{/gist_id}","starred_url":"https://api.github.com/users/pabloferz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabloferz/subscriptions","organizations_url":"https://api.github.com/users/pabloferz/orgs","repos_url":"https://api.github.com/users/pabloferz/repos","events_url":"https://api.github.com/users/pabloferz/events{/privacy}","received_events_url":"https://api.github.com/users/pabloferz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pabloferz/julia","description":"The Julia Language: A fresh approach to technical computing.","fork":true,"url":"https://api.github.com/repos/pabloferz/julia","forks_url":"https://api.github.com/repos/pabloferz/julia/forks","keys_url":"https://api.github.com/repos/pabloferz/julia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pabloferz/julia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pabloferz/julia/teams","hooks_url":"https://api.github.com/repos/pabloferz/julia/hooks","issue_events_url":"https://api.github.com/repos/pabloferz/julia/issues/events{/number}","events_url":"https://api.github.com/repos/pabloferz/julia/events","assignees_url":"https://api.github.com/repos/pabloferz/julia/assignees{/user}","branches_url":"https://api.github.com/repos/pabloferz/julia/branches{/branch}","tags_url":"https://api.github.com/repos/pabloferz/julia/tags","blobs_url":"https://api.github.com/repos/pabloferz/julia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pabloferz/julia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pabloferz/julia/git/refs{/sha}","trees_url":"https://api.github.com/repos/pabloferz/julia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pabloferz/julia/statuses/{sha}","languages_url":"https://api.github.com/repos/pabloferz/julia/languages","stargazers_url":"https://api.github.com/repos/pabloferz/julia/stargazers","contributors_url":"https://api.github.com/repos/pabloferz/julia/contributors","subscribers_url":"https://api.github.com/repos/pabloferz/julia/subscribers","subscription_url":"https://api.github.com/repos/pabloferz/julia/subscription","commits_url":"https://api.github.com/repos/pabloferz/julia/commits{/sha}","git_commits_url":"https://api.github.com/repos/pabloferz/julia/git/commits{/sha}","comments_url":"https://api.github.com/repos/pabloferz/julia/comments{/number}","issue_comment_url":"https://api.github.com/repos/pabloferz/julia/issues/comments{/number}","contents_url":"https://api.github.com/repos/pabloferz/julia/contents/{+path}","compare_url":"https://api.github.com/repos/pabloferz/julia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pabloferz/julia/merges","archive_url":"https://api.github.com/repos/pabloferz/julia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pabloferz/julia/downloads","issues_url":"https://api.github.com/repos/pabloferz/julia/issues{/number}","pulls_url":"https://api.github.com/repos/pabloferz/julia/pulls{/number}","milestones_url":"https://api.github.com/repos/pabloferz/julia/milestones{/number}","notifications_url":"https://api.github.com/repos/pabloferz/julia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pabloferz/julia/labels{/name}","releases_url":"https://api.github.com/repos/pabloferz/julia/releases{/id}","deployments_url":"https://api.github.com/repos/pabloferz/julia/deployments","created_at":"2015-06-04T18:40:41Z","updated_at":"2016-01-12T10:40:47Z","pushed_at":"2016-09-06T23:06:51Z","git_url":"git://github.com/pabloferz/julia.git","ssh_url":"git@github.com:pabloferz/julia.git","clone_url":"https://github.com/pabloferz/julia.git","svn_url":"https://github.com/pabloferz/julia","homepage":"http://julialang.org/","size":94561,"stargazers_count":0,"watchers_count":0,"language":"Julia","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"JuliaLang:master","ref":"master","sha":"2ab4a0d5aba0861f4f25d575192a22c95b12dec9","user":{"login":"JuliaLang","id":743164,"avatar_url":"https://avatars.githubusercontent.com/u/743164?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaLang","html_url":"https://github.com/JuliaLang","followers_url":"https://api.github.com/users/JuliaLang/followers","following_url":"https://api.github.com/users/JuliaLang/following{/other_user}","gists_url":"https://api.github.com/users/JuliaLang/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaLang/subscriptions","organizations_url":"https://api.github.com/users/JuliaLang/orgs","repos_url":"https://api.github.com/users/JuliaLang/repos","events_url":"https://api.github.com/users/JuliaLang/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaLang/received_events","type":"Organization","site_admin":false},"repo":{"id":1644196,"name":"julia","full_name":"JuliaLang/julia","owner":{"login":"JuliaLang","id":743164,"avatar_url":"https://avatars.githubusercontent.com/u/743164?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaLang","html_url":"https://github.com/JuliaLang","followers_url":"https://api.github.com/users/JuliaLang/followers","following_url":"https://api.github.com/users/JuliaLang/following{/other_user}","gists_url":"https://api.github.com/users/JuliaLang/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaLang/subscriptions","organizations_url":"https://api.github.com/users/JuliaLang/orgs","repos_url":"https://api.github.com/users/JuliaLang/repos","events_url":"https://api.github.com/users/JuliaLang/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaLang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JuliaLang/julia","description":"The Julia Language: A fresh approach to technical computing.","fork":false,"url":"https://api.github.com/repos/JuliaLang/julia","forks_url":"https://api.github.com/repos/JuliaLang/julia/forks","keys_url":"https://api.github.com/repos/JuliaLang/julia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JuliaLang/julia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JuliaLang/julia/teams","hooks_url":"https://api.github.com/repos/JuliaLang/julia/hooks","issue_events_url":"https://api.github.com/repos/JuliaLang/julia/issues/events{/number}","events_url":"https://api.github.com/repos/JuliaLang/julia/events","assignees_url":"https://api.github.com/repos/JuliaLang/julia/assignees{/user}","branches_url":"https://api.github.com/repos/JuliaLang/julia/branches{/branch}","tags_url":"https://api.github.com/repos/JuliaLang/julia/tags","blobs_url":"https://api.github.com/repos/JuliaLang/julia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JuliaLang/julia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JuliaLang/julia/git/refs{/sha}","trees_url":"https://api.github.com/repos/JuliaLang/julia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JuliaLang/julia/statuses/{sha}","languages_url":"https://api.github.com/repos/JuliaLang/julia/languages","stargazers_url":"https://api.github.com/repos/JuliaLang/julia/stargazers","contributors_url":"https://api.github.com/repos/JuliaLang/julia/contributors","subscribers_url":"https://api.github.com/repos/JuliaLang/julia/subscribers","subscription_url":"https://api.github.com/repos/JuliaLang/julia/subscription","commits_url":"https://api.github.com/repos/JuliaLang/julia/commits{/sha}","git_commits_url":"https://api.github.com/repos/JuliaLang/julia/git/commits{/sha}","comments_url":"https://api.github.com/repos/JuliaLang/julia/comments{/number}","issue_comment_url":"https://api.github.com/repos/JuliaLang/julia/issues/comments{/number}","contents_url":"https://api.github.com/repos/JuliaLang/julia/contents/{+path}","compare_url":"https://api.github.com/repos/JuliaLang/julia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JuliaLang/julia/merges","archive_url":"https://api.github.com/repos/JuliaLang/julia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JuliaLang/julia/downloads","issues_url":"https://api.github.com/repos/JuliaLang/julia/issues{/number}","pulls_url":"https://api.github.com/repos/JuliaLang/julia/pulls{/number}","milestones_url":"https://api.github.com/repos/JuliaLang/julia/milestones{/number}","notifications_url":"https://api.github.com/repos/JuliaLang/julia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JuliaLang/julia/labels{/name}","releases_url":"https://api.github.com/repos/JuliaLang/julia/releases{/id}","deployments_url":"https://api.github.com/repos/JuliaLang/julia/deployments","created_at":"2011-04-21T07:01:50Z","updated_at":"2016-09-06T21:08:11Z","pushed_at":"2016-09-06T23:06:52Z","git_url":"git://github.com/JuliaLang/julia.git","ssh_url":"git@github.com:JuliaLang/julia.git","clone_url":"https://github.com/JuliaLang/julia.git","svn_url":"https://github.com/JuliaLang/julia","homepage":"http://julialang.org/","size":420564,"stargazers_count":7463,"watchers_count":7463,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1747,"mirror_url":null,"open_issues_count":1977,"forks":1747,"open_issues":1977,"watchers":7463,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/16986"},"html":{"href":"https://github.com/JuliaLang/julia/pull/16986"},"issue":{"href":"https://api.github.com/repos/JuliaLang/julia/issues/16986"},"comments":{"href":"https://api.github.com/repos/JuliaLang/julia/issues/16986/comments"},"review_comments":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/16986/comments"},"review_comment":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/16986/commits"},"statuses":{"href":"https://api.github.com/repos/JuliaLang/julia/statuses/a1bfe10a19997c89e03a0838c3bada39cfe931a6"}}}}
{"actor":{"display_login":"stevengj"}}