From ab9921165889f268553c1667cf57916fcca98383 Mon Sep 17 00:00:00 2001 From: GianmarcoC Date: Thu, 18 Sep 2025 18:05:45 +0200 Subject: [PATCH 1/4] Update README.md --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 5f10dfe0..0a6b4359 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,24 @@ # LinearAlgebra +--- +## 🚀 About this fork + +This is my fork of LinearAlgebra.jl for contributing to Julia as part of my GSoC 2026 preparation. + +**My contributions:** +- [PR #1445](https://github.com/JuliaLang/LinearAlgebra.jl/pull/1445) - Add hermitianpart method for Number types +- Active in issues: [Inserisci numeri issue quando ne commenti alcuni] + +**Original repository:** [JuliaLang/LinearAlgebra.jl](https://github.com/JuliaLang/LinearAlgebra.jl) + +--- + +# LinearAlgebra + +This package is part of the Julia standard library (stdlib). + +LinearAlgebra.jl provides functionality for performing linear algebra operations in Julia. + This package is part of the Julia standard library (stdlib). `LinearAlgebra.jl` provides functionality for performing linear algebra operations in Julia. From fbf947563280c155339f559d19414ee8ba9b0526 Mon Sep 17 00:00:00 2001 From: GianmarcoC Date: Thu, 18 Sep 2025 18:06:04 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a6b4359..47ef85f3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This is my fork of LinearAlgebra.jl for contributing to Julia as part of my GSoC **My contributions:** - [PR #1445](https://github.com/JuliaLang/LinearAlgebra.jl/pull/1445) - Add hermitianpart method for Number types -- Active in issues: [Inserisci numeri issue quando ne commenti alcuni] +- Active in issues: Coming **Original repository:** [JuliaLang/LinearAlgebra.jl](https://github.com/JuliaLang/LinearAlgebra.jl) From 93357580a3089550086aa36e04aaf511d72e1971 Mon Sep 17 00:00:00 2001 From: GianmarcoCuppari Date: Tue, 16 Sep 2025 11:55:36 +0200 Subject: [PATCH 3/4] Add hermitianpart method for Number types --- src/symmetric.jl | 2 ++ test/symmetric.jl | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/symmetric.jl b/src/symmetric.jl index 50f34022..df8916fd 100644 --- a/src/symmetric.jl +++ b/src/symmetric.jl @@ -1003,6 +1003,7 @@ end """ hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian + hermitianpart(x::Number) -> Real Return the Hermitian part of the square matrix `A`, defined as `(A + A') / 2`, as a [`Hermitian`](@ref) matrix. For real matrices `A`, this is also known as the symmetric part @@ -1016,6 +1017,7 @@ See also [`hermitianpart!`](@ref) for the corresponding in-place operation. This function requires Julia 1.10 or later. """ hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) = Hermitian(_hermitianpart(A), uplo) +hermitianpart(x::Number) = real(x) """ hermitianpart!(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian diff --git a/test/symmetric.jl b/test/symmetric.jl index 031dac27..ca130a3b 100644 --- a/test/symmetric.jl +++ b/test/symmetric.jl @@ -1035,6 +1035,14 @@ end @test Aherm isa Hermitian @test Aherm.uplo == LinearAlgebra.char_uplo(uplo) end + @testset "hermitianpart for numbers" begin + @test hermitianpart(3 + 4im) == 3 + @test hermitianpart(5) == 5 + @test hermitianpart(2.5) == 2.5 + @test hermitianpart(-1 + 0im) == -1 + @test typeof(hermitianpart(3 + 4im)) == Int + @test typeof(hermitianpart(2.5 + 3im)) == Float64 +end end @testset "Structured display" begin From 8bf4fdc5240abff4076869ba91703b5abdb857a3 Mon Sep 17 00:00:00 2001 From: GianmarcoCuppari Date: Tue, 16 Sep 2025 13:28:04 +0200 Subject: [PATCH 4/4] Apply suggestion to return Float64 for scalars; update docstring and tests accordingly --- src/symmetric.jl | 11 ++++++++--- test/symmetric.jl | 6 ++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/symmetric.jl b/src/symmetric.jl index df8916fd..2a6751b9 100644 --- a/src/symmetric.jl +++ b/src/symmetric.jl @@ -1003,7 +1003,7 @@ end """ hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian - hermitianpart(x::Number) -> Real + hermitianpart(x::Number) -> Number Return the Hermitian part of the square matrix `A`, defined as `(A + A') / 2`, as a [`Hermitian`](@ref) matrix. For real matrices `A`, this is also known as the symmetric part @@ -1011,13 +1011,18 @@ of `A`; it is also sometimes called the "operator real part". The optional argum [`Hermitian`](@ref) view. For real matrices, the latter is equivalent to a [`Symmetric`](@ref) view. +For scalar inputs `x`, the function returns the real part of `x`. Standard integer scalars +are promoted to `Float64` to align with the behavior of 1×1 Hermitian matrices, while other numeric types +(`Float32`, `BigInt`, `Rational`, `BigFloat`) are preserved. + See also [`hermitianpart!`](@ref) for the corresponding in-place operation. !!! compat "Julia 1.10" This function requires Julia 1.10 or later. """ + hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) = Hermitian(_hermitianpart(A), uplo) -hermitianpart(x::Number) = real(x) +hermitianpart(x::Number) = float(real(x)) """ hermitianpart!(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian @@ -1054,4 +1059,4 @@ function Base.replace_in_print_matrix(A::HermOrSym,i::Integer,j::Integer,s::Abst ijminmax = minmax(i, j) inds = A.uplo == 'U' ? ijminmax : reverse(ijminmax) Base.replace_in_print_matrix(parent(A), inds..., s) -end +end \ No newline at end of file diff --git a/test/symmetric.jl b/test/symmetric.jl index ca130a3b..c59e297d 100644 --- a/test/symmetric.jl +++ b/test/symmetric.jl @@ -1037,10 +1037,12 @@ end end @testset "hermitianpart for numbers" begin @test hermitianpart(3 + 4im) == 3 - @test hermitianpart(5) == 5 + @test hermitianpart(5) == 5.0 + @test typeof(hermitianpart(5)) == Float64 @test hermitianpart(2.5) == 2.5 @test hermitianpart(-1 + 0im) == -1 - @test typeof(hermitianpart(3 + 4im)) == Int + @test typeof(hermitianpart(3 + 4im)) == 3.0 + @test typeof(hermitianpart(3 + 4im)) == Float64 @test typeof(hermitianpart(2.5 + 3im)) == Float64 end end