Skip to content

Commit

Permalink
Add support to (+)(::UniformScaling) (#36784)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisbr authored Jul 24, 2020
1 parent ad804f5 commit 3dc49ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
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

0 comments on commit 3dc49ca

Please sign in to comment.