Skip to content

Commit

Permalink
Multiple 0.7 compat def
Browse files Browse the repository at this point in the history
* Third argument for `Base.rtoldefault`
* `select`* renaming
* `ctranspose`* renaming
* Math constant module and renaming
* `isleaftype` renaming
  • Loading branch information
yuyichao committed Sep 15, 2017
1 parent 209fdc4 commit 40353d7
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 1 deletion.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ Currently, the `@compat` macro supports the following syntaxes:

* `retry` for the more flexible `retry` method introduced in 0.6 which includes support for kwargs ([#19331], [#21419]).

## Renamed functions and types
* `Base.rtoldefault` how takes a third parameter `atol`.
The two argument form is deprecated in favor of the three arguments form with `atol=0`.

* The `corrected` optional argument of `cov` becomes a keyword argument.
Due to conflict with 0.5 deprecation,
`cov(::AbstractVector; corrected=)` and `cov(::AbstractVector, ::AbstractVector; corrected=)`
are only available on 0.6. ([#21709])

## Renaming


* `$` is now `xor` or `` ([#18977])
Expand All @@ -184,6 +192,17 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Range` is now `AbstractRange` ([#23570])

* `select`* functions (`select`, `select!`, `selectperm`, `selectperm!`) are renamed to
`partialsort`* (`partialsort`, `partialsort!`, `partialsortperm`, `partialsortperm!`) ([#23051])

* `ctranspose` and `ctranspose!` are now `adjoint` and `adjoint!` ([#23235])

* Math constants (`π`, `pi`, `e`, `γ`, `eulergamma`, `catalan`, `φ`, `golden`) are moved to the
`MathConstants` module (available as `Compat.MathConstants`).
The name exported from `Base` for `e` is changed to ``. ([#23427])

* `isleaftype` is now `isconcrete` ([#23666])

## New macros

* `@__DIR__` has been added ([#18380])
Expand Down Expand Up @@ -296,6 +315,7 @@ includes this fix. Find the minimum version from there.
[#21257]: https://github.com/JuliaLang/julia/issues/21257
[#21346]: https://github.com/JuliaLang/julia/issues/21346
[#21378]: https://github.com/JuliaLang/julia/issues/21378
[#21709]: https://github.com/JuliaLang/julia/issues/21709
[#22064]: https://github.com/JuliaLang/julia/issues/22064
[#22182]: https://github.com/JuliaLang/julia/issues/22182
[#22350]: https://github.com/JuliaLang/julia/issues/22350
Expand All @@ -306,4 +326,8 @@ includes this fix. Find the minimum version from there.
[#22751]: https://github.com/JuliaLang/julia/issues/22751
[#22761]: https://github.com/JuliaLang/julia/issues/22761
[#22864]: https://github.com/JuliaLang/julia/issues/22864
[#23051]: https://github.com/JuliaLang/julia/issues/23051
[#23235]: https://github.com/JuliaLang/julia/issues/23235
[#23427]: https://github.com/JuliaLang/julia/issues/23427
[#23570]: https://github.com/JuliaLang/julia/issues/23570
[#23666]: https://github.com/JuliaLang/julia/issues/23666
75 changes: 75 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,87 @@ if VERSION < v"0.7.0-DEV.1285"
Base.OverflowError(msg) = OverflowError()
end

if VERSION < v"0.7.0-DEV.755"
# This is a hack to only add keyword signature that won't work on all julia versions.
# However, since we really only need to support a few (0.5, 0.6 and early 0.7) versions
# this should be good enough.
let Tf = typeof(cov), Tkw = Core.Core.kwftype(Tf)
@eval begin
@inline function _get_corrected(kws)
corrected = true
nkw = length(kws) >> 1
for i in 1:nkw
if kws[i * 2 - 1] !== :corrected
Base.kwerr(kws)
end
corrected = kws[i * 2]
end
return corrected::Bool
end
if VERSION >= v"0.6"
(::$Tkw)(kws::Vector{Any}, ::$Tf, x::AbstractVector) = cov(x, _get_corrected(kws))
(::$Tkw)(kws::Vector{Any}, ::$Tf, X::AbstractVector, Y::AbstractVector) =
cov(X, Y, _get_corrected(kws))
end
(::$Tkw)(kws::Vector{Any}, ::$Tf, x::AbstractMatrix, vardim::Int) =
cov(x, vardim, _get_corrected(kws))
(::$Tkw)(kws::Vector{Any}, ::$Tf, X::AbstractVecOrMat, Y::AbstractVecOrMat,
vardim::Int) = cov(X, Y, vardim, _get_corrected(kws))
end
end
end

# 0.7.0-DEV.1415
@static if !isdefined(Base, :adjoint)
const adjoint = ctranspose
const adjoint! = ctranspose!
export adjoint, adjoint!
end

# 0.7.0-DEV.1592
@static if !isdefined(Base, :MathConstants)
@eval module MathConstants
# All other ones are already exported by Base (so should be already in the users namespace)
# and will be automatically be in this module.
export
const= e
end
const= e
export
else
import Base.MathConstants
end

# 0.7.0-DEV.1535
@static if !isdefined(Base, :partialsort)
const partialsort = select
const partialsort! = select!
const partialsortperm = selectperm
const partialsortperm! = selectperm!
export partialsort, partialsort!, partialsortperm, partialsortperm!
end

# 0.7.0-DEV.1721
@static if !isdefined(Base, :AbstractRange)
const AbstractRange = Range
export AbstractRange
end

if VERSION < v"0.7.0-DEV.1325"
function Base.rtoldefault(x, y, atol::Real)
T = isa(x, Type) ? x : typeof(x)
S = isa(y, Type) ? y : typeof(y)
rtol = max(Base.rtoldefault(real(T)), Base.rtoldefault(real(S)))
return atol > 0 ? zero(rtol) : rtol
end
end

# 0.7.0-DEV.1775
@static if !isdefined(Base, :isconcrete)
const isconcrete = isleaftype
export isconcrete
end

include("deprecated.jl")

end # module Compat
53 changes: 53 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ A = view(rand(5,5), 1:3, 1:3)

# julia#13998
for x in (3.1, -17, 3//4, big(111.1), Inf)
local x
@test min(x) == max(x) == x
@test minmax(x) == (x, x)
end
Expand Down Expand Up @@ -770,6 +771,58 @@ no_specialize(@nospecialize(x::Integer)) = sin(2)
# 0.7
@test isa(1:2, AbstractRange)

# 0.7
let M = [1 + 2im 3 + 4im; 5 + 6im 7 + 8im],
M2 = adjoint(M),
Mc = [1 - 2im 5 - 6im; 3 - 4im 7 - 8im]

@test adjoint(M) == Mc
M2 .= 0
adjoint!(M2, M)
@test M2 == Mc
end

# 0.7
module TestMathConstants
using Compat.MathConstants
end
for name in [, :pi, :ℯ, :e, , :eulergamma, :catalan, , :golden]
@test isdefined(TestMathConstants, name) && !Base.isdeprecated(TestMathConstants, name)
@test isdefined(Compat.MathConstants, name) && !Base.isdeprecated(Compat.MathConstants, name)
end
module TestMathConstants2
using Compat
end
@test isdefined(TestMathConstants2, :ℯ) && !Base.isdeprecated(TestMathConstants, :ℯ)

# 0.7
@test partialsort([3,6,30,1,9], 2, rev=true) == 9
@test partialsort([3,6,30,1,9], 2, by=x->1/x) == 9
@test partialsortperm([3,6,30,1,9], 2, rev=true) == 5
@test partialsortperm([3,6,30,1,9], 2, by=x->1/x) == 5

# 0.7
@test isa(Base.rtoldefault(1.0, 2.0, 0), Float64)
@test isa(Base.rtoldefault(Float64, 2.0, 0), Float64)
@test isa(Base.rtoldefault(1.0, Float64, 0), Float64)
@test isa(Base.rtoldefault(Float64, Float64, 0), Float64)
@test Base.rtoldefault(Float64, Float64, 1.0) === 0.0

# 0.7
@test cov([1 2; 3 4], 1, corrected=true) == fill(2.0, 2, 2)
@test cov([1 2; 3 4], 1, corrected=false) == fill(1.0, 2, 2)
@test cov([1 2; 3 4], [0 4; 8 9], 1, corrected=true) == [8.0 5.0; 8.0 5.0]
@test cov([1 2; 3 4], [0 4; 8 9], 1, corrected=false) == [4.0 2.5; 4.0 2.5]
if VERSION >= v"0.6"
@test cov([1, 2], corrected=true) === 0.5
@test cov([1, 2], corrected=false) === 0.25
@test cov([1, 2], [0, 10], corrected=true) === 5.0
@test cov([1, 2], [0, 10], corrected=false) === 2.5
end

# 0.7
@test isconcrete(Int)

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

0 comments on commit 40353d7

Please sign in to comment.