-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix equality of QRCompactWY #41363
fix equality of QRCompactWY #41363
Conversation
Equality for `QRCompactWY` did not ignore the subdiagonal entries of `T` leading to nondeterministic behavior. Perhaps `T` should be directly stored as `UpperTriangular` in `QRCompactWY`, but that seems potentially breaking. This is pulled out from #41228, since this change should be less controversial than the other changes there and this particular bug just came up in ChainRules again.
Seems unlikely to be breaking. |
stdlib/LinearAlgebra/src/qr.jl
Outdated
@@ -127,6 +127,16 @@ Base.iterate(S::QRCompactWY) = (S.Q, Val(:R)) | |||
Base.iterate(S::QRCompactWY, ::Val{:R}) = (S.R, Val(:done)) | |||
Base.iterate(S::QRCompactWY, ::Val{:done}) = nothing | |||
|
|||
function Base.hash(F::QRCompactWY, h::UInt) | |||
return hash(F.factors, hash(UpperTriangular(F.T), hash(QRCompactWY, h))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct. Generally, the T
matrix will not be square but wide where the number of rows is a block size, see
julia/stdlib/LinearAlgebra/src/qr.jl
Line 249 in 1e3ae23
qr!(A::StridedMatrix{<:BlasFloat}, ::NoPivot; blocksize=36) = |
min(size(A)...)
. For matrices smaller than the block size T
will be square but for larger matrices, it will consist of several triangular blocks side by side, so the hashing here will be slightly more complicated and depend on the block size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see! (Random appreciation for the new sparse matrix printing:
julia> using LinearAlgebra, SparseArrays
julia> a = rand(100, 100);
julia> sparse(qr(a).T .== qr(a).T)
36×100 SparseMatrixCSC{Bool, Int64} with 1767 stored entries:
⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿
⠀⠀⠀⠀⠀⠂⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿
⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⢀⠐⠙⢿⣿⣿⣿⣿
⠀⠀⠐⠀⠀⠀⠀⠀⠀⢀⢙⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠁⠀⡀⠀⠙⢿⣿⣿
⠀⠀⠐⠀⠀⠀⠀⠀⠀⠀⠄⠀⠙⢿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⡀⠀⠀⢀⠀⠀⠙⢿
⠀⡀⠀⠀⠀⠀⠀⠀⠂⠒⠒⠀⠀⠀⠙⢿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⡀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣈⡀⠀⠀⠀⠀⠀⠀⠙⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠂⠀⢀⠀
)
@oxinabox See Andreas' comment. I was misinformed, unfortunately just making |
Equality for `QRCompactWY` did not ignore the subdiagonal entries of `T` leading to nondeterministic behavior. This is pulled out from #41228, since this change should be less controversial than the other changes there and this particular bug just came up in ChainRules again.
* fix equality of QRCompactWY (#41363) Equality for `QRCompactWY` did not ignore the subdiagonal entries of `T` leading to nondeterministic behavior. This is pulled out from #41228, since this change should be less controversial than the other changes there and this particular bug just came up in ChainRules again.
Equality for `QRCompactWY` did not ignore the subdiagonal entries of `T` leading to nondeterministic behavior. This is pulled out from #41228, since this change should be less controversial than the other changes there and this particular bug just came up in ChainRules again. (cherry picked from commit 74fab49)
Equality for `QRCompactWY` did not ignore the subdiagonal entries of `T` leading to nondeterministic behavior. This is pulled out from JuliaLang#41228, since this change should be less controversial than the other changes there and this particular bug just came up in ChainRules again.
* fix equality of QRCompactWY (#41363) Equality for `QRCompactWY` did not ignore the subdiagonal entries of `T` leading to nondeterministic behavior. This is pulled out from #41228, since this change should be less controversial than the other changes there and this particular bug just came up in ChainRules again.
Equality for
QRCompactWY
did not ignore the subdiagonal entries ofT
leading to nondeterministic behavior. PerhapsT
should bedirectly stored as
UpperTriangular
inQRCompactWY
, but that seemspotentially breaking.
This is pulled out from #41228, since this change should be less
controversial than the other changes there and this particular bug just
came up in ChainRules again.