From 04c1b13eb577a72416dc1c0f795206041eba58ab Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Fri, 4 Oct 2019 21:19:46 +0200 Subject: [PATCH] Drop compat code for `Array` c'tors from `UniformScaling` from #412 and #438 --- README.md | 4 ---- src/Compat.jl | 27 --------------------------- test/old.jl | 15 +++++++++++++++ test/runtests.jl | 15 --------------- 4 files changed, 15 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 4eb91cf55..a7cc71dbf 100644 --- a/README.md +++ b/README.md @@ -81,10 +81,6 @@ Currently, the `@compat` macro supports the following syntaxes: * `isnothing` for testing if a variable is equal to `nothing` ([#29674]). -* Constructors for `Matrix{T}`, `Array{T}`, and `SparseMatrixCSC{T}` from `UniformScaling` ([#24372], [#24657]) - -* Constructor for `Matrix` from `UniformScaling` ([#24372], [#24657]). - * `UndefInitializer` and `undef` with corresponding `Array` constructors ([#24652], [#26316]). * `BitArray` constructors for `undef` ([#24785], [#26316]). diff --git a/src/Compat.jl b/src/Compat.jl index c0ced1f5d..e17fccaf3 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -37,33 +37,6 @@ import Base64 include("compatmacro.jl") -@static if VERSION < v"0.7.0-DEV.2377" - (::Type{Matrix{T}}){T}(s::UniformScaling, dims::Dims{2}) = setindex!(zeros(T, dims), T(s.λ), diagind(dims...)) - (::Type{Matrix{T}}){T}(s::UniformScaling, m::Integer, n::Integer) = Matrix{T}(s, Dims((m, n))) - - (::Type{SparseMatrixCSC{Tv,Ti}}){Tv,Ti}(s::UniformScaling, m::Integer, n::Integer) = SparseMatrixCSC{Tv,Ti}(s, Dims((m, n))) - (::Type{SparseMatrixCSC{Tv}}){Tv}(s::UniformScaling, m::Integer, n::Integer) = SparseMatrixCSC{Tv}(s, Dims((m, n))) - (::Type{SparseMatrixCSC{Tv}}){Tv}(s::UniformScaling, dims::Dims{2}) = SparseMatrixCSC{Tv,Int}(s, dims) - function (::Type{SparseMatrixCSC{Tv,Ti}}){Tv,Ti}(s::UniformScaling, dims::Dims{2}) - @boundscheck first(dims) < 0 && throw(ArgumentError("first dimension invalid ($(first(dims)) < 0)")) - @boundscheck last(dims) < 0 && throw(ArgumentError("second dimension invalid ($(last(dims)) < 0)")) - iszero(s.λ) && return spzeros(Tv, Ti, dims...) - m, n, k = dims..., min(dims...) - nzval = fill!(Vector{Tv}(k), Tv(s.λ)) - rowval = copy!(Vector{Ti}(k), 1:k) - colptr = copy!(Vector{Ti}(n + 1), 1:(k + 1)) - for i in (k + 2):(n + 1) colptr[i] = (k + 1) end - SparseMatrixCSC{Tv,Ti}(dims..., colptr, rowval, nzval) - end -end -@static if VERSION < v"0.7.0-DEV.2543" - (::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" Base.IOContext(io::IO, arg1::Pair, arg2::Pair, args::Pair...) = IOContext(IOContext(io, arg1), arg2, args...) diff --git a/test/old.jl b/test/old.jl index 289c29cf4..ef302effd 100644 --- a/test/old.jl +++ b/test/old.jl @@ -501,3 +501,18 @@ end @test diagm(0 => ones(2), 1 => ones(2)) == [1.0 1.0 0.0; 0.0 1.0 1.0; 0.0 0.0 0.0] @test spdiagm(0 => ones(2), -1 => ones(2)) == [1.0 0.0 0.0; 1.0 1.0 0.0; 0.0 1.0 0.0] @test spdiagm(0 => ones(2), 1 => ones(2)) == [1.0 1.0 0.0; 0.0 1.0 1.0; 0.0 0.0 0.0] + +# 0.7 +let a = [1 0 0; 0 1 0; 0 0 1] + @test Matrix{Int}(I, 3, 3)::Matrix{Int} == a + @test Matrix{Float64}(I, (3, 2))::Matrix{Float64} == a[:,1:2] + @test Array{Int}(I, (3, 3))::Matrix{Int} == a + @test Array{Float64}(I, 3, 2)::Matrix{Float64} == a[:,1:2] + @test SparseMatrixCSC{Int}(I, 3, 3)::SparseMatrixCSC{Int,Int} == a + @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 diff --git a/test/runtests.jl b/test/runtests.jl index d0768fb0d..fba575e1a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -76,21 +76,6 @@ end @test textwidth("A") == 1 @test textwidth('A') == 1 -# 0.7 -let a = [1 0 0; 0 1 0; 0 0 1] - @test Matrix{Int}(I, 3, 3)::Matrix{Int} == a - @test Matrix{Float64}(I, (3, 2))::Matrix{Float64} == a[:,1:2] - @test Array{Int}(I, (3, 3))::Matrix{Int} == a - @test Array{Float64}(I, 3, 2)::Matrix{Float64} == a[:,1:2] - @test SparseMatrixCSC{Int}(I, 3, 3)::SparseMatrixCSC{Int,Int} == a - @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, 0.7.0-DEV.4527 @test isa(Vector(undef, 2), Vector{Any}) @test isa(Vector{Float64}(undef, 2), Vector{Float64})