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

R'xQ' of mxn matrix with m<n not allowed #986

Closed
evelyne-ringoot opened this issue Feb 24, 2023 · 1 comment
Closed

R'xQ' of mxn matrix with m<n not allowed #986

evelyne-ringoot opened this issue Feb 24, 2023 · 1 comment

Comments

@evelyne-ringoot
Copy link

evelyne-ringoot commented Feb 24, 2023

Hi all,

I would like to use the Q and R factors of matrices and their transposes and I'm running into some issues for an mxn matrix m<n.

julia> using LinearAlgebra

julia> m, n = 2, 3;

julia> a=randn(m,n)
2×3 Matrix{Float64}:

julia> b=randn(n,m)
3×2 Matrix{Float64}:

julia> qa,ra=qr(a)
LinearAlgebra.QRCompactWY{Float64, Matrix{Float64}, Matrix{Float64}}
Q factor:
2×2 LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}}:
R factor:
2×3 Matrix{Float64}:
julia> qb,rb=qr(b)
LinearAlgebra.QRCompactWY{Float64, Matrix{Float64}, Matrix{Float64}}
Q factor:
3×3 LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}}:
R factor:
2×2 Matrix{Float64}:

julia> qa*ra
2×3 Matrix{Float64}: # works fine
julia> qb*rb
3×2 Matrix{Float64}:  # works fine

julia> ra'*qa'  # works fine
3×2 Matrix{Float64}:
julia> rb'*qb'  # does not work
ERROR: DimensionMismatch: second dimension of C, 2, and first dimension of V, 3 must match
Stacktrace:
 [1] gemqrt!(side::Char, trans::Char, V::Matrix{Float64}, T::Matrix{Float64}, C::Matrix{Float64})
   @ LinearAlgebra.LAPACK Local\Programs\Julia-1.8.0\share\julia\stdlib\v1.8\LinearAlgebra\src\lapack.jl:2925
 [2] rmul!
   @ Local\Programs\Julia-1.8.0\share\julia\stdlib\v1.8\LinearAlgebra\src\qr.jl:789 [inlined]
 [3] *(adjA::Adjoint{Float64, Matrix{Float64}}, adjQ::Adjoint{Float64, LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}}})
   @ LinearAlgebra Local\Programs\Julia-1.8.0\share\julia\stdlib\v1.8\LinearAlgebra\src\qr.jl:850
 [4] top-level scope
   @ REPL[41]:1

While there is definetly a work-around (manually padding with zeros), I wonder whether it might be worth allowing rb'*qb' in LinearAlgebra Base in the same way as qb*rb?

@dkarrasch
Copy link
Member

This is resolved on current nightly, perhaps since JuliaLang/julia#46196.

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
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

2 participants