-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix some issues with equality of factorizations
- `hash` did not respect the type of a factorization, so completely different factorizations with the same underlying data would result in same `hash` leading to inconsistencies with `isequal`. This likely doesn't occur very often in practice, but definitely seems worth fixing. - `==` and `isequal` only returned true if two factorizations are of exactly the same type, which is inconsistent with their implementation for other objects and with the definition of `hash` for factorizations. - 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. Relying on implementation details of `DataType` here is certainly less than ideal, but I could not come up with a nicer solution.
- Loading branch information
1 parent
4a81b08
commit 642e6e9
Showing
4 changed files
with
72 additions
and
3 deletions.
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,50 @@ | ||
# 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 | ||
|
||
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...) | ||
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 | ||
@test isequal(F, G) | ||
@test hash(F) == hash(G) | ||
end | ||
|
||
@testset "hash collisions" begin | ||
A, v = randn(2, 2), randn(2) | ||
F, G = LQ(A, v), QR(A, v) | ||
@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 |