-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. (cherry picked from commit 74fab49)
- Loading branch information
1 parent
1bb99ef
commit 5dccb09
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
module TestFactorization | ||
using Test, LinearAlgebra | ||
|
||
@testset "equality for factorizations - $f" for f in Any[ | ||
bunchkaufman, | ||
cholesky, | ||
x -> cholesky(x, Val(true)), | ||
eigen, | ||
hessenberg, | ||
lq, | ||
lu, | ||
qr, | ||
x -> qr(x, ColumnNorm()), | ||
svd, | ||
schur, | ||
] | ||
A = randn(3, 3) | ||
A = A * A' # ensure A is pos. def. and symmetric | ||
F, G = f(A), f(A) | ||
|
||
@test F == G | ||
@test isequal(F, G) | ||
@test hash(F) == hash(G) | ||
|
||
f === hessenberg && continue | ||
|
||
# change all arrays in F to have eltype Float32 | ||
F = typeof(F).name.wrapper(Base.mapany(1:nfields(F)) do i | ||
x = getfield(F, i) | ||
return x isa AbstractArray{Float64} ? Float32.(x) : x | ||
end...) | ||
# round all arrays in G to the nearest Float64 representable as Float32 | ||
G = typeof(G).name.wrapper(Base.mapany(1:nfields(G)) do i | ||
x = getfield(G, i) | ||
return x isa AbstractArray{Float64} ? Float64.(Float32.(x)) : x | ||
end...) | ||
|
||
@test F == G broken=!(f === eigen || f === qr) | ||
@test isequal(F, G) broken=!(f === eigen || f === qr) | ||
@test hash(F) == hash(G) | ||
end | ||
|
||
@testset "equality of QRCompactWY" begin | ||
A = rand(100, 100) | ||
F, G = qr(A), qr(A) | ||
|
||
@test F == G | ||
@test isequal(F, G) | ||
@test hash(F) == hash(G) | ||
|
||
G.T[28, 100] = 42 | ||
|
||
@test F != G | ||
@test !isequal(F, G) | ||
@test hash(F) != hash(G) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ givens | |
structuredbroadcast | ||
addmul | ||
ldlt | ||
factorization |