{"action":"created","comment":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/comments/87340638","pull_request_review_id":7956361,"id":87340638,"diff_hunk":"@@ -126,6 +126,34 @@ _length(A) = length(A)\n endof(a::AbstractArray) = length(a)\n first(a::AbstractArray) = a[first(eachindex(a))]\n \n+function fixate_eltype{T<:AbstractArray}(::Type{T}, default::Type)\n+    @_pure_meta\n+    aa_type = T\n+    while aa_type.name.primary != AbstractArray\n+        aa_type = supertype(aa_type)\n+    end\n+    if isa(aa_type.parameters[1], TypeVar)\n+        varname = aa_type.parameters[1].name\n+        new_params = collect(T.parameters)\n+        for i in eachindex(new_params)\n+            p = new_params[i]\n+            if isa(p, TypeVar) && p.name == varname\n+                new_params[i] = default\n+            end\n+        end\n+        return T.name.primary{new_params...}\n+    else\n+        return T\n+    end\n+end","path":"base/abstractarray.jl","position":23,"original_position":23,"commit_id":"e7e9bb1b9a8ee959744f28f0a5439b1a4d8839ba","original_commit_id":"e7e9bb1b9a8ee959744f28f0a5439b1a4d8839ba","user":{"login":"martinholters","id":15785210,"avatar_url":"https://avatars.githubusercontent.com/u/15785210?v=3","gravatar_id":"","url":"https://api.github.com/users/martinholters","html_url":"https://github.com/martinholters","followers_url":"https://api.github.com/users/martinholters/followers","following_url":"https://api.github.com/users/martinholters/following{/other_user}","gists_url":"https://api.github.com/users/martinholters/gists{/gist_id}","starred_url":"https://api.github.com/users/martinholters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinholters/subscriptions","organizations_url":"https://api.github.com/users/martinholters/orgs","repos_url":"https://api.github.com/users/martinholters/repos","events_url":"https://api.github.com/users/martinholters/events{/privacy}","received_events_url":"https://api.github.com/users/martinholters/received_events","type":"User","site_admin":false},"body":"I deliberately wanted `fixate_eltype(Diagonal{Int}, Float64) === Diagonal{Int}` to be able to specify a default element type. E.g. `zeros(Diagonal, 2, 2)` should give a `Diagonal{Float64}`, but `zeros(Diagonal{Int}, 2, 2)` should give a `Diagonal{Int}`. Maybe a third, boolean argument could be used to choose between \"set always\" and \"set only if unset\".","created_at":"2016-11-10T07:32:06Z","updated_at":"2016-11-10T07:32:06Z","html_url":"https://github.com/JuliaLang/julia/pull/16740#discussion_r87340638","pull_request_url":"https://api.github.com/repos/JuliaLang/julia/pulls/16740","_links":{"self":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/comments/87340638"},"html":{"href":"https://github.com/JuliaLang/julia/pull/16740#discussion_r87340638"},"pull_request":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/16740"}}},"pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/16740","id":72503756,"html_url":"https://github.com/JuliaLang/julia/pull/16740","diff_url":"https://github.com/JuliaLang/julia/pull/16740.diff","patch_url":"https://github.com/JuliaLang/julia/pull/16740.patch","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/16740","number":16740,"state":"open","locked":false,"title":"RFC/WIP: Support array type as input for functions returning AbstractArray instance","user":{"login":"martinholters","id":15785210,"avatar_url":"https://avatars.githubusercontent.com/u/15785210?v=3","gravatar_id":"","url":"https://api.github.com/users/martinholters","html_url":"https://github.com/martinholters","followers_url":"https://api.github.com/users/martinholters/followers","following_url":"https://api.github.com/users/martinholters/following{/other_user}","gists_url":"https://api.github.com/users/martinholters/gists{/gist_id}","starred_url":"https://api.github.com/users/martinholters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinholters/subscriptions","organizations_url":"https://api.github.com/users/martinholters/orgs","repos_url":"https://api.github.com/users/martinholters/repos","events_url":"https://api.github.com/users/martinholters/events{/privacy}","received_events_url":"https://api.github.com/users/martinholters/received_events","type":"User","site_admin":false},"body":"This is a shot at #11557.\n\nAt the moment, only `zeros`, `ones`, and `eye` are supported. For example\n\n``` Julia\neye(Bidiagonal, 4, 4)        # Bidiagonal{Float64}\neye(Bidiagonal{Int64}, 4, 4) # Bidiagonal{Int64}\n```\n\nwill return 4×4 identity matrices of the indicated types. (EDIT: Changed example to use `Bidiagonal`.) There is still some work ahead, but I'd appreciate feedback on the approach taken before committing more time to this. To avoid code duplication, I have added `Type(dims...)` like constructors for all array types where it makes sense and then implemented `zeros`, `ones`, and `eye` for `{T<:AbstractArray}(::Type{T}, dims...)` using these.\n\nTo exercise things, `spzeros` now simply falls back to `zeros` while `speye` forwards to a custom `eye(::Type{SparseMatrixCSC}, dims...)` (which is more efficient than the generic implementation). So far, no syntax or functionality is invalidated/removed, with one exception: `spzeros(Any, ...)` now fails with `ERROR: MethodError: no method matching zero(::Type{Any})`, while previously it succeeded in constructing a matrix, which however was of rather limited use.\n\nIn addition to extending this to more functions (suggestions welcome) and adding tests and docs, there is a more conceptual aspect that might need some work: the way missing type parameters are handled. Presently, all new constructors just use `Float64` as default eltype which just happens to be the right thing to do for these functions, but seems a bit arbitrary and requires special-casing `Array`, which defaults to `Array{Any}`. I'm thinking about something like `fixate_eltype{T<:AbstractArray}(::Type{T}, default::Type)` that would be implemented by array types like e.g.\n\n``` Julia\nfixate_eltype(::Type{SparseMatrixCSC}, default::Type) = SparseMatrixCSC{default,Int}\nfixate_eltype{Tv}(::Type{SparseMatrixCSC{Tv}}, default::Type) = SparseMatrixCSC{Tv,Int}\nfixate_eltype{Tv,Ti}(::Type{SparseMatrixCSC{Tv,Ti}}, default::Type) = SparseMatrixCSC{Tv,Ti}\n```\n\nThoughts?\n","created_at":"2016-06-03T13:05:50Z","updated_at":"2016-11-10T07:32:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5b256c81bae1c673ae5bb8268d516de2e437b750","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/JuliaLang/julia/pulls/16740/commits","review_comments_url":"https://api.github.com/repos/JuliaLang/julia/pulls/16740/comments","review_comment_url":"https://api.github.com/repos/JuliaLang/julia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/16740/comments","statuses_url":"https://api.github.com/repos/JuliaLang/julia/statuses/e7e9bb1b9a8ee959744f28f0a5439b1a4d8839ba","head":{"label":"martinholters:array_constr_type","ref":"array_constr_type","sha":"e7e9bb1b9a8ee959744f28f0a5439b1a4d8839ba","user":{"login":"martinholters","id":15785210,"avatar_url":"https://avatars.githubusercontent.com/u/15785210?v=3","gravatar_id":"","url":"https://api.github.com/users/martinholters","html_url":"https://github.com/martinholters","followers_url":"https://api.github.com/users/martinholters/followers","following_url":"https://api.github.com/users/martinholters/following{/other_user}","gists_url":"https://api.github.com/users/martinholters/gists{/gist_id}","starred_url":"https://api.github.com/users/martinholters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinholters/subscriptions","organizations_url":"https://api.github.com/users/martinholters/orgs","repos_url":"https://api.github.com/users/martinholters/repos","events_url":"https://api.github.com/users/martinholters/events{/privacy}","received_events_url":"https://api.github.com/users/martinholters/received_events","type":"User","site_admin":false},"repo":{"id":52508350,"name":"julia","full_name":"martinholters/julia","owner":{"login":"martinholters","id":15785210,"avatar_url":"https://avatars.githubusercontent.com/u/15785210?v=3","gravatar_id":"","url":"https://api.github.com/users/martinholters","html_url":"https://github.com/martinholters","followers_url":"https://api.github.com/users/martinholters/followers","following_url":"https://api.github.com/users/martinholters/following{/other_user}","gists_url":"https://api.github.com/users/martinholters/gists{/gist_id}","starred_url":"https://api.github.com/users/martinholters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinholters/subscriptions","organizations_url":"https://api.github.com/users/martinholters/orgs","repos_url":"https://api.github.com/users/martinholters/repos","events_url":"https://api.github.com/users/martinholters/events{/privacy}","received_events_url":"https://api.github.com/users/martinholters/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/martinholters/julia","description":"The Julia Language: A fresh approach to technical computing.","fork":true,"url":"https://api.github.com/repos/martinholters/julia","forks_url":"https://api.github.com/repos/martinholters/julia/forks","keys_url":"https://api.github.com/repos/martinholters/julia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/martinholters/julia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/martinholters/julia/teams","hooks_url":"https://api.github.com/repos/martinholters/julia/hooks","issue_events_url":"https://api.github.com/repos/martinholters/julia/issues/events{/number}","events_url":"https://api.github.com/repos/martinholters/julia/events","assignees_url":"https://api.github.com/repos/martinholters/julia/assignees{/user}","branches_url":"https://api.github.com/repos/martinholters/julia/branches{/branch}","tags_url":"https://api.github.com/repos/martinholters/julia/tags","blobs_url":"https://api.github.com/repos/martinholters/julia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/martinholters/julia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/martinholters/julia/git/refs{/sha}","trees_url":"https://api.github.com/repos/martinholters/julia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/martinholters/julia/statuses/{sha}","languages_url":"https://api.github.com/repos/martinholters/julia/languages","stargazers_url":"https://api.github.com/repos/martinholters/julia/stargazers","contributors_url":"https://api.github.com/repos/martinholters/julia/contributors","subscribers_url":"https://api.github.com/repos/martinholters/julia/subscribers","subscription_url":"https://api.github.com/repos/martinholters/julia/subscription","commits_url":"https://api.github.com/repos/martinholters/julia/commits{/sha}","git_commits_url":"https://api.github.com/repos/martinholters/julia/git/commits{/sha}","comments_url":"https://api.github.com/repos/martinholters/julia/comments{/number}","issue_comment_url":"https://api.github.com/repos/martinholters/julia/issues/comments{/number}","contents_url":"https://api.github.com/repos/martinholters/julia/contents/{+path}","compare_url":"https://api.github.com/repos/martinholters/julia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/martinholters/julia/merges","archive_url":"https://api.github.com/repos/martinholters/julia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/martinholters/julia/downloads","issues_url":"https://api.github.com/repos/martinholters/julia/issues{/number}","pulls_url":"https://api.github.com/repos/martinholters/julia/pulls{/number}","milestones_url":"https://api.github.com/repos/martinholters/julia/milestones{/number}","notifications_url":"https://api.github.com/repos/martinholters/julia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/martinholters/julia/labels{/name}","releases_url":"https://api.github.com/repos/martinholters/julia/releases{/id}","deployments_url":"https://api.github.com/repos/martinholters/julia/deployments","created_at":"2016-02-25T08:19:41Z","updated_at":"2016-02-25T08:19:47Z","pushed_at":"2016-11-09T14:46:08Z","git_url":"git://github.com/martinholters/julia.git","ssh_url":"git@github.com:martinholters/julia.git","clone_url":"https://github.com/martinholters/julia.git","svn_url":"https://github.com/martinholters/julia","homepage":"http://julialang.org/","size":100157,"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":"a3a78c2b5d6fb4e44f3b26cea894dc2ab518cd05","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-11-10T06:58:58Z","pushed_at":"2016-11-10T06:46:38Z","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":430670,"stargazers_count":7787,"watchers_count":7787,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1830,"mirror_url":null,"open_issues_count":2181,"forks":1830,"open_issues":2181,"watchers":7787,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/16740"},"html":{"href":"https://github.com/JuliaLang/julia/pull/16740"},"issue":{"href":"https://api.github.com/repos/JuliaLang/julia/issues/16740"},"comments":{"href":"https://api.github.com/repos/JuliaLang/julia/issues/16740/comments"},"review_comments":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/16740/comments"},"review_comment":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/16740/commits"},"statuses":{"href":"https://api.github.com/repos/JuliaLang/julia/statuses/e7e9bb1b9a8ee959744f28f0a5439b1a4d8839ba"}}}}
{"actor":{"display_login":"martinholters"}}