Skip to content

Commit 1505b07

Browse files
authored
Don't try cholesky for Hermitian in factorize (#54775)
1 parent c8a90cc commit 1505b07

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

stdlib/LinearAlgebra/src/dense.jl

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,15 +1387,14 @@ end
13871387
factorize(A)
13881388
13891389
Compute a convenient factorization of `A`, based upon the type of the input matrix.
1390-
`factorize` checks `A` to see if it is symmetric/triangular/etc. if `A` is passed
1391-
as a generic matrix. `factorize` checks every element of `A` to verify/rule out
1392-
each property. It will short-circuit as soon as it can rule out symmetry/triangular
1393-
structure. The return value can be reused for efficient solving of multiple
1394-
systems. For example: `A=factorize(A); x=A\\b; y=A\\C`.
1390+
If `A` is passed as a generic matrix, `factorize` checks to see if it is
1391+
symmetric/triangular/etc. To this end, `factorize` may check every element of `A` to
1392+
verify/rule out each property. It will short-circuit as soon as it can rule out
1393+
symmetry/triangular structure. The return value can be reused for efficient solving
1394+
of multiple systems. For example: `A=factorize(A); x=A\\b; y=A\\C`.
13951395
13961396
| Properties of `A` | type of factorization |
13971397
|:---------------------------|:-----------------------------------------------|
1398-
| Positive-definite | Cholesky (see [`cholesky`](@ref)) |
13991398
| Dense Symmetric/Hermitian | Bunch-Kaufman (see [`bunchkaufman`](@ref)) |
14001399
| Sparse Symmetric/Hermitian | LDLt (see [`ldlt`](@ref)) |
14011400
| Triangular | Triangular |
@@ -1406,9 +1405,6 @@ systems. For example: `A=factorize(A); x=A\\b; y=A\\C`.
14061405
| General square | LU (see [`lu`](@ref)) |
14071406
| General non-square | QR (see [`qr`](@ref)) |
14081407
1409-
If `factorize` is called on a Hermitian positive-definite matrix, for instance, then `factorize`
1410-
will return a Cholesky factorization.
1411-
14121408
# Examples
14131409
```jldoctest
14141410
julia> A = Array(Bidiagonal(fill(1.0, (5, 5)), :U))
@@ -1427,8 +1423,9 @@ julia> factorize(A) # factorize will check to see that A is already factorized
14271423
⋅ ⋅ ⋅ 1.0 1.0
14281424
⋅ ⋅ ⋅ ⋅ 1.0
14291425
```
1430-
This returns a `5×5 Bidiagonal{Float64}`, which can now be passed to other linear algebra functions
1431-
(e.g. eigensolvers) which will use specialized methods for `Bidiagonal` types.
1426+
1427+
This returns a `5×5 Bidiagonal{Float64}`, which can now be passed to other linear algebra
1428+
functions (e.g. eigensolvers) which will use specialized methods for `Bidiagonal` types.
14321429
"""
14331430
function factorize(A::AbstractMatrix{T}) where T
14341431
m, n = size(A)
@@ -1490,12 +1487,7 @@ function factorize(A::AbstractMatrix{T}) where T
14901487
return UpperTriangular(A)
14911488
end
14921489
if herm
1493-
cf = cholesky(A; check = false)
1494-
if cf.info == 0
1495-
return cf
1496-
else
1497-
return factorize(Hermitian(A))
1498-
end
1490+
return factorize(Hermitian(A))
14991491
end
15001492
if sym
15011493
return factorize(Symmetric(A))

stdlib/LinearAlgebra/test/cholesky.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,15 @@ end
6161

6262
# Test of symmetric pos. def. strided matrix
6363
apd = a'*a
64-
@inferred cholesky(apd)
65-
capd = factorize(apd)
64+
capd = @inferred cholesky(apd)
6665
r = capd.U
6766
κ = cond(apd, 1) #condition number
6867

6968
unary_ops_tests(apd, capd, ε*κ*n)
7069
if eltya != Int
7170
@test Factorization{eltya}(capd) === capd
7271
if eltya <: Real
73-
@test Array(Factorization{complex(eltya)}(capd)) Array(factorize(complex(apd)))
72+
@test Array(Factorization{complex(eltya)}(capd)) Array(cholesky(complex(apd)))
7473
@test eltype(Factorization{complex(eltya)}(capd)) == complex(eltya)
7574
end
7675
end
@@ -358,7 +357,7 @@ end
358357
0.11192755545114 - 0.1603741874112385im 0.8439562576196216 + 1.0850814110398734im
359358
-1.0568488936791578 - 0.06025820467086475im 0.12696236014017806 - 0.09853584666755086im]
360359
cholesky(Hermitian(apd, :L), RowMaximum()) \ b
361-
r = factorize(apd).U
360+
r = cholesky(apd).U
362361
E = abs.(apd - r'*r)
363362
ε = eps(abs(float(one(ComplexF32))))
364363
n = 10

0 commit comments

Comments
 (0)