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 b739018 commit e05b794
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 @@ -371,3 +371,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 @@ -216,3 +216,10 @@ end
@test alltwos != 2I != alltwos # test generic path / inequality off diag
@test rdenseI != I != rdenseI # test square matrix check
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 e05b794

Please sign in to comment.