241
241
diag (A:: Symmetric ) = symmetric .(diag (parent (A)), sym_uplo (A. uplo))
242
242
diag (A:: Hermitian ) = hermitian .(diag (parent (A)), sym_uplo (A. uplo))
243
243
244
+ isdiag (A:: HermOrSym ) = isdiag (A. uplo == ' U' ? UpperTriangular (A. data) : LowerTriangular (A. data))
245
+
244
246
# For A<:Union{Symmetric,Hermitian}, similar(A[, neweltype]) should yield a matrix with the same
245
247
# symmetry type, uplo flag, and underlying storage type as A. The following methods cover these cases.
246
248
similar (A:: Symmetric , :: Type{T} ) where {T} = Symmetric (similar (parent (A), T), ifelse (A. uplo == ' U' , :U , :L ))
@@ -316,6 +318,7 @@ function fillstored!(A::HermOrSym{T}, x) where T
316
318
return A
317
319
end
318
320
321
+ Base. isreal (A:: HermOrSym{<:Real} ) = true
319
322
function Base. isreal (A:: HermOrSym )
320
323
n = size (A, 1 )
321
324
@inbounds if A. uplo == ' U'
578
581
579
582
function dot (x:: AbstractVector , A:: RealHermSymComplexHerm , y:: AbstractVector )
580
583
require_one_based_indexing (x, y)
581
- (length (x) == length (y) == size (A, 1 )) || throw (DimensionMismatch ())
584
+ n = length (x)
585
+ (n == length (y) == size (A, 1 )) || throw (DimensionMismatch ())
582
586
data = A. data
583
- r = zero (eltype (x)) * zero (eltype (A)) * zero (eltype (y))
587
+ r = dot (zero (eltype (x)), zero (eltype (A)), zero (eltype (y)))
588
+ iszero (n) && return r
584
589
if A. uplo == ' U'
585
590
@inbounds for j = 1 : length (y)
586
591
r += dot (x[j], real (data[j,j]), y[j])
612
617
factorize (A:: HermOrSym ) = _factorize (A)
613
618
function _factorize (A:: HermOrSym{T} ; check:: Bool = true ) where T
614
619
TT = typeof (sqrt (oneunit (T)))
615
- if TT <: BlasFloat
620
+ if isdiag (A)
621
+ return Diagonal (A)
622
+ elseif TT <: BlasFloat
616
623
return bunchkaufman (A; check= check)
617
624
else # fallback
618
625
return lu (A; check= check)
@@ -626,7 +633,7 @@ det(A::Symmetric) = det(_factorize(A; check=false))
626
633
\ (A:: HermOrSym , B:: AbstractVector ) = \ (factorize (A), B)
627
634
# Bunch-Kaufman solves can not utilize BLAS-3 for multiple right hand sides
628
635
# so using LU is faster for AbstractMatrix right hand side
629
- \ (A:: HermOrSym , B:: AbstractMatrix ) = \ (lu (A), B)
636
+ \ (A:: HermOrSym , B:: AbstractMatrix ) = \ (isdiag (A) ? Diagonal (A) : lu (A), B)
630
637
631
638
function _inv (A:: HermOrSym )
632
639
n = checksquare (A)
0 commit comments