Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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: 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.

Comment on lines +3 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove all these changes?

This package is part of the Julia standard library (stdlib).

`LinearAlgebra.jl` provides functionality for performing linear algebra operations in Julia.
Expand Down
9 changes: 8 additions & 1 deletion src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1003,19 +1003,26 @@ end

"""
hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian
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
of `A`; it is also sometimes called the "operator real part". The optional argument `uplo` controls the corresponding argument of the
[`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.

Comment on lines +1014 to +1017
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to leave this out, too.

See also [`hermitianpart!`](@ref) for the corresponding in-place operation.

!!! compat "Julia 1.10"
This function requires Julia 1.10 or later.
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

The docstring needs to be attached to the function definition, otherwise Julia doesn't know where it belongs.

hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) = Hermitian(_hermitianpart(A), uplo)
hermitianpart(x::Number) = float(real(x))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hermitianpart(x::Number) = float(real(x))
hermitianpart(x::Number) = real(x)

I believe this will get promoted if necessary by other mechanisms, so there is no need to enforce it per se.


"""
hermitianpart!(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian
Expand Down Expand Up @@ -1052,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
end
end

It's common style to have an empty line at the end. No need to modify this.

10 changes: 10 additions & 0 deletions test/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,16 @@ 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.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
Comment on lines +1041 to +1046
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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
@test hermitianpart(2.5) == 2.5
@test hermitianpart(-1 + 0im) == -1
@test typeof(hermitianpart(3 + 4im)) == 3.0

These type tests wouldn't be needed anymore.

end
end

@testset "Structured display" begin
Expand Down
Loading