Skip to content

Commit d79a809

Browse files
ararslanfredrikekre
authored andcommitted
Add Matrix(I, dims) constructor (#438)
1 parent a342f94 commit d79a809

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ Currently, the `@compat` macro supports the following syntaxes:
216216

217217
* Constructors for `Matrix{T}`, `Array{T}`, and `SparseMatrixCSC{T}` from `UniformScaling` ([#24372], [#24657])
218218

219+
* Constructor for `Matrix` from `UniformScaling` ([#24372], [#24657]).
220+
219221
* `Uninitialized` and `uninitialized` with corresponding `Array` constructors ([#24652]).
220222

221223
* `BitArray` constructors for `uninitialized` ([#24785]).

src/Compat.jl

+3
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,9 @@ end
922922
(::Type{Array{T}}){T}(s::UniformScaling, dims::Dims{2}) = Matrix{T}(s, dims)
923923
(::Type{Array{T}}){T}(s::UniformScaling, m::Integer, n::Integer) = Matrix{T}(s, m, n)
924924
end
925+
@static if VERSION < v"0.7.0-DEV.2541"
926+
(::Type{Matrix})(s::UniformScaling{T}, dims...) where {T} = Matrix{T}(s, dims...)
927+
end
925928

926929
# https://github.com/JuliaLang/julia/pull/23271
927930
@static if VERSION < v"0.7.0-DEV.1472"

test/runtests.jl

+3
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,9 @@ let a = [1 0 0; 0 1 0; 0 0 1]
975975
@test SparseMatrixCSC{Float64}(I, (3, 2))::SparseMatrixCSC{Float64,Int} == a[:,1:2]
976976
@test SparseMatrixCSC{Bool,Int16}(I, (3, 3))::SparseMatrixCSC{Bool,Int16} == a
977977
@test SparseMatrixCSC{ComplexF64,Int8}(I, 3, 2)::SparseMatrixCSC{ComplexF64,Int8} == a[:,1:2]
978+
979+
@test Matrix(2I, 3, 3)::Matrix{Int} == Matrix(2I, (3, 3))::Matrix{Int} == 2a
980+
@test Matrix(2.0I, 3, 3)::Matrix{Float64} == Matrix(2.0I, (3, 3))::Matrix{Float64} == 2a
978981
end
979982

980983
# 0.7.0-DEV.2581

0 commit comments

Comments
 (0)