From ab9921165889f268553c1667cf57916fcca98383 Mon Sep 17 00:00:00 2001 From: GianmarcoC Date: Thu, 18 Sep 2025 18:05:45 +0200 Subject: [PATCH 01/12] 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 02/12] 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 ba8cb235f004f870e314252031434f490da44984 Mon Sep 17 00:00:00 2001 From: GianmarcoCuppari Date: Tue, 16 Sep 2025 11:55:36 +0200 Subject: [PATCH 03/12] 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 595dc285b1a9e01ab725b1e736f52fb2e3fc42db Mon Sep 17 00:00:00 2001 From: GianmarcoCuppari Date: Tue, 16 Sep 2025 13:28:04 +0200 Subject: [PATCH 04/12] 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 From 1e62be3617284ccf8a6c9476e3bc8b597b778691 Mon Sep 17 00:00:00 2001 From: GianmarcoC Date: Sun, 2 Nov 2025 14:42:34 +0100 Subject: [PATCH 05/12] Update src/symmetric.jl Co-authored-by: Daniel Karrasch --- src/symmetric.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/symmetric.jl b/src/symmetric.jl index 2a6751b9..80621cf4 100644 --- a/src/symmetric.jl +++ b/src/symmetric.jl @@ -1020,7 +1020,6 @@ 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) = float(real(x)) From 591b86717e289461aab0a33a264d9bd34d737385 Mon Sep 17 00:00:00 2001 From: GianmarcoC Date: Sun, 2 Nov 2025 14:42:45 +0100 Subject: [PATCH 06/12] Update src/symmetric.jl Co-authored-by: Daniel Karrasch --- src/symmetric.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symmetric.jl b/src/symmetric.jl index 80621cf4..ac9485ca 100644 --- a/src/symmetric.jl +++ b/src/symmetric.jl @@ -1021,7 +1021,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) = float(real(x)) +hermitianpart(x::Number) = real(x) """ hermitianpart!(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian From dc7a69eaa17c774f74d0d75ba69ae29076d5d50e Mon Sep 17 00:00:00 2001 From: GianmarcoC Date: Sun, 2 Nov 2025 14:42:53 +0100 Subject: [PATCH 07/12] Update src/symmetric.jl Co-authored-by: Daniel Karrasch --- src/symmetric.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symmetric.jl b/src/symmetric.jl index ac9485ca..6edbedbb 100644 --- a/src/symmetric.jl +++ b/src/symmetric.jl @@ -1058,4 +1058,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 \ No newline at end of file +end From 3370119f0a2c7c7e7c1af26b06606621442fed2e Mon Sep 17 00:00:00 2001 From: GianmarcoC Date: Sun, 2 Nov 2025 14:43:02 +0100 Subject: [PATCH 08/12] Update test/symmetric.jl Co-authored-by: Daniel Karrasch --- test/symmetric.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/symmetric.jl b/test/symmetric.jl index c59e297d..a702dbb8 100644 --- a/test/symmetric.jl +++ b/test/symmetric.jl @@ -1038,12 +1038,9 @@ end @testset "hermitianpart for numbers" begin @test hermitianpart(3 + 4im) == 3 @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)) == 3.0 - @test typeof(hermitianpart(3 + 4im)) == Float64 - @test typeof(hermitianpart(2.5 + 3im)) == Float64 end end From 85c025bdc354cb203332d87159e49e9214344662 Mon Sep 17 00:00:00 2001 From: GianmarcoCuppari Date: Sun, 2 Nov 2025 14:48:50 +0100 Subject: [PATCH 09/12] Apply requested changes --- README.md | 25 ------------------------- src/symmetric.jl | 4 ---- 2 files changed, 29 deletions(-) diff --git a/README.md b/README.md index 47ef85f3..bc04a58a 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,3 @@ -# 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: Coming - -**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. - | **Build Status** | **Coverage** | |:-------------------------------:|:-------------------------------:| [![Build status](https://badge.buildkite.com/4032f509b3a7354c8ce7b34b98c7496d66adc4504b0101cbcf.svg?branch=master)](https://buildkite.com/julialang/linearalgebra-dot-jl) | [![][codecov-img]][codecov-url] | diff --git a/src/symmetric.jl b/src/symmetric.jl index 6edbedbb..fd4b9ada 100644 --- a/src/symmetric.jl +++ b/src/symmetric.jl @@ -1011,10 +1011,6 @@ 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" From 507d0c7646624fba557662b4fa6cda760a98fddc Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Mon, 10 Nov 2025 11:36:53 +0100 Subject: [PATCH 10/12] revert changes to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index bc04a58a..5f10dfe0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +# LinearAlgebra + +This package is part of the Julia standard library (stdlib). + +`LinearAlgebra.jl` provides functionality for performing linear algebra operations in Julia. + | **Build Status** | **Coverage** | |:-------------------------------:|:-------------------------------:| [![Build status](https://badge.buildkite.com/4032f509b3a7354c8ce7b34b98c7496d66adc4504b0101cbcf.svg?branch=master)](https://buildkite.com/julialang/linearalgebra-dot-jl) | [![][codecov-img]][codecov-url] | From 095ce1f644685b1f34bf6702ac107323a4da7806 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Mon, 10 Nov 2025 11:38:31 +0100 Subject: [PATCH 11/12] remove superfluous test --- test/symmetric.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/symmetric.jl b/test/symmetric.jl index a702dbb8..73086476 100644 --- a/test/symmetric.jl +++ b/test/symmetric.jl @@ -1040,7 +1040,6 @@ end @test hermitianpart(5) == 5.0 @test hermitianpart(2.5) == 2.5 @test hermitianpart(-1 + 0im) == -1 - @test typeof(hermitianpart(3 + 4im)) == 3.0 end end From ea354386115c549f204327dcbc461852615f113a Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Mon, 10 Nov 2025 11:41:29 +0100 Subject: [PATCH 12/12] tweak tests slightly --- test/symmetric.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/symmetric.jl b/test/symmetric.jl index 73086476..03529fc0 100644 --- a/test/symmetric.jl +++ b/test/symmetric.jl @@ -1036,11 +1036,11 @@ end @test Aherm.uplo == LinearAlgebra.char_uplo(uplo) end @testset "hermitianpart for numbers" begin - @test hermitianpart(3 + 4im) == 3 - @test hermitianpart(5) == 5.0 - @test hermitianpart(2.5) == 2.5 - @test hermitianpart(-1 + 0im) == -1 -end + @test hermitianpart(3 + 4im) == 3 + @test hermitianpart(5) == 5.0 + @test hermitianpart(2.5 + 4.3im) == 2.5 + @test hermitianpart(-1 + 0im) == -1 + end end @testset "Structured display" begin