{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/29546","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/29546/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/29546/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/29546/events","html_url":"https://github.com/JuliaLang/julia/pull/29546","id":367424071,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIwODY1MjQw","number":29546,"title":"Delegate mightalias(::ReinterpretArray, ::ReinterpretArray) to parent","user":{"login":"tkf","id":29282,"node_id":"MDQ6VXNlcjI5Mjgy","avatar_url":"https://avatars3.githubusercontent.com/u/29282?v=4","gravatar_id":"","url":"https://api.github.com/users/tkf","html_url":"https://github.com/tkf","followers_url":"https://api.github.com/users/tkf/followers","following_url":"https://api.github.com/users/tkf/following{/other_user}","gists_url":"https://api.github.com/users/tkf/gists{/gist_id}","starred_url":"https://api.github.com/users/tkf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkf/subscriptions","organizations_url":"https://api.github.com/users/tkf/orgs","repos_url":"https://api.github.com/users/tkf/repos","events_url":"https://api.github.com/users/tkf/events{/privacy}","received_events_url":"https://api.github.com/users/tkf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-10-06T05:01:03Z","updated_at":"2018-10-16T00:03:49Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/29546","html_url":"https://github.com/JuliaLang/julia/pull/29546","diff_url":"https://github.com/JuliaLang/julia/pull/29546.diff","patch_url":"https://github.com/JuliaLang/julia/pull/29546.patch"},"body":"It fixes #29545, i.e., it makes the following snippet work\r\n\r\n```julia\r\nbuffer = zeros(UInt8, 4 * sizeof(Int))\r\nmid = length(buffer) ÷ 2\r\nx1 = reinterpret(Int, @view buffer[1:mid])\r\nx2 = reinterpret(Int, @view buffer[mid+1:end])\r\nx1 .= x2\r\n```\r\n\r\nHowever, this PR still has some problems.  For example, it does not support `mightalias(::ReinterpretArray, ::SubArray)`.  But defining `mightalias(::ReinterpretArray, ::AbstractArray)` and `mightalias(::AbstractArray, ::ReinterpretArray)` would cause the ambiguity problem (and not DRY).\r\n\r\nA general question is: How one can ensure that `mightalias` is symmetric (i.e., `mightalias(a, b) == mightalias(b, a)`) and easily overloadable?  One possibility is to define a function (say)\r\n\r\n```julia\r\nsymmetric_mightalias(a, b) = mightalias(a, b) && mightalias(b, a)\r\n```\r\n\r\nand document that the first argument of `mightalias` has to specify the type user defined (to reduce ambiguity).\r\n\r\nNote that `symmetric_mightalias` has to be exposed as a public (non-overloadable) API so that it can be called from user's `mightalias`:\r\n\r\n```julia\r\nmightalias(a::ReinterpretArray, b::AbstractArray) = symmetric_mightalias(parent(a), b)\r\n```\r\n\r\nIs it a sane approach?  I'm pretty sure this is a generic problem solved in Julia community ages ago.\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/430055466","html_url":"https://github.com/JuliaLang/julia/pull/29546#issuecomment-430055466","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/29546","id":430055466,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDA1NTQ2Ng==","user":{"login":"tkf","id":29282,"node_id":"MDQ6VXNlcjI5Mjgy","avatar_url":"https://avatars3.githubusercontent.com/u/29282?v=4","gravatar_id":"","url":"https://api.github.com/users/tkf","html_url":"https://github.com/tkf","followers_url":"https://api.github.com/users/tkf/followers","following_url":"https://api.github.com/users/tkf/following{/other_user}","gists_url":"https://api.github.com/users/tkf/gists{/gist_id}","starred_url":"https://api.github.com/users/tkf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkf/subscriptions","organizations_url":"https://api.github.com/users/tkf/orgs","repos_url":"https://api.github.com/users/tkf/repos","events_url":"https://api.github.com/users/tkf/events{/privacy}","received_events_url":"https://api.github.com/users/tkf/received_events","type":"User","site_admin":false},"created_at":"2018-10-16T00:03:49Z","updated_at":"2018-10-16T00:03:49Z","author_association":"CONTRIBUTOR","body":"> Note, too, that tracking subsetted memory locations through different views is exceedingly difficult and likely to be too expensive to be worthwhile in all but the most trivial of cases.\r\n\r\nI don't think what I'm suggesting would introduce more complex analysis.  It's all about delegating to existing dedicated analysis and making use of it more.\r\n\r\nI suppose that until the buffer type #12447 is introduced, `SubArray` would be the only non-unsafe way to create a custom memory pool?  I think `reinterpret`ed `view` is a good substitute until then.\r\n\r\nAside: Reading #29481, I started thinking that Julia may not have a standard way to define extensible symmetric/commutative interface.  My idea above is somewhat based on Python's [`NotImplemented` and `__add__`/`__radd__` method pairs](https://docs.python.org/3/reference/datamodel.html#object.__add__) and I think it can work in other cases like #29481.  While it's not possible to fix #29481 in 1.x time-frame, I think it would be nice to establish a standard strategy for achieving symmetry/commutativity before 2.0 and start using it whenever possible.  Perhaps even turn it into a trait-based system.  If what I presented here was one of the application of the standard pattern, I think the apparent complexity could be considered \"amortized.\"\r\n"}}
{"actor":{"display_login":"tkf"}}