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

map SOneTo to arrays? 🤷‍♀️ #855

Open
fonsp opened this issue Nov 27, 2020 · 3 comments
Open

map SOneTo to arrays? 🤷‍♀️ #855

fonsp opened this issue Nov 27, 2020 · 3 comments
Labels

Comments

@fonsp
Copy link
Contributor

fonsp commented Nov 27, 2020

This causes fonsp/Pluto.jl#458

MWE:

julia> using StaticArrays

julia> s = SA[1,2,3];

julia> i = eachindex(s)
SOneTo(3)

julia> map(i) do k
           []
       end
ERROR: setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] setindex! at /home/fons/.julia/packages/StaticArrays/LJQEe/src/MArray.jl:99 [inlined]
 [3] collect_to_with_first!(::MArray{Tuple{3},Array{Any,1},1,3}, ::Array{Any,1}, ::Base.Generator{SOneTo{3},var"#3#4"}, ::Int64) at ./array.jl:709
 [4] _collect(::SOneTo{3}, ::Base.Generator{SOneTo{3},var"#3#4"}, ::Base.EltypeUnknown, ::Base.HasShape{1}) at ./array.jl:704
 [5] collect_similar(::SOneTo{3}, ::Base.Generator{SOneTo{3},var"#3#4"}) at ./array.jl:628
 [6] map(::Function, ::SOneTo{3}) at ./abstractarray.jl:2162
 [7] top-level scope at REPL[6]:1

Note that this map is fine:

julia> map(i) do k
           2
       end
3-element MArray{Tuple{3},Int64,1,3} with indices SOneTo(3):
 2
 2
 2

Julia 1.5.2, StaticArrays v0.12.5

@fonsp fonsp changed the title map SOneTo to arrays 🤷‍♀️ map SOneTo to arrays? 🤷‍♀️ Nov 27, 2020
@c42f c42f added the bug label Dec 1, 2020
@c42f
Copy link
Member

c42f commented Dec 1, 2020

Would likely be fixed by #749

@andyferris
Copy link
Member

The root cause here is that SOneTo is not a StaticArray (it subtypes AbstractUnitRange) and we don’t have most the methods defined for it and it is falling back to generic one from Base. Which is a problem in general and I’m not sure how much effort it would be to fix for all methods normally defined for static arrays...

@c42f
Copy link
Member

c42f commented Dec 1, 2020

The other more direct cause is that similar(SOneTo(3)) produces an MArray and setindex! isn't defined for MArray of non-isbits type. #749 would fix this, though I've been a little hesitant to merge that because it's inefficient.

But yes the underlying dispatch problem is that SOneTo <: AbstractUnitRange is not a subtype of StaticArray and can't really be made into one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants