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

static indexing on sparse array doesn't work anymore #878

Closed
Roger-luo opened this issue Feb 20, 2021 · 4 comments · Fixed by #879
Closed

static indexing on sparse array doesn't work anymore #878

Roger-luo opened this issue Feb 20, 2021 · 4 comments · Fixed by #879

Comments

@Roger-luo
Copy link

Roger-luo commented Feb 20, 2021

not sure what is changed, but is causing QuantumBFS/tutorials#17

MWE:

julia> using StaticArrays, SparseArrays

julia> st = sprand(16, 1, 0.1);

julia> I = @SVector [2, 4];

julia> st[I, 1] = st[I, 1]
ERROR: MethodError: no method matching length(::StaticArrays.StaticIndexing{SVector{2, Int64}})
Closest candidates are:
  length(::Union{Base.KeySet, Base.ValueIterator}) at abstractdict.jl:58
  length(::Union{LinearAlgebra.Adjoint{T, var"#s6"} where var"#s6"<:Union{StaticVector{var"#s1", T} where var"#s1", StaticMatrix{var"#s4", var"#s5", T} where {var"#s4", var"#s5"}}, LinearAlgebra.Diagonal{T, var"#s13"} where var"#s13"<:(StaticVector{var"#s14", T} where var"#s14"), LinearAlgebra.Hermitian{T, var"#s10"} where var"#s10"<:(StaticMatrix{var"#s11", var"#s12", T} where {var"#s11", var"#s12"}), LinearAlgebra.LowerTriangular{T, var"#s18"} where var"#s18"<:(StaticMatrix{var"#s19", var"#s20", T} where {var"#s19", var"#s20"}), LinearAlgebra.Symmetric{T, var"#s7"} where var"#s7"<:(StaticMatrix{var"#s8", var"#s9", T} where {var"#s8", var"#s9"}), LinearAlgebra.Transpose{T, var"#s1"} where var"#s1"<:Union{StaticVector{var"#s1", T} where var"#s1", StaticMatrix{var"#s4", var"#s5", T} where {var"#s4", var"#s5"}}, LinearAlgebra.UnitLowerTriangular{T, var"#s24"} where var"#s24"<:(StaticMatrix{var"#s25", var"#s26", T} where {var"#s25", var"#s26"}), LinearAlgebra.UnitUpperTriangular{T, var"#s21"} where var"#s21"<:(StaticMatrix{var"#s22", var"#s23", T} where {var"#s22", var"#s23"}), LinearAlgebra.UpperTriangular{T, var"#s15"} where var"#s15"<:(StaticMatrix{var"#s16", var"#s17", T} where {var"#s16", var"#s17"}), StaticVector{var"#s26", T} where var"#s26", StaticMatrix{var"#s5", var"#s4", T} where {var"#s5", var"#s4"}, StaticArray{var"#s26", T, N} where {var"#s26"<:Tuple, N}} where T) at /Users/roger/.julia/packages/StaticArrays/LJQEe/src/abstractarray.jl:1
  length(::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/adjtrans.jl:207
  ...
Stacktrace:
 [1] setindex!(A::SparseMatrixCSC{Float64, Int64}, V::SparseVector{Float64, Int64}, Ix::SVector{2, Int64}, Jx::Int64)
   @ SparseArrays /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/SparseArrays/src/sparsematrix.jl:2798
 [2] top-level scope
   @ REPL[10]:1
@Roger-luo
Copy link
Author

it works on normal vectors, I assume static vector should work on this case with iterate, length interface etc. defeind?

@andyferris
Copy link
Member

I’m surprised to see 'StaticIndexing` being intercepted outside this package. I thought it was meant to be internal?

If not then it probably needs to be a valid set of array indices (like an AbstractArray).

I suppose this might be the nature of setindex! though?

@mateuszbaran
Copy link
Collaborator

StaticIndexing can't be considered internal since it is returned by a method extending a function from Base.to_indices. Currently StaticArrays breaks the rules described here: https://docs.julialang.org/en/v1/base/arrays/#Base.to_indices. I think StaticIndexing should be <:AbstractVector and support length and getindex operations.

@andyferris
Copy link
Member

Yeah that does sound good.

@mateuszbaran mateuszbaran linked a pull request Feb 27, 2021 that will close this issue
mateuszbaran added a commit that referenced this issue Sep 28, 2023
* Improved StaticIndexing (issue #878)

* improve coverage

* fix test on 32-bit systems

* add subtyping

* fix

* disambiguation

* implement size

* don't `<:AbstractVector` for now

* remove disambiguation
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 a pull request may close this issue.

3 participants