{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/30435","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/30435/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/30435/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/30435/events","html_url":"https://github.com/JuliaLang/julia/pull/30435","id":392242368,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM5NTU3NTE4","number":30435,"title":"similar(::SparseMatrixCSC, dims) returns sparse matrix with empty space (#26560)","user":{"login":"KlausC","id":6223854,"node_id":"MDQ6VXNlcjYyMjM4NTQ=","avatar_url":"https://avatars0.githubusercontent.com/u/6223854?v=4","gravatar_id":"","url":"https://api.github.com/users/KlausC","html_url":"https://github.com/KlausC","followers_url":"https://api.github.com/users/KlausC/followers","following_url":"https://api.github.com/users/KlausC/following{/other_user}","gists_url":"https://api.github.com/users/KlausC/gists{/gist_id}","starred_url":"https://api.github.com/users/KlausC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KlausC/subscriptions","organizations_url":"https://api.github.com/users/KlausC/orgs","repos_url":"https://api.github.com/users/KlausC/repos","events_url":"https://api.github.com/users/KlausC/events{/privacy}","received_events_url":"https://api.github.com/users/KlausC/received_events","type":"User","site_admin":false},"labels":[{"id":94575532,"node_id":"MDU6TGFiZWw5NDU3NTUzMg==","url":"https://api.github.com/repos/JuliaLang/julia/labels/sparse","name":"sparse","color":"fad8c7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":20,"created_at":"2018-12-18T16:44:39Z","updated_at":"2019-01-02T10:33:43Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/30435","html_url":"https://github.com/JuliaLang/julia/pull/30435","diff_url":"https://github.com/JuliaLang/julia/pull/30435.diff","patch_url":"https://github.com/JuliaLang/julia/pull/30435.patch"},"body":"As discussed in issue https://github.com/JuliaLang/julia/issues/26560 the reservation of space for `rowval`and `nzval` in the same size as for the origin leads to inaccessible (by the exported API) memory \r\nlocations.\r\nThe behaviour now is the same for matrices as for sparse vectors in this respect.\r\nIt was checked, that in `stdlib` no use is made of this space (by modifying the internal fields). Actually no `similar` of sparse matrices or vectors at all is used there."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/450830880","html_url":"https://github.com/JuliaLang/julia/pull/30435#issuecomment-450830880","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/30435","id":450830880,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MDgzMDg4MA==","user":{"login":"abraunst","id":7630142,"node_id":"MDQ6VXNlcjc2MzAxNDI=","avatar_url":"https://avatars0.githubusercontent.com/u/7630142?v=4","gravatar_id":"","url":"https://api.github.com/users/abraunst","html_url":"https://github.com/abraunst","followers_url":"https://api.github.com/users/abraunst/followers","following_url":"https://api.github.com/users/abraunst/following{/other_user}","gists_url":"https://api.github.com/users/abraunst/gists{/gist_id}","starred_url":"https://api.github.com/users/abraunst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abraunst/subscriptions","organizations_url":"https://api.github.com/users/abraunst/orgs","repos_url":"https://api.github.com/users/abraunst/repos","events_url":"https://api.github.com/users/abraunst/events{/privacy}","received_events_url":"https://api.github.com/users/abraunst/received_events","type":"User","site_admin":false},"created_at":"2019-01-02T10:33:43Z","updated_at":"2019-01-02T10:33:43Z","author_association":"CONTRIBUTOR","body":"> First, happy new year everyone!  All the best to you and yours in the coming year! :)\r\n\r\nAll the best to everyone :-)\r\n\r\n> Take sparse broadcast again as a prime example, which (in the cases it was designed for) allocates only if it runs out of storage in the destination: You do not know how much storage e.g. `sin.(A)` might require, and typically the best guess is the storage of the argument(s); with that guess, e.g. `sin.(A)` ends up in good shape without reallocation (you typically end up with either the right amount of storage or only marginally more than you strictly need). If you do have to reallocate, which you would always have to do at the outset of the operation with the destination being empty, your options are roughly to: 1) reallocate pessimistically but only once and safely (which regrettably the present implementation does as a stopgap in some cases it wasn't designed for, and clearly isn't the happiest behavior); or 2) reallocate optimistically, at risk of having to reallocate repeatedly, and almost certainly allocating more space (by roughly your growth factor) than you will ultimately need. So the tradeoffs here are regrettably not merely two additional empty allocations one way or another.\r\n\r\nWouldn't it suffice to `sizehint!` the `nzval` and `rowval` vectors, in order to perform the allocation, but keep their nominal size at zero? In this way we would have both coherence and the optimization gain due to preallocation. If it's too difficult to put it in the calling code (e.g. broadcast), the `sizehint!` call could be just left in `similar`. In this way the two problems seem to me more or less orthogonal to me..."}}
{"actor":{"display_login":"abraunst"}}