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

qr error for matrices with 0 columns #28447

Closed
StephenVavasis opened this issue Aug 4, 2018 · 8 comments
Closed

qr error for matrices with 0 columns #28447

StephenVavasis opened this issue Aug 4, 2018 · 8 comments
Labels

Comments

@StephenVavasis
Copy link
Contributor

Function qr in 0.6 works fine for matrices with 0 columns, but not in 0.7.0-beta2:

julia> F = qr(zeros(4,0))
WARNING: Base.qr is deprecated: it has been moved to the standard library package `LinearAlgebra`.
Add `using LinearAlgebra` to your imports.
 in module Main
LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}}
Q factor:
4×4 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}:
 1.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0
 0.0  0.0  1.0  0.0
 0.0  0.0  0.0  1.0
R factor:
Error showing value of type LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}}:
ERROR: ArgumentError: the requested diagonal, 0, must be at least 1 and at most 1 in an 0-by-0 matrix
@KristofferC
Copy link
Sponsor Member

The computation seems to work, it's just the display that errors?

@StephenVavasis
Copy link
Contributor Author

It's true that not displaying the answer prevents the problem from occurring immediately, but the it still occurs later:

julia> F = qr(zeros(4,0));

julia> R = Matrix(F.R)
ERROR: ArgumentError: the requested diagonal, 0, must be at least 1 and at most 1 in an 0-by-0 matrix
Stacktrace:
 [1] triu!(::Array{Float64,2}, ::Int64) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v0.7\LinearAlgebra\src\dense.jl:175
 [2] triu! at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v0.7\LinearAlgebra\src\generic.jl:237 [inlined]
 [3] getproperty(::LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}}, ::Symbol) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v0.7\LinearAlgebra\src\qr.jl:419
 [4] top-level scope at none:0

@andreasnoack
Copy link
Member

julia> triu!(randn(0,0));
ERROR: ArgumentError: the requested diagonal, 0, must be at least 1 and at most 1 in an 0-by-0 matrix
Stacktrace:
 [1] triu!(::Array{Float64,2}, ::Int64) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/LinearAlgebra/src/dense.jl:175
 [2] triu!(::Array{Float64,2}) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/LinearAlgebra/src/generic.jl:237
 [3] top-level scope at none:0

We added some checks to the triu/l functions to catch potential user errors but so far these checks have mainly been causing problems. I think we should seriously consider to revert the change that introduced the checks.

@garrison garrison added the domain:linear algebra Linear algebra label Aug 5, 2018
@StefanKarpinski
Copy link
Sponsor Member

StefanKarpinski commented Aug 5, 2018

100%. We need to either do the looser bounds or delete the checks altogether. Not super urgent since loosening the bounds can be done at any time, but these bounds checks seem mostly annoying.

@chenxlieee
Copy link

chenxlieee commented Aug 6, 2018

julia> a=[1 2 3; 4 5 6; 7 8 9]
3×3 Array{Int64,2}:
1 2 3
4 5 6
7 8 9

julia> using LinearAlgebra: qr

julia> q,r=qr(a)
LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}}
Q factor:
3×3 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}:
-0.123091 0.904534 0.408248
-0.492366 0.301511 -0.816497
-0.86164 -0.301511 0.408248
R factor:
3×3 Array{Float64,2}:
-8.12404 -9.60114 -11.0782
0.0 0.904534 1.80907
0.0 0.0 -8.88178e-16

julia> q
3×3 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}:
-0.123091 0.904534 0.408248
-0.492366 0.301511 -0.816497
-0.86164 -0.301511 0.408248

julia> r
3×3 Array{Float64,2}:
-8.12404 -9.60114 -11.0782
0.0 0.904534 1.80907
0.0 0.0 -8.88178e-16

It seems the q and r matrices are not compact. Since the rank of "a" is 2, the size of the compact "q" and "r" should be 3 × 2 and 2 × 3, respectively.

@StephenVavasis
Copy link
Contributor Author

With respect to the previous comment, I don't see anything wrong with the output from qr in your posting. Could you say more precisely what is the issue you are raising?

@andreasnoack
Copy link
Member

Fixed by #28480

@StephenVavasis
Copy link
Contributor Author

With respect to the comment from @chenxlieee , plain QR is not suitable for use as a rank estimator. For rank estimation, use either pivoted QR or, for greatest robustness, SVD.

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

No branches or pull requests

6 participants