Skip to content

Commit f371de8

Browse files
jishnubKristofferC
authored andcommitted
Default uplo in symmetric/hermitian (#52605)
This makes the function signatures match the respective docstrings, as well as that of `Symmetric/Hermitian`. (cherry picked from commit b4eefd0)
1 parent e0e3c63 commit f371de8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

stdlib/LinearAlgebra/src/symmetric.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ If a symmetric view of a matrix is to be constructed of which the elements are n
7373
matrices nor numbers, an appropriate method of `symmetric` has to be implemented. In that
7474
case, `symmetric_type` has to be implemented, too.
7575
"""
76-
symmetric(A::AbstractMatrix, uplo::Symbol) = Symmetric(A, uplo)
77-
symmetric(A::Number, ::Symbol) = A
76+
symmetric(A::AbstractMatrix, uplo::Symbol=:U) = Symmetric(A, uplo)
77+
symmetric(A::Number, ::Symbol=:U) = A
7878

7979
"""
8080
symmetric_type(T::Type)
@@ -164,8 +164,8 @@ If a hermitian view of a matrix is to be constructed of which the elements are n
164164
matrices nor numbers, an appropriate method of `hermitian` has to be implemented. In that
165165
case, `hermitian_type` has to be implemented, too.
166166
"""
167-
hermitian(A::AbstractMatrix, uplo::Symbol) = Hermitian(A, uplo)
168-
hermitian(A::Number, ::Symbol) = convert(typeof(A), real(A))
167+
hermitian(A::AbstractMatrix, uplo::Symbol=:U) = Hermitian(A, uplo)
168+
hermitian(A::Number, ::Symbol=:U) = convert(typeof(A), real(A))
169169

170170
"""
171171
hermitian_type(T::Type)

stdlib/LinearAlgebra/test/symmetric.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,9 @@ end
727727
end
728728

729729
@testset "symmetric()/hermitian() for Numbers" begin
730-
@test LinearAlgebra.symmetric(1, :U) == 1
730+
@test LinearAlgebra.symmetric(1) == LinearAlgebra.symmetric(1, :U) == 1
731731
@test LinearAlgebra.symmetric_type(Int) == Int
732-
@test LinearAlgebra.hermitian(1, :U) == 1
732+
@test LinearAlgebra.hermitian(1) == LinearAlgebra.hermitian(1, :U) == 1
733733
@test LinearAlgebra.hermitian_type(Int) == Int
734734
end
735735

@@ -900,4 +900,12 @@ end
900900
end
901901
end
902902

903+
@testset "symmetric/hermitian for matrices" begin
904+
A = [1 2; 3 4]
905+
@test LinearAlgebra.symmetric(A) === Symmetric(A)
906+
@test LinearAlgebra.symmetric(A, :L) === Symmetric(A, :L)
907+
@test LinearAlgebra.hermitian(A) === Hermitian(A)
908+
@test LinearAlgebra.hermitian(A, :L) === Hermitian(A, :L)
909+
end
910+
903911
end # module TestSymmetric

0 commit comments

Comments
 (0)