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

Support for qr factorizations #545

Open
kmp5VT opened this issue Jun 27, 2024 · 2 comments
Open

Support for qr factorizations #545

kmp5VT opened this issue Jun 27, 2024 · 2 comments

Comments

@kmp5VT
Copy link

kmp5VT commented Jun 27, 2024

Hello,

I am trying to convert the output packed Q output of the QR decomposition of a JLArray back into a JLArray but there is a constructor error being thrown.

 julia> using JLArrays, LinearAlgebra
 julia> A = JLArray(randn(8,4))
 julia> Q,R = qr(A)
 julia> convert(typeof(A), Q)
 ERROR: MethodError: no method matching JLArray{Float64, 2}(::LinearAlgebra.QRCompactWYQ{Float64, JLArray{Float64, 2}, 
 JLArray{Float64, 2}})
 
 Closest candidates are:
  JLArray{T, N}(::UndefInitializer, ::Tuple{Vararg{Int64, N}}) where {T, N}
   @ JLArrays ~/.julia/packages/JLArrays/hD5YX/src/JLArrays.jl:168
  JLArray{T, N}(::UndefInitializer, ::Tuple{Vararg{Integer, N}}) where {T, N}
   @ JLArrays ~/.julia/packages/JLArrays/hD5YX/src/JLArrays.jl:207
  JLArray{T, N}(::UndefInitializer, Integer...) where {T, N}
   @ JLArrays ~/.julia/packages/JLArrays/hD5YX/src/JLArrays.jl:209
  ...

Stacktrace:
 [1] convert(::Type{JLArray{Float64, 2}}, Q::LinearAlgebra.QRCompactWYQ{Float64, JLArray{Float64, 2}, JLArray{Float64, 2}})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LinearAlgebra/src/abstractq.jl:49
 [2] top-level scope
   @ ~/.julia/dev/testing.jl:187
@maleadt
Copy link
Member

maleadt commented Jun 27, 2024

GPUArrays.jl does not support factorizations. It's interesting that qr(A) doesn't error straight away.

This may be easy to fix, since it seems like the factorization was computed correctly, but I'm not familiar enough to be sure. In any case, CUDA.jl carries quite a bit of code for QR factorizations: https://github.com/JuliaGPU/CUDA.jl/blob/14de0097ff7c26932cc4a175840961cc7d3f396e/lib/cusolver/linalg.jl#L141-L237. Quite a bit of those rely on CUSOLVER APIs, so I'm not sure it's possible to add this here.

@maleadt maleadt changed the title Converting packed QR matrix into a JLArray results in an error. Support for qr factorizations Jun 27, 2024
@kmp5VT
Copy link
Author

kmp5VT commented Jun 27, 2024

Yeah it actually has no issue running the QR and gets the right answer

julia> A = JLArray(randn(5,5))
5×5 JLArray{Float64, 2}:
 -1.72275   -1.71712   -0.633798   0.177743   -1.08403
  0.478877   0.395843  -1.02957    0.645991   -1.37382
 -0.410473   0.871103   0.245303   0.538019   -1.31581
 -0.190147  -1.46851   -0.183525  -0.216322    0.793294
 -0.626786  -2.15311    0.591278   0.0816701   1.23045

julia> Q,R = qr(A)
LinearAlgebra.QRCompactWY{Float64, JLArray{Float64, 2}, JLArray{Float64, 2}}
Q factor: 5×5 LinearAlgebra.QRCompactWYQ{Float64, JLArray{Float64, 2}, JLArray{Float64, 2}}
R factor:
5×5 JLArray{Float64, 2}:
 1.948  2.26845   0.0833889  -0.116918   0.42488
 0.0    2.34746  -0.127072    0.351965  -1.96242
 0.0    0.0       1.37189    -0.366869   1.51315
 0.0    0.0       0.0         0.720891  -0.781938
 0.0    0.0       0.0         0.0       -0.067345

julia> Q * R  A
true

I can look into this issue though. Thanks!

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

No branches or pull requests

2 participants