Skip to content

Commit b4eefd0

Browse files
authored
Default uplo in symmetric/hermitian (#52605)
This makes the function signatures match the respective docstrings, as well as that of `Symmetric/Hermitian`.
1 parent 713560b commit b4eefd0

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
@@ -729,9 +729,9 @@ end
729729
end
730730

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

@@ -902,6 +902,14 @@ end
902902
end
903903
end
904904

905+
@testset "symmetric/hermitian for matrices" begin
906+
A = [1 2; 3 4]
907+
@test LinearAlgebra.symmetric(A) === Symmetric(A)
908+
@test LinearAlgebra.symmetric(A, :L) === Symmetric(A, :L)
909+
@test LinearAlgebra.hermitian(A) === Hermitian(A)
910+
@test LinearAlgebra.hermitian(A, :L) === Hermitian(A, :L)
911+
end
912+
905913
@testset "custom axes" begin
906914
SZA = SizedArrays.SizedArray{(2,2)}([1 2; 3 4])
907915
for T in (Symmetric, Hermitian)

0 commit comments

Comments
 (0)