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

constructors for Array from UniformScaling #24657

Merged
merged 1 commit into from
Nov 20, 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 base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ Matrix{T}(s::UniformScaling, dims::Dims{2}) where {T} = setindex!(zeros(T, dims)
Matrix{T}(s::UniformScaling, m::Integer, n::Integer) where {T} = Matrix{T}(s, Dims((m, n)))
Matrix(s::UniformScaling, m::Integer, n::Integer) = Matrix(s, Dims((m, n)))
Matrix(s::UniformScaling, dims::Dims{2}) = Matrix{eltype(s)}(s, dims)
Array{T}(s::UniformScaling, dims::Dims{2}) where {T} = Matrix{T}(s, dims)
Array{T}(s::UniformScaling, m::Integer, n::Integer) where {T} = Matrix{T}(s, m, n)
Array(s::UniformScaling, m::Integer, n::Integer) = Matrix(s, m, n)
Array(s::UniformScaling, dims::Dims{2}) = Matrix(s, dims)

## Diagonal construction from UniformScaling
Diagonal{T}(s::UniformScaling, m::Integer) where {T} = Diagonal{T}(fill(T(s.λ), m))
Expand Down
16 changes: 9 additions & 7 deletions test/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,18 @@ end
end
end

@testset "Matrix construction from UniformScaling" begin
@testset "Matrix/Array construction from UniformScaling" begin
I2_33 = [2 0 0; 0 2 0; 0 0 2]
I2_34 = [2 0 0 0; 0 2 0 0; 0 0 2 0]
I2_43 = [2 0 0; 0 2 0; 0 0 2; 0 0 0]
@test Matrix(2I, 3, 3)::Matrix{Int} == I2_33
@test Matrix(2I, 3, 4)::Matrix{Int} == I2_34
@test Matrix(2I, 4, 3)::Matrix{Int} == I2_43
@test Matrix(2.0I, 3, 3)::Matrix{Float64} == I2_33
@test Matrix{Real}(2I, 3, 3)::Matrix{Real} == I2_33
@test Matrix{Float64}(2I, 3, 3)::Matrix{Float64} == I2_33
for ArrType in (Matrix, Array)
@test ArrType(2I, 3, 3)::Matrix{Int} == I2_33
@test ArrType(2I, 3, 4)::Matrix{Int} == I2_34
@test ArrType(2I, 4, 3)::Matrix{Int} == I2_43
@test ArrType(2.0I, 3, 3)::Matrix{Float64} == I2_33
@test ArrType{Real}(2I, 3, 3)::Matrix{Real} == I2_33
@test ArrType{Float64}(2I, 3, 3)::Matrix{Float64} == I2_33
end
end

@testset "Diagonal construction from UniformScaling" begin
Expand Down