Skip to content
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

Add support to (+)(::UniformScaling) #36784

Merged
merged 4 commits into from
Jul 24, 2020
Merged
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Standard library changes
* New method `LinearAlgebra.issuccess(::CholeskyPivoted)` for checking whether pivoted Cholesky factorization was successful ([#36002]).
* `UniformScaling` can now be indexed into using ranges to return dense matrices and vectors ([#24359]).
* New function `LinearAlgebra.BLAS.get_num_threads()` for getting the number of BLAS threads. ([#36360])
* `(+)(::UniformScaling)` is now defined, making `+I` a valid unary operation. ([#36784])

#### Markdown

Expand Down
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/src/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ isposdef(J::UniformScaling) = isposdef(J.λ)
(-)(J::UniformScaling, x::Number) = J.λ - x
(-)(x::Number, J::UniformScaling) = x - J.λ

(+)(J::UniformScaling) = UniformScaling(+J.λ)
(+)(J1::UniformScaling, J2::UniformScaling) = UniformScaling(J1.λ+J2.λ)
(+)(B::BitArray{2}, J::UniformScaling) = Array(B) + J
(+)(J::UniformScaling, B::BitArray{2}) = J + Array(B)
Expand Down
5 changes: 5 additions & 0 deletions stdlib/LinearAlgebra/test/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ end
@test (α * I) .^ β == UniformScaling(α^β)
end

@testset "unary" begin
@test +I === +1*I
@test -I === -1*I
end

@testset "tr, det and logdet" begin
for T in (Int, Float64, ComplexF64, Bool)
@test tr(UniformScaling(zero(T))) === zero(T)
Expand Down