-
-
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.
Browse files
Browse the repository at this point in the history
* 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.
- Loading branch information
1 parent
c5eceef
commit 4dd3346
Showing
4 changed files
with
102 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,65 @@ | ||
# 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, Val(true)), | ||
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...) | ||
|
||
if f === qr | ||
@test F == G | ||
@test isequal(F, G) | ||
else | ||
@test_broken F == G | ||
@test_broken isequal(F, G) | ||
end | ||
@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 |