Skip to content

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

Closed
@evelyne-ringoot

Description

@evelyne-ringoot

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions