JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.4k stars 5.46k forks source link

QR multiplication #26588

Open andreasnoack opened 6 years ago

andreasnoack commented 6 years ago

This is a followup on https://github.com/JuliaLang/julia/pull/26391. As @KlausC points out, it is currently not possible to multiply Q*R for QRSparseQ (in the tall case). For the dense QR factorizations, this is possible because the multiplication methods allow that Q can both be interpreted as thin and square. E.g.

julia> using LinearAlgebra

julia> A = randn(4,2);

julia> F = qrfact(A);

julia> F.Q*Matrix(I, 4, 2)
4×2 Array{Float64,2}:
 -0.687523    0.286761
 -0.544745    0.0838634
  0.0651093  -0.733251
  0.475737    0.610801

julia> F.Q*Matrix(I, 2, 2)
4×2 Array{Float64,2}:
 -0.687523    0.286761
 -0.544745    0.0838634
  0.0651093  -0.733251
  0.475737    0.610801

Multiply Q in Householder form is actually only possible when the right hand side corresponds to a square Q so the special behavior is implemented by zero padding the right hand side.

There are two solutions here. Either we make sparse QR behave like the dense or the opposite. The former is the more complicated solution and I like the simplicity of the latter. People like to reconstruct the input with Q*R which wouldn't be possible if go with the latter. However, reconstructing the input is only useful for teaching and in that case, it might be instructive to require F.Q*Matrix(I, 4, 2)*F.R. Finally, if we decide to stick with dense behavior then we also need to fix R'Q' (as also pointed out by @KlausC).

vini-fda commented 2 years ago

Hello there! This is still an issue. Are there any prospects of defining a standard behavior for the results of the QR factorization?