From b4eefd0f8afe91fb8e68c79f1a6615de25005529 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Wed, 27 Dec 2023 12:06:08 +0530 Subject: [PATCH] Default uplo in symmetric/hermitian (#52605) This makes the function signatures match the respective docstrings, as well as that of `Symmetric/Hermitian`. --- stdlib/LinearAlgebra/src/symmetric.jl | 8 ++++---- stdlib/LinearAlgebra/test/symmetric.jl | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/stdlib/LinearAlgebra/src/symmetric.jl b/stdlib/LinearAlgebra/src/symmetric.jl index 23ea72badcbc5..d48274855a001 100644 --- a/stdlib/LinearAlgebra/src/symmetric.jl +++ b/stdlib/LinearAlgebra/src/symmetric.jl @@ -73,8 +73,8 @@ If a symmetric view of a matrix is to be constructed of which the elements are n matrices nor numbers, an appropriate method of `symmetric` has to be implemented. In that case, `symmetric_type` has to be implemented, too. """ -symmetric(A::AbstractMatrix, uplo::Symbol) = Symmetric(A, uplo) -symmetric(A::Number, ::Symbol) = A +symmetric(A::AbstractMatrix, uplo::Symbol=:U) = Symmetric(A, uplo) +symmetric(A::Number, ::Symbol=:U) = A """ 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 matrices nor numbers, an appropriate method of `hermitian` has to be implemented. In that case, `hermitian_type` has to be implemented, too. """ -hermitian(A::AbstractMatrix, uplo::Symbol) = Hermitian(A, uplo) -hermitian(A::Number, ::Symbol) = convert(typeof(A), real(A)) +hermitian(A::AbstractMatrix, uplo::Symbol=:U) = Hermitian(A, uplo) +hermitian(A::Number, ::Symbol=:U) = convert(typeof(A), real(A)) """ hermitian_type(T::Type) diff --git a/stdlib/LinearAlgebra/test/symmetric.jl b/stdlib/LinearAlgebra/test/symmetric.jl index 9d06f2b919481..f7caed17414d9 100644 --- a/stdlib/LinearAlgebra/test/symmetric.jl +++ b/stdlib/LinearAlgebra/test/symmetric.jl @@ -729,9 +729,9 @@ end end @testset "symmetric()/hermitian() for Numbers" begin - @test LinearAlgebra.symmetric(1, :U) == 1 + @test LinearAlgebra.symmetric(1) == LinearAlgebra.symmetric(1, :U) == 1 @test LinearAlgebra.symmetric_type(Int) == Int - @test LinearAlgebra.hermitian(1, :U) == 1 + @test LinearAlgebra.hermitian(1) == LinearAlgebra.hermitian(1, :U) == 1 @test LinearAlgebra.hermitian_type(Int) == Int end @@ -902,6 +902,14 @@ end end end +@testset "symmetric/hermitian for matrices" begin + A = [1 2; 3 4] + @test LinearAlgebra.symmetric(A) === Symmetric(A) + @test LinearAlgebra.symmetric(A, :L) === Symmetric(A, :L) + @test LinearAlgebra.hermitian(A) === Hermitian(A) + @test LinearAlgebra.hermitian(A, :L) === Hermitian(A, :L) +end + @testset "custom axes" begin SZA = SizedArrays.SizedArray{(2,2)}([1 2; 3 4]) for T in (Symmetric, Hermitian)