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

[BUG] TensorAlgebra.qr(::SparseArrays.SparseMatrixCSC, ...) broken #21

Open
mtfishman opened this issue Jan 24, 2025 · 3 comments
Open
Labels
bug Something isn't working

Comments

@mtfishman
Copy link
Member

For example:

julia> using TensorAlgebra

julia> using SparseArrays

julia> TensorAlgebra.qr(sprandn(2, 2, 0.5), ("i", "j"), ("i",), ("j",))
ERROR: MethodError: no method matching iterate(::SparseArrays.SPQR.QRSparse{Float64, Int64})
The function `iterate` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  iterate(::SimpleTraits.GenerateTypeVars{:upcase})
   @ SimpleTraits ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:445
  iterate(::SimpleTraits.GenerateTypeVars{:lcase})
   @ SimpleTraits ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:446
  iterate(::SimpleTraits.GenerateTypeVars{:upcase}, ::Any)
   @ SimpleTraits ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:445
  ...

Stacktrace:
 [1] indexed_iterate(I::SparseArrays.SPQR.QRSparse{Float64, Int64}, i::Int64)
   @ Base ./tuple.jl:162
 [2] qr(a::SparseMatrixCSC{Float64, Int64}, biperm::TensorAlgebra.BlockedPermutation{2, (1, 1), Tuple{Int64, Int64}})
   @ TensorAlgebra ~/.julia/packages/TensorAlgebra/p4Ouf/src/factorizations.jl:8
 [3] qr(a::SparseMatrixCSC{Float64, Int64}, labels_a::Tuple{String, String}, labels_codomain::Tuple{String}, labels_domain::Tuple{String})
   @ TensorAlgebra ~/.julia/packages/TensorAlgebra/p4Ouf/src/factorizations.jl:20
 [4] top-level scope
   @ REPL[10]:1

julia> pkgversion(TensorAlgebra)
v"0.1.7"

The reason for the error is that LinearAlgebra.qr(::SparseArrays.SparseMatrixCSC) outputs a factorization object that can't be unpacked as a tuple:

julia> using LinearAlgebra

julia> using SparseArrays

julia> q, r = qr(sprandn(2, 2, 0.5))
ERROR: MethodError: no method matching iterate(::SparseArrays.SPQR.QRSparse{Float64, Int64})
The function `iterate` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  iterate(::SimpleTraits.GenerateTypeVars{:upcase})
   @ SimpleTraits ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:445
  iterate(::SimpleTraits.GenerateTypeVars{:lcase})
   @ SimpleTraits ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:446
  iterate(::SimpleTraits.GenerateTypeVars{:upcase}, ::Any)
   @ SimpleTraits ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:445
  ...

Stacktrace:
 [1] indexed_iterate(I::SparseArrays.SPQR.QRSparse{Float64, Int64}, i::Int64)
   @ Base ./tuple.jl:162
 [2] top-level scope
   @ REPL[16]:1

which is being used inside TensorAlgebra.qr.

@mtfishman mtfishman added the bug Something isn't working label Jan 24, 2025
@mtfishman
Copy link
Member Author

@lkdvos maybe this could be a good use case for MatrixAlgebraKit.jl, i.e. defining a uniform interface for sparse and dense QR.

@lkdvos
Copy link
Contributor

lkdvos commented Jan 24, 2025

I'm trying to get that pushed along indeed, since that would also be a good place to have the truncated SVD. I am hoping to get that registered by the end of next week, but if not I can do a temporary hack and just add it to the ITensor registry.

@mtfishman
Copy link
Member Author

I'm trying to get that pushed along indeed, since that would also be a good place to have the truncated SVD. I am hoping to get that registered by the end of next week, but if not I can do a temporary hack and just add it to the ITensor registry.

Sounds good! Probably it would be helpful for us to meet up for you to go over that package with me since I haven't been following along with the development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants