-
-
Couldn't load subscription status.
- Fork 35
Add hermitianpart method for Number types #1445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ab99211
fbf9475
a2358df
9335758
8bf4fdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||||
| """ | ||||||||
|
|
||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 | ||||||||
|
|
@@ -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 | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It's common style to have an empty line at the end. No need to modify this. |
||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
These type tests wouldn't be needed anymore. |
||||||||||||||||||||
| end | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @testset "Structured display" begin | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
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?