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

Undeprecate +/- for UniformScaling and Number #23923

Merged
merged 1 commit into from
Oct 2, 2017
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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ Language changes
of the `:quote` expression head (though `:quote` `Expr`s are still used for quoted
expressions) ([#23885]).

* The `+` and `-` methods for `Number` and `UniformScaling` are not ambiguous anymore since `+`
and `-` no longer do automatic broadcasting. Hence the methods for `UniformScaling` and `Number` are
no longer deprecated ([#23923]).

Breaking changes
----------------

Expand Down
5 changes: 0 additions & 5 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ function delete!(::EnvHash, k::AbstractString, def)
haskey(ENV,k) ? delete!(ENV,k) : def
end

@deprecate (+)(J::UniformScaling, x::Number) J.λ + x
@deprecate (+)(x::Number, J::UniformScaling) x + J.λ
@deprecate (-)(J::UniformScaling, x::Number) J.λ - x
@deprecate (-)(x::Number, J::UniformScaling) x - J.λ

# Deprecate methods that convert Diagonal and Bidiagonal to <:AbstractTriangular.
function convert(::Type{UpperTriangular}, A::Diagonal)
depwarn(string("`convert(::Type{UpperTriangular}, A::Diagonal)` and other methods ",
Expand Down
5 changes: 5 additions & 0 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ istril(::UniformScaling) = true
issymmetric(::UniformScaling) = true
ishermitian(J::UniformScaling) = isreal(J.λ)

(+)(J::UniformScaling, x::Number) = J.λ + x
(+)(x::Number, J::UniformScaling) = x + J.λ
(-)(J::UniformScaling, x::Number) = J.λ - x
(-)(x::Number, J::UniformScaling) = x - 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
8 changes: 7 additions & 1 deletion test/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ end
@test UniformScaling(4.32) ≉ 4.3*ones(2,2) rtol=0.1 atol=0.01
end

@testset "* and / with number" begin
@testset "arithmetic with Number" begin
α = randn()
@test α + I == α + 1
@test I + α == α + 1
@test α - I == α - 1
@test I - α == 1 - α
@test α .* UniformScaling(1.0) == UniformScaling(1.0) .* α
@test UniformScaling(α)./α == UniformScaling(1.0)
@test α * UniformScaling(1.0) == UniformScaling(1.0) * α
@test UniformScaling(α)/α == UniformScaling(1.0)
end

@testset "det and logdet" begin
Expand Down