Skip to content

Commit

Permalink
Drop compat code for diagm and spdiagm` with pairs from #408
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Oct 4, 2019
1 parent ec74f44 commit 5a591cc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 35 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* `isnothing` for testing if a variable is equal to `nothing` ([#29674]).

* `diagm` and `spdiagm` accept pairs mapping diagonals to vectors ([#24047], [#23757])

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

* Constructor for `Matrix` from `UniformScaling` ([#24372], [#24657]).
Expand Down
27 changes: 0 additions & 27 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,6 @@ import Base: Fix2

include("compatmacro.jl")

# 0.7.0-DEV.2116
@static if VERSION < v"0.7.0-DEV.2116"
import Compat.SparseArrays: spdiagm
function spdiagm(kv::Pair...)
I, J, V = Compat.SparseArrays.spdiagm_internal(last.(kv), first.(kv))
m = max(Compat.SparseArrays.dimlub(I), Compat.SparseArrays.dimlub(J))
return sparse(I, J, V, m, m)
end
end

# 0.7.0-DEV.2161
@static if VERSION < v"0.7.0-DEV.2161"
import Base: diagm
function diagm(kv::Pair...)
T = promote_type(map(x -> eltype(x.second), kv)...)
n = Base.mapreduce(x -> length(x.second) + abs(x.first), max, kv)
A = zeros(T, n, n)
for p in kv
inds = diagind(A, p.first)
for (i, val) in enumerate(p.second)
A[inds[i]] += val
end
end
return A
end
end

# 0.7.0-DEV.2338
@static if VERSION >= v"0.7.0-DEV.2338"
import Base64
Expand Down
6 changes: 6 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,9 @@ end

# 0.7
@test 1 in BitSet(1:10)

# 0.7
@test diagm(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 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]
6 changes: 0 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ end
@test textwidth("A") == 1
@test textwidth('A') == 1

# 0.7
@test diagm(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 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
Expand Down

0 comments on commit 5a591cc

Please sign in to comment.