diff --git a/README.md b/README.md index a588f80fa..c8b1474ee 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,8 @@ Currently, the `@compat` macro supports the following syntaxes: * Constructors for `Matrix{T}`, `Array{T}`, and `SparseMatrixCSC{T}` from `UniformScaling` ([#24372], [#24657]) +* Constructor for `Matrix` from `UniformScaling` ([#24372], [#24657]). + * `Uninitialized` and `uninitialized` with corresponding `Array` constructors ([#24652]). * `BitArray` constructors for `uninitialized` ([#24785]). diff --git a/src/Compat.jl b/src/Compat.jl index 4cf974ea8..72ed35f6e 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -922,6 +922,9 @@ end (::Type{Array{T}}){T}(s::UniformScaling, dims::Dims{2}) = Matrix{T}(s, dims) (::Type{Array{T}}){T}(s::UniformScaling, m::Integer, n::Integer) = Matrix{T}(s, m, n) end +@static if VERSION < v"0.7.0-DEV.2541" + (::Type{Matrix})(s::UniformScaling{T}, dims...) where {T} = Matrix{T}(s, dims...) +end # https://github.com/JuliaLang/julia/pull/23271 @static if VERSION < v"0.7.0-DEV.1472" diff --git a/test/runtests.jl b/test/runtests.jl index 9cf0dbc25..25c28cc0e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -975,6 +975,9 @@ let a = [1 0 0; 0 1 0; 0 0 1] @test SparseMatrixCSC{Float64}(I, (3, 2))::SparseMatrixCSC{Float64,Int} == a[:,1:2] @test SparseMatrixCSC{Bool,Int16}(I, (3, 3))::SparseMatrixCSC{Bool,Int16} == a @test SparseMatrixCSC{ComplexF64,Int8}(I, 3, 2)::SparseMatrixCSC{ComplexF64,Int8} == a[:,1:2] + + @test Matrix(2I, 3, 3)::Matrix{Int} == Matrix(2I, (3, 3))::Matrix{Int} == 2a + @test Matrix(2.0I, 3, 3)::Matrix{Float64} == Matrix(2.0I, (3, 3))::Matrix{Float64} == 2a end # 0.7.0-DEV.2581