Skip to content

Commit

Permalink
Add (sp)diagm pair constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Nov 7, 2017
1 parent 5bd5e8c commit 1615b51
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `*(::Union{Char,AbstractString},::Union{Char,AbstractString})` concatenation. ([#22512])

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

## Renaming


Expand Down Expand Up @@ -343,7 +345,9 @@ includes this fix. Find the minimum version from there.
[#23427]: https://github.com/JuliaLang/julia/issues/23427
[#23570]: https://github.com/JuliaLang/julia/issues/23570
[#23666]: https://github.com/JuliaLang/julia/issues/23666
[#23757]: https://github.com/JuliaLang/julia/issues/23757
[#23812]: https://github.com/JuliaLang/julia/issues/23812
[#23931]: https://github.com/JuliaLang/julia/issues/23931
[#24047]: https://github.com/JuliaLang/julia/issues/24047
[#24282]: https://github.com/JuliaLang/julia/issues/24282
[#22512]: https://github.com/JuliaLang/julia/issues/22532
28 changes: 28 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,34 @@ end
export BitSet
end

# 0.7.0-DEV.2116
@static if VERSION < v"0.7.0-DEV.2116"
import Base.spdiagm
if VERSION >= v"0.6.0"
include_string(@__MODULE__, """
spdiagm(kv::Pair{<:Integer,<:AbstractArray}...) = spdiagm(last.(kv), first.(kv))
""")
else
include_string(@__MODULE__, """
spdiagm{I<:Integer,A<:AbstractArray}(kv::Pair{I,A}...) = spdiagm(last.(kv), first.(kv))
""")
end
end

# 0.7.0-DEV.2161
@static if VERSION < v"0.7.0-DEV.2161"
import Base.diagm
if VERSION >= v"0.6.0"
include_string(@__MODULE__, """
diagm(kv::Pair{<:Integer,<:AbstractArray}...) = diagm(last.(kv), first.(kv))
""")
else
include_string(@__MODULE__, """
diagm{I<:Integer,A<:AbstractArray}(kv::Pair{I,A}...) = spdiag(last.(kv), first.(kv))
""")
end
end

include("deprecated.jl")

end # module Compat
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,12 @@ 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]

if VERSION < v"0.6.0"
include("deprecated.jl")
end
Expand Down

0 comments on commit 1615b51

Please sign in to comment.