Skip to content

Commit 5af75df

Browse files
authored
Remove zeroing in similar for Hermitian (#1455)
The comment suggests that the `Hermitian` constructor used to ensure that the parent had a real diagonal. It doesn't anymore, so the explicit fill may be removed.
1 parent 5685390 commit 5af75df

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/symmetric.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,8 @@ isdiag(A::HermOrSym) = applytri(isdiag, A)
330330

331331
# For A<:Union{Symmetric,Hermitian}, similar(A[, neweltype]) should yield a matrix with the same
332332
# symmetry type, uplo flag, and underlying storage type as A. The following methods cover these cases.
333-
similar(A::Symmetric, ::Type{T}) where {T} = Symmetric(similar(parent(A), T), ifelse(A.uplo == 'U', :U, :L))
334-
# If the Hermitian constructor's check ascertaining that the wrapped matrix's
335-
# diagonal is strictly real is removed, the following method can be simplified.
336-
function similar(A::Hermitian, ::Type{T}) where T
337-
B = similar(parent(A), T)
338-
for i in 1:size(B, 1) B[i, i] = 0 end
339-
return Hermitian(B, ifelse(A.uplo == 'U', :U, :L))
340-
end
333+
similar(A::Symmetric, ::Type{T}) where {T} = Symmetric(similar(parent(A), T), sym_uplo(A.uplo))
334+
similar(A::Hermitian, ::Type{T}) where {T} = Hermitian(similar(parent(A), T), sym_uplo(A.uplo))
341335
# On the other hand, similar(A, [neweltype,] shape...) should yield a matrix of the underlying
342336
# storage type of A (not wrapped in a symmetry type). The following method covers these cases.
343337
similar(A::Union{Symmetric,Hermitian}, ::Type{T}, dims::Dims{N}) where {T,N} = similar(parent(A), T, dims)

0 commit comments

Comments
 (0)