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

Improved StaticIndexing (issue #878) #879

Merged
merged 10 commits into from
Sep 28, 2023

Conversation

mateuszbaran
Copy link
Collaborator

These changes make the example in issue #878 work. I didn't put the exact example in tests because I didn't want to add a new test dependency (SparseArrays) but I can add it if you want.

@mateuszbaran mateuszbaran linked an issue Feb 27, 2021 that may be closed by this pull request
Copy link
Contributor

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly fine, but StaticIndexing needs to be Int or AbstractArray to follow the to_indices interface:

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

As A is untyped here this means for any possible AbstractArray, so it needs to follow the interface.

@mateuszbaran
Copy link
Collaborator Author

Would just subtyping StaticIndexing{I} <: AbstractVector{Int} be OK?

@rafaqz
Copy link
Contributor

rafaqz commented Sep 26, 2023

I think so

@rafaqz
Copy link
Contributor

rafaqz commented Sep 26, 2023

It also needs size rather than length

@rafaqz
Copy link
Contributor

rafaqz commented Sep 26, 2023

I just realised this is still incorrect... now we are wrapping Int indices in a AbstractArray which will change the indexing behavior.

I don't know why StaticArrays is doing this but I think we need to just limit the to_indices here to dispatch on A::StaticArray or this will just be wrong in some cases.

Another option is to not wrap Int or CartesianIndex in StaticIndices at all, so map(StaticIndices, ... needs a conditional on the type.

@mateuszbaran
Copy link
Collaborator Author

Well, I'm afraid limiting that to_indices dispatch may break some optimization. If this isn't (close to) good enough then I think I will leave this issue for someone else.

@mbauman
Copy link
Member

mbauman commented Sep 26, 2023

I suspect the rough idea behind StaticIndexing is so that StaticArrays can define implementations like f(A::AbstractArray, Idx::StaticIndexing...) without worry of ambiguities. Making it an StaticIndexing <: AbstractVector won't quite work, as far as I understand it, because it needs to wrap integers, matrices and other-dimensional arrays in addition to vectors.

@rafaqz
Copy link
Contributor

rafaqz commented Sep 26, 2023

It really can't dispatch on AbstractArray or we will just keep getting confused Discourse posts when it breaks.

Maybe supporting StaticArray and Array is enough for performance? Or a wider set of Base arrays?

@mateuszbaran
Copy link
Collaborator Author

I think it's less wrong to go with the changes that I've just pushed than keep the status quo, so I'm going to merge this (if CI passes and there are no objections). More comprehensive changes can happen in a separate PR (which I'm not planning to work on in the foreseeable future).

@mateuszbaran mateuszbaran merged commit d80455d into master Sep 28, 2023
20 of 27 checks passed
@mateuszbaran mateuszbaran deleted the mbaran/static-indexing-improvements branch September 28, 2023 16:32
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

Successfully merging this pull request may close these issues.

static indexing on sparse array doesn't work anymore
3 participants