From 980b45f408d3488a52035aab289ff8e6c52ea994 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Wed, 27 Dec 2017 12:55:18 -0800 Subject: [PATCH] Add Matrix(I, dims) constructor --- README.md | 2 ++ src/Compat.jl | 4 ++++ test/runtests.jl | 4 ++++ 3 files changed, 10 insertions(+) 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..a1703ce99 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1310,6 +1310,10 @@ end export parentmodule end +@static if VERSION < v"0.7.0-DEV.2541" + (::Type{Matrix}){T}(I::UniformScaling{T}, dims...) = eye(T, dims...) +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 9cf0dbc25..7fd3b4aff 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1168,6 +1168,10 @@ end # 0.7.0-DEV.3415 @test findall(x -> x==1, [1, 2, 3, 2, 1]) == [1, 5] +# 0.7.0-DEV.2541 +@test Matrix(I, 2, 2) == [1 0; 0 1] +@test eltype(Matrix(1.0I, 3, 3)) == Float64 + if VERSION < v"0.6.0" include("deprecated.jl") end