JuliaArrays / StaticArrays.jl

Statically sized arrays for Julia
Other
774 stars 148 forks source link

StaticIndexing breaks the `to_indices` interface #1204

Open rafaqz opened 1 year ago

rafaqz commented 1 year ago

The to_indices docs state that:

The returned tuple must only contain either Ints or AbstractArrays of scalar indices that are supported by array A

But StaticIndexing is not either:

https://github.com/JuliaArrays/StaticArrays.jl/blob/217e6f10a01433b8a60b679622065bc8702da923/src/indexing.jl#L213-L221

See discourse: https://discourse.julialang.org/t/a-sparse-matrix-cannot-be-indexed-by-a-svector/104265/5

mbauman commented 1 year ago

scalar indices that are supported by array A

This is exactly why the machinery passes A itself so deeply into the call stack here. Simple fix would be something like:

KnownStaticFriendlyArrays = Union{StaticArray, Array, #= others? ... =#}
static_index(A::KnownStaticFriendlyArray, ind) = StaticIndexing(ind)
static_index(A, ind) = ind
# ...
    return map(i->static_index(A, i), inds)
mateuszbaran commented 1 year ago

Probably duplicate of #878? See also #879.

rafaqz commented 1 year ago

@mbauman the docs still says AbstractArray of scalar indices even for known friendly types ;)

But absolutely, limiting it as to_indices(A::StaticArray, ... would fix the problem.