Skip to content

Commit

Permalink
Add Diagonal[{T}](S::UniformScaling, n) constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Oct 31, 2017
1 parent 268f878 commit 64e3c08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,7 @@ UniformScaling{Float64}
```
"""
chol(J::UniformScaling, args...) = ((C, info) = _chol!(J, nothing); @assertposdef C info)

## Diagonal construction from UniformScaling
Diagonal{T}(s::UniformScaling, m::Integer) where {T} = Diagonal{T}(fill(T(s.λ), m))
Diagonal(s::UniformScaling, m::Integer) where {T} = Diagonal{eltype(s)}(s, m)
7 changes: 7 additions & 0 deletions test/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,10 @@ end
@test_throws LinAlg.PosDefException chol(-λ*I)
end
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

0 comments on commit 64e3c08

Please sign in to comment.