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

deprecate eye(::Type{Diagonal{T}}, n), introduce Diagonal[{T}](s::UniformScaling, n) #24415

Merged
merged 2 commits into from
Nov 1, 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
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 @@ -1786,6 +1786,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 @@ -341,8 +341,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