Skip to content

findnz fail for adjoint sparse matrix #632

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

Open
ErikQQY opened this issue May 31, 2025 · 0 comments
Open

findnz fail for adjoint sparse matrix #632

ErikQQY opened this issue May 31, 2025 · 0 comments

Comments

@ErikQQY
Copy link

ErikQQY commented May 31, 2025

findnz on a regular sparse matrix or vector is working fine, but as for the adjoint of the sparse matrix, it would error about missing dispatches.

MWE:

julia> using SparseArrays

julia> a = sprand(5, 5, 0.3)
5×5 SparseMatrixCSC{Float64, Int64} with 10 stored entries:
 0.0427685  0.200511  0.671743  0.218248    
                                      0.187924
           0.550776           0.575211    
 0.818149                     0.765981    
                                      0.67016

julia> findnz(a)
([1, 4, 1, 3, 1, 1, 3, 4, 2, 5], [1, 1, 2, 2, 3, 4, 4, 4, 5, 5], [0.04276845834332266, 0.8181492402324447, 0.20051143143705996, 0.5507758664465765, 0.671743090935252, 0.21824817491559279, 0.5752107151129244, 0.7659814619199559, 0.18792429490108353, 0.6701601805330932])

julia> findnz(a')
ERROR: MethodError: no method matching findnz(::LinearAlgebra.Adjoint{Float64, SparseMatrixCSC{Float64, Int64}})
The function `findnz` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  findnz(::Union{SparseArrays.AbstractCompressedVector{Tv, Ti}, SubArray{Tv, 1, <:SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, false}, SubArray{Tv, 1, <:AbstractSparseVector{Tv, Ti}, Tuple{Base.Slice{Base.OneTo{Int64}}}, false}} where {Tv, Ti})
   @ SparseArrays ~/.julia/juliaup/julia-1.11.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/SparseArrays/src/sparsevector.jl:904
  findnz(::SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}) where {Tv, Ti}
   @ SparseArrays ~/.julia/juliaup/julia-1.11.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/SparseArrays/src/sparsematrix.jl:1930

Stacktrace:
 [1] top-level scope
   @ REPL[11]:1
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

1 participant