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

StaticIndexing breaks the to_indices interface #1204

Open
rafaqz opened this issue Sep 26, 2023 · 3 comments
Open

StaticIndexing breaks the to_indices interface #1204

rafaqz opened this issue Sep 26, 2023 · 3 comments

Comments

@rafaqz
Copy link
Contributor

rafaqz commented Sep 26, 2023

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:

struct StaticIndexing{I}
ind::I
end
unwrap(i::StaticIndexing) = i.ind
function Base.to_indices(A, I::Tuple{Vararg{Union{Integer, CartesianIndex, StaticArray{<:Tuple,Int}}}})
inds = to_indices(A, axes(A), I)
return map(StaticIndexing, inds)
end

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

@mbauman
Copy link
Member

mbauman commented Sep 26, 2023

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
Copy link
Collaborator

Probably duplicate of #878? See also #879.

@rafaqz
Copy link
Contributor Author

rafaqz commented Sep 26, 2023

@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.

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

No branches or pull requests

3 participants