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

eliminate uses of full from base/linalg/lq.jl #23729

Merged
merged 1 commit into from
Sep 19, 2017

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Sep 16, 2017

Another small step towards deprecation of full. Ref. JuliaLang/LinearAlgebra.jl#229, JuliaLang/LinearAlgebra.jl#231, #18850, and linked threads. Best!

@Sacha0 Sacha0 added the linear algebra Linear algebra label Sep 16, 2017
@Sacha0 Sacha0 added this to the 1.0 milestone Sep 16, 2017
Copy link
Member

@andreasnoack andreasnoack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also wondering if requesting the full matrix from LQPackedQ is a sufficiently common operation to require a separate function.

in the (implicit) input matrix `Q`. That identity matrix is modified by the elementary
reflectors held in `Q`, so this operation does not reduce to simple indexing.
"""
squareQ(Q::LQPackedQ) = A_mul_B!(Q, eye(eltype(Q), reverse(size(Q.factors))...))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not square. Should probably be eye(eltype(Q), size(Q.factors, 2)).

Copy link
Member Author

@Sacha0 Sacha0 Sep 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I failed to read the existing code critically. And agreed, eye(eltype(Q), size(Q.factors, 2)) looks correct. What was the object the existing code returns?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this PR is turning into a significant bug fix. The current version gives

julia> full(lqfact(randn(4,2))[:Q], thin = true)
2×2 Array{Float64,2}:
 -0.759173  0.650889
  0.650889  0.759173

julia> full(lqfact(randn(4,2))[:Q], thin = false)
2×4 Array{Float64,2}:
 -0.652378  -0.757894  0.0  0.0
 -0.757894   0.652378  0.0  0.0

julia> full(lqfact(randn(2,4))[:Q], thin = false)
4×2 Array{Float64,2}:
 -0.22708   -0.390319
  0.72372   -0.204318
 -0.025446   0.888878
 -0.651166  -0.125704

julia> full(lqfact(randn(2,4))[:Q], thin = false)
4×2 Array{Float64,2}:
 -0.0604746   0.111308
  0.822683   -0.406272
 -0.158067   -0.81894
  0.542725    0.389731

so only the first one is correct. Here is how they are supposed to look like

2017-09-18 09 25 21

@Sacha0
Copy link
Member Author

Sacha0 commented Sep 17, 2017

I'm also wondering if requesting the full matrix from LQPackedQ is a sufficiently common operation to require a separate function.

To clarify, are you suggesting squareQ(Q::LQPackedQ) should not exist, or something beyond squareQ(Q::LQPackedQ) should exist? Thanks!

@andreasnoack
Copy link
Member

To clarify, are you suggesting squareQ(Q::LQPackedQ) should not exist

Yes. I'm suggesting that it shouldn't exist. I think it is pretty rare that you actually want to do that. If you, for instructional purposes, want to work with the full Q you would probably call qr instead of qrfact in the first place. We could also mention in the documentation that the dense Q can be computed from a package Q via multiplication with eye. It is very simple and also instructive since it would be how we'd compute Q anyway.

@Sacha0
Copy link
Member Author

Sacha0 commented Sep 18, 2017

Yes. I'm suggesting that it shouldn't exist. I think it is pretty rare that you actually want to do that. If you, for instructional purposes, want to work with the full Q you would probably call qr instead of qrfact in the first place. We could also mention in the documentation that the dense Q can be computed from a package Q via multiplication with eye. It is very simple and also instructive since it would be how we'd compute Q anyway.

Sounds good on this end :).

@Sacha0
Copy link
Member Author

Sacha0 commented Sep 19, 2017

Revised. Thoughts? Thanks! :)

@kshyatt
Copy link
Contributor

kshyatt commented Sep 19, 2017

@andreasnoack as the author of that function, I included it for consistency with qr.jl but have no particular attachment to it otherwise.

@andreasnoack andreasnoack merged commit 417331c into JuliaLang:master Sep 19, 2017
@Sacha0 Sacha0 deleted the nixlqfull branch September 19, 2017 18:44
@Sacha0
Copy link
Member Author

Sacha0 commented Sep 19, 2017

Thanks all! :)

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

Successfully merging this pull request may close these issues.

3 participants