Skip to content

Commit

Permalink
Merge pull request #24415 from Sacha0/eyediagonal
Browse files Browse the repository at this point in the history
deprecate eye(::Type{Diagonal{T}}, n), introduce Diagonal[{T}](s::UniformScaling, n)
  • Loading branch information
Sacha0 authored Nov 1, 2017
2 parents b6a2394 + 3fa96bd commit adc97b7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ Library improvements

* The `crc32c` function for CRC-32c checksums is now exported ([#22274]).

* `eye(::Type{Diagonal{T}}, m::Integer)` has been deprecated in favor of
`Diagonal{T}(I, m)` ([#24413]).

* The output of `versioninfo` is now controlled with keyword arguments ([#21974]).

* The function `LibGit2.set_remote_url` now always sets both the fetch and push URLs for a
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,8 @@ end
@deprecate get_creds!(cache::CachedCredentials, credid, default) get!(cache, credid, default)
end

@deprecate eye(::Type{Diagonal{T}}, n::Int) where {T} Diagonal{T}(I, n)

export tic, toq, toc
function tic()
depwarn("tic() is deprecated, use @time, @elapsed, or calls to time_ns() instead.", :tic)
Expand Down
2 changes: 0 additions & 2 deletions base/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ function logdet(D::Diagonal{<:Complex}) # make sure branch cut is correct
z = sum(log, D.diag)
complex(real(z), rem2pi(imag(z), RoundNearest))
end
# identity matrices via eye(Diagonal{type},n)
eye(::Type{Diagonal{T}}, n::Int) where {T} = Diagonal(ones(T,n))

# Matrix functions
for f in (:exp, :log, :sqrt,
Expand Down
4 changes: 4 additions & 0 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,7 @@ Matrix(s::UniformScaling, dims::Dims{2}) = Matrix{eltype(s)}(s, dims)
# convenience variations that accept a single integer to specify dims
Matrix{T}(s::UniformScaling, m::Integer) where {T} = Matrix{T}(s, m, m)
Matrix(s::UniformScaling, m::Integer) = Matrix(s, m, m)

## Diagonal construction from UniformScaling
Diagonal{T}(s::UniformScaling, m::Integer) where {T} = Diagonal{T}(fill(T(s.λ), m))
Diagonal(s::UniformScaling, m::Integer) = Diagonal{eltype(s)}(s, m)
1 change: 0 additions & 1 deletion test/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ srand(1)
end

@testset "Basic properties" begin
@test eye(Diagonal{elty},n) == Diagonal(ones(elty,n))
@test_throws ArgumentError size(D,0)
@test typeof(convert(Diagonal{Complex64},D)) <: Diagonal{Complex64}
@test typeof(convert(AbstractMatrix{Complex64},D)) <: Diagonal{Complex64}
Expand Down
7 changes: 7 additions & 0 deletions test/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ end
@test Matrix{Float64}(2I, 3, 3)::Matrix{Float64} == 2*eye(3)
end

@testset "Diagonal construction from UniformScaling" begin
@test Diagonal(2I, 3)::Diagonal{Int} == 2*eye(3)
@test Diagonal(2.0I, 3)::Diagonal{Float64} == 2*eye(3)
@test Diagonal{Real}(2I, 3)::Diagonal{Real} == 2*eye(3)
@test Diagonal{Float64}(2I, 3)::Diagonal{Float64} == 2*eye(3)
end

@testset "equality comparison of matrices with UniformScaling" begin
# AbstractMatrix methods
diagI = Diagonal(fill(1, 3))
Expand Down

0 comments on commit adc97b7

Please sign in to comment.