From 0d1a94f0342288cafec9456d9c9eb4e015c62b54 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Sat, 9 Feb 2019 11:44:17 -0800 Subject: [PATCH] Drop support for Julia < 0.7 The time has come, as 0.6 is unmaintained. Fixes #651. --- .travis.yml | 1 - README.md | 465 +---------- REQUIRE | 2 +- appveyor.yml | 1 - src/Compat.jl | 1863 +-------------------------------------------- src/deprecated.jl | 28 +- test/REQUIRE | 1 - test/runtests.jl | 1470 +---------------------------------- 8 files changed, 66 insertions(+), 3765 deletions(-) delete mode 100644 test/REQUIRE diff --git a/.travis.yml b/.travis.yml index 8b561f997..ce7a24920 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ os: - linux - osx julia: - - 0.6 - 0.7 - 1.0 - 1.1 diff --git a/README.md b/README.md index 7501ad7e9..21053bffc 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ shortly after the `module` statement include lines like these: ```julia using Compat -import Compat.String +using Compat: somefunction ``` and then as needed add @@ -40,357 +40,40 @@ and then as needed add ``` wherever you want to use syntax that differs in the latest Julia -`master` (the development version of Julia). The `compat syntax` is usually +`master` (the development version of Julia). The `@compat syntax` is usually the syntax on Julia `master`. However, in a few cases where this is not possible, a slightly different syntax might be used. Please check the list below for the specific syntax you need. ## Supported syntax -Currently, the `@compat` macro supports the following syntaxes: - -* `@compat foo(::CartesianRange{N})` to replace the former - `foo(::CartesianRange{CartesianIndex{N}})` ([#20974]). Note that - `CartesianRange` now has two type parameters, so using them as - fields in other `struct`s requires manual intervention. - -* Required keyword arguments ([#25830]). For example, `@compat foo(; x, y)` makes `x` and `y` required keyword arguments: when calling `foo`, an error is thrown if `x` or `y` is not explicitly provided. +The `@compat` macro currently does no syntax tranformations and is a no-op. ## Module Aliases -* `using Compat.Test`, `using Compat.SharedArrays`, `using Compat.Mmap`, and `using - Compat.DelimitedFiles` are provided on versions older than 0.7, where these are not yet - part of the standard library. ([#23931]) - -* `using Compat.Base64` is provided on versions older than 0.7, where this library is not - yet a part of the standard library. ([#24361]) - -* `using Compat.Dates` is provided on versions older than 0.7, where this library is not - yet a part of the standard library. ([#24459]) - -* `using Compat.Unicode` is provided on versions older than 0.7, where this library is not - yet a part of the standard library. ([#25021]) - -* `using Compat.Printf` is provided on versions older than 0.7, where this library is not - yet a part of the standard library. ([#25056]) - -* `using Compat.SparseArrays` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25249]). - -* `using Compat.LinearAlgebra` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25571]). - -* `using Compat.Random` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#24874]). - -* `using Compat.Libdl` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25459]). - -* `using Compat.REPL` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25544]). - -* `using Compat.Serialization` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25628]). - -* `using Compat.Distributed` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#24443]). - -* `using Compat.Pkg` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25705]). Note that `Compat.Pkg` will point to - the new package manager on 0.7 which does not have a fully compatible API with the old - package manager. - -* `using Compat.InteractiveUtils` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25780]). - -* `using Compat.LibGit2` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25706]). - -* `using Compat.UUIDs` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25819]). - -* `using Compat.Markdown` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25738]). - -* `using Compat.Sockets` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#25935]) - -* `using Compat.Statistics` is provided on versions older than 0.7, where this library is - not yet part of the standard library ([#27834]). +`Compat.X` is available for every stdlib package `X` for backwards compatibility with +previous verisons of Compat. +Newer code should use `X` directly. ## New functions, macros, and methods -* `Compat.readline` with `keep` keyword argument ([#25646]) - -* `Compat.eachline` with `keep` keyword argument ([#25646]) - -* `Compat.readuntil` with `keep` keyword argument ([#25646]) - -* The `isabstract`, `parameter_upper_bound`, `typename` reflection methods were added in Julia 0.6. This package re-exports these from the `Compat.TypeUtils` submodule. On earlier versions of julia, that module contains the same functions, but operating on the pre-0.6 type system representation. - -* `Compat.invokelatest` supports keywords ([#22646]). - -* `@__MODULE__` is aliased to `current_module()` for Julia versions 0.6 and below. Versions of `Base.binding_module`, `expand`, `macroexpand`, and `include_string` were added that accept a module as the first argument. ([#22064]) - -* `Cmd` elements can be accessed as if the `Cmd` were an array of strings for 0.6 and below ([#21197]). - -* `Val(x)` constructs `Val{x}()`. ([#22475]) - -* The `reshape` and `ntuple` APIs are extended to support `Val{x}()` arguments on 0.6 and below. - -* `logdet` for `Number`s ([#22629]). - -* `fieldcount` is equivalent to `nfields` for Julia versions 0.6 and below and is used to - determine the number of fields in a data type ([#22350]). - -* There are versions of `InexactError`, `DomainError`, and `OverflowError` that take the same arguments as introduced in Julia 0.7-DEV ([#20005], [#22751], [#22761]). - -* `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 of `Compat.Statistics.cov` ([#21709]). - -* `isequal`, `==` and `in` have one argument "curried" forms. For example `isequal(x)` - returns a function that compares its arguments to `x` using `isequal` ([#26436]). - -* `*(::Union{Char,AbstractString},::Union{Char,AbstractString})` concatenation. ([#22512]) - -* `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]). - -* `UndefInitializer` and `undef` with corresponding `Array` constructors ([#24652], [#26316]). - -* `BitArray` constructors for `undef` ([#24785], [#26316]). - -* `@compat finalizer(func, obj)` with the finalizer to run as the first argument and the object to be finalized - as the second ([#24605]). - -* `IOContext` accepting key-value `Pair`s ([#23271]). - -* `pairs` for iterating over key-value `Pair`s ([#22907]). - -* `get` do-block syntax supported when using `ENV` ([#23412]). - -* `Some{T}` wraps `T` to signify that a result of `T<:Void` is expected ([#23642]). - -* `replace` accepts a pair of pattern and replacement, with the number of replacements as - a keyword argument ([#25165]). - -* `CartesianIndices` and `LinearIndices` types represent cartesian and linear indices of - an array (respectively), and indexing such objects allows translating from one kind of index - to the other ([#25113]). - -* `codeunits(s)` returns an array-like view of the `UInt8` code units of - a string and `ncodeunits(s)` returns the number of code units ([#25241]). - `codeunit(s)` returns the type of the code units of `s` ([#24999]). - -* `thisind(s, i)` returns the character index for codeunit `i` ([#24414]). - -* Three-argument methods `prevind(s,i,n)`, `nextind(s,i,n)` ([#23805]), and `length(s,i,j)` ([#24999]); the latter two replace `chr2ind` and `ind2chr` in Julia 0.7, respectively. - -* `printstyled` prints to a given stream optionally in color and/or bolded ([#25522]). - -* `Dates.Period` rounding (e.g., `round(Dates.Hour(36), Dates.Day, RoundNearestTiesUp) == Dates.Day(2)` ([#24182]). - -* `firstindex` to obtain the first index of an iterable ([#25458]). - -* `Compat.names` supporting keyword arguments for `all` and `imported` ([#25647]). - -* `Compat.IOBuffer` supporting keyword arguments ([#25873]). - -* `Compat.range` supporting positional and keyword arguments flavors ([#25896]), ([#28708]). - -* `Compat.trunc`, `Compat.floor`, `Compat.ceil`, `Compat.round`, take a keyword argument - for `base` and `digits`, `Compat.round` also takes `sigdigits` ([#26156], [#26670]). - -* `Compat.mv` and `Compat.cp` with `force` keyword argument ([#26069]). - -* `Compat.accumulate`, `Compat.accumulate!`, `Compat.all`, `Compat.any`, - `Compat.cumprod`, `Compat.cumprod!`, `Compat.cumsum`, `Compat.cumsum!`, - `Compat.findmax`, `Compat.findmin`, `Compat.mapreduce`, `Compat.maximum`, `Compat.Statistics.mean`, - `Compat.Statistics.median`, `Compat.minimum`, `Compat.prod`, `Compat.reduce`, `Compat.sort`, - and `Compat.sum` with `dims` keyword argument ([#25989],[#26369]). - -* `Compat.mapreduce` and `Compat.reduce` with `init` keyword argument ([#27711]). - -* `selectdim` to obtain a view of an array with a specified index for a specified dimension ([#26009]). - -* `Compat.cat` with `dims` as keyword argument ([#27163]) - -* Single-argument `permutedims(x)` for matrices and vectors ([#24839]). - -* `fetch` for `Task`s ([#25940]). - -* `Compat.qr` takes `pivot` as a `Val` _instance_ ([#22475]). - -* `Compat.Sys.which` and `Compat.Sys.isexecutable` ([#26559], [#27298]). - -* `Compat.rmul!` provides a subset of the functionality of `LinearAlgebra.rmul!` for - use with Julia 0.6 ([#25701], [#25812]). - -* `isbits(t::Type)` is now `isbitstype(t)` ([#26850]). - -* `something` to get the first argument different from `nothing`, unwrapping those - of the `Some` type ([#27258]). - -* `mapslices` with `dims` keyword argument ([#27828]). - * `hasproperty` and `hasfield` ([#28850]). - `hasproperty` is defined only for Julia 0.7 or later. ## Renaming -* `Display` is now `AbstractDisplay` ([#24831]). - -* `reprmime(mime, x)` is now `repr(mime, x)` ([#25990]) and `mimewritable` is now `showable` ([#26089]). - -* `is_apple`, `is_bsd`, `is_linux`, `is_unix`, and `is_windows` are now `Sys.isapple`, `Sys.isbsd`, - `Sys.islinux`, `Sys.isunix`, and `Sys.iswindows`, respectively. These are available in the `Compat.Sys` - submodule. ([#22182]) - -* `readstring` is replaced by methods of `read`. ([#22864]) - - `read(::IO, ::Type{String})`, `read(::AbstractString, ::Type{String})`, - and `read(::AbstractCmd, ::Type{String})` are defined for 0.6 and below. - -* `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]) - -* `IntSet` is now `BitSet` ([#24282]) - -* `strwidth` and `charwidth` are now merged into `textwidth` ([#23667]). - -* `Complex32`, `Complex64`, and `Complex128` are now `ComplexF16`, `ComplexF32`, and - `ComplexF64`, respectively ([#24647]). - -* `trace` is now `tr`, available as `Compat.tr` ([#26365]). - -* `JULIA_HOME` is now `Sys.BINDIR`, available in the `Compat.Sys` submodule. ([#25102]) - -* `Associative` is now `AbstractDict` ([#25012]). - -* `indices` is now `axes` ([#25057]). This function is not exported from Compat to avoid - conflicts with AxisArrays and other such packages. - -* `Void` is now `Nothing` with an alias `Cvoid` for C interop ([#25162]). - -* `unshift!` and `shift!` are now `pushfirst!` and `popfirst!` ([#25100]). - -* `Base.IteratorSize` and `Base.IteratorEltype` are available as - `Compat.IteratorSize` and `Compat.IteratorEltype` ([#25402]). - -* `copy!` and `unsafe_copy!` are now `copyto!` and `unsafe_copyto!` ([#24808]). - -* `contains(haystack, needle)` is now `occursin(needle, haystack)` ([#26283]). - `occursin` also has a new method for `Char` needles ([#22435]). - -* `ismatch(r::Regex, str::AbstractString, offset=0)` is now `occursin(r, str)` and - `occursin(r, str, offset = offset)` respectively ([#24673],[#26283]). - -* `ipermute!` is now `invpermute!` ([#25168]). - -* `module_parent`, `Base.function_module`, and `Base.datatype_module` are now methods of - a new function called `parentmodule` ([#25629]). - -* `module_name`, `Base.function_name`, and `Base.datatype_name` are now methods of a - new function called `nameof` ([#25622]). - -* `find` is now `findall` ([#25545]). - -* `search` is now `findfirst`/`findnext` and `rsearch` is now `findlast`/`findprev`, - sometimes combined with `isequal` or `in` ([#24673], [#26436]). - -* `Compat.findfirst`, `Compat.findnext`, `Compat.findlast` and `Compat.findprev`, - return `nothing` when no match is found (rather than `0` or `0:-1`) - as on Julia 0.7 ([#24673], [#26149]). - -* `findin(a, b)` is now `findall(in(b), a)` ([#24673]). - -* `indmin` and `indmax` are now `argmin` and `argmax`, respectively ([#25654]). - -* `Compat.indexin` accepts any iterable as first argument, returns `nothing` (rather than `0`) - for entries with no match and gives the index of the first (rather than the last) match - ([#25662], [#25998]). - -* `isabstract` and `isleaftype` are now `isabstracttype` and `isconcretetype`, respectively - ([#23666], [#25496]). - -* `gc` and `gc_enable` are now `GC.gc` and `GC.enable`, respectively ([#25616]). - -* `endof` is now `lastindex` ([#25458]). (Note that `lastindex(A, n)` is not supported.) - -* `nb_available` is now `bytesavailable` ([#25634]). - -* `method_exists` is now `hasmethod` ([#25615]). - -* `object_id` is now `objectid` ([#25615]). - -* `DevNull`, `STDIN`, `STDOUT` and `STDERR` are now `devnull`, `stdin`, `stdout` and - `stderr` respectively ([#25959]). - -* `LinSpace` is now `LinRange` ([#25896]). - -* `isupper`, `islower`, `ucfirst` and `lcfirst` are now `isuppercase`, `islowercase`, - `uppercasefirst` and `lowercasefirst` ([#26442]). - -* `Compat.split` and `Compat.rsplit` accept `keepempty` keyword argument - if `splitter` is given as second argument ([#26634]) - -* `isalpha` is now `isletter` ([#27077]). - -* `cfunction` is now `@cfunction` ([#26486]). - -* `Unicode.isnumeric` is now available as `isnumeric` ([#25479]). - -* `vecnorm` and `vecdot` are now `Compat.norm` and `Compat.dot`, respectively, while the - old `norm(A::AbstractMatrix, p=2)` is now `Compat.opnorm` ([#27401]). `import Compat: ⋅` - to get `Compat.dot` as the binary operator `⋅`. - -* `atan2` is now a 2-argument method of `atan` ([#27253]). - -* `srand` is now `Compat.Random.seed!` ([#28295]) - -* `realmin` and `realmax` are now `floatmin` and `floatmax` ([#28302]) - -* `squeeze` is now `dropdims` ([#28303], [#26660]). - -* `repmat` is now `repeat` ([#26039]) +N/A ## New macros -* `@nospecialize` has been added ([#22666]). - -* The logging macros `@error`, `@warn`, `@info` and `@debug` can be used as - `Compat.@error`, `Compat.@warn`, `Compat.@info` and `Compat.@debug` on Julia 0.6 ([#24490]). - Note that the behavior do not mirror the logging macros in Julia 0.7, instead on Julia 0.6: - - Messages are printed to `STDERR` (like `info` and `warn` on Julia 0.6) and not to a - dedicated logging stream. - - The loglevel can not be controlled, but `Compat.@debug` messages can be turned on/off - by calling `Compat.enable_debug(true/false)`. - - Extra metadata sent to the macros are ignored. - - As an alternative, see the MicroLogging.jl package for a logging interface similar to the one in Julia 0.7. +N/A ## Other changes -* On versions of Julia that do not contain a Base.Threads module, Compat defines a Threads module containing a no-op `@threads` macro. - -* The `Expr(:macrocall)` has an extra initial argument `__source__`, which can be tested for with `Compat.macros_have_sourceloc`. +N/A ## New types -* `Compat.AbstractDateTime` is an alias for `Compat.Dates.AbstractDateTime` as of ([#25227]) and `Compat.Dates.TimeType` prior to that. +N/A ## Developer tips @@ -441,132 +124,4 @@ includes this fix. Find the minimum version from there. * Now specify the correct minimum version for Compat in your REQUIRE file by `Compat ` -[#20005]: https://github.com/JuliaLang/julia/issues/20005 -[#20974]: https://github.com/JuliaLang/julia/issues/20974 -[#21197]: https://github.com/JuliaLang/julia/issues/21197 -[#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 -[#22435]: https://github.com/JuliaLang/julia/issues/22435 -[#22475]: https://github.com/JuliaLang/julia/issues/22475 -[#22512]: https://github.com/JuliaLang/julia/issues/22512 -[#22629]: https://github.com/JuliaLang/julia/issues/22629 -[#22646]: https://github.com/JuliaLang/julia/issues/22646 -[#22666]: https://github.com/JuliaLang/julia/issues/22666 -[#22751]: https://github.com/JuliaLang/julia/issues/22751 -[#22761]: https://github.com/JuliaLang/julia/issues/22761 -[#22864]: https://github.com/JuliaLang/julia/issues/22864 -[#22907]: https://github.com/JuliaLang/julia/issues/22907 -[#23051]: https://github.com/JuliaLang/julia/issues/23051 -[#23235]: https://github.com/JuliaLang/julia/issues/23235 -[#23271]: https://github.com/JuliaLang/julia/issues/23271 -[#23412]: https://github.com/JuliaLang/julia/issues/23412 -[#23427]: https://github.com/JuliaLang/julia/issues/23427 -[#23570]: https://github.com/JuliaLang/julia/issues/23570 -[#23642]: https://github.com/JuliaLang/julia/issues/23642 -[#23666]: https://github.com/JuliaLang/julia/issues/23666 -[#23667]: https://github.com/JuliaLang/julia/issues/23667 -[#23757]: https://github.com/JuliaLang/julia/issues/23757 -[#23805]: https://github.com/JuliaLang/julia/issues/23805 -[#23931]: https://github.com/JuliaLang/julia/issues/23931 -[#24047]: https://github.com/JuliaLang/julia/issues/24047 -[#24182]: https://github.com/JuliaLang/julia/issues/24182 -[#24282]: https://github.com/JuliaLang/julia/issues/24282 -[#24361]: https://github.com/JuliaLang/julia/issues/24361 -[#24372]: https://github.com/JuliaLang/julia/issues/24372 -[#24414]: https://github.com/JuliaLang/julia/issues/24414 -[#24443]: https://github.com/JuliaLang/julia/issues/24443 -[#24459]: https://github.com/JuliaLang/julia/issues/24459 -[#24490]: https://github.com/JuliaLang/julia/issues/24490 -[#24605]: https://github.com/JuliaLang/julia/issues/24605 -[#24647]: https://github.com/JuliaLang/julia/issues/24647 -[#24652]: https://github.com/JuliaLang/julia/issues/24652 -[#24657]: https://github.com/JuliaLang/julia/issues/24657 -[#24673]: https://github.com/JuliaLang/julia/issues/24673 -[#24785]: https://github.com/JuliaLang/julia/issues/24785 -[#24808]: https://github.com/JuliaLang/julia/issues/24808 -[#24831]: https://github.com/JuliaLang/julia/issues/24831 -[#24839]: https://github.com/JuliaLang/julia/issues/24839 -[#24874]: https://github.com/JuliaLang/julia/issues/24874 -[#24999]: https://github.com/JuliaLang/julia/issues/24999 -[#25012]: https://github.com/JuliaLang/julia/issues/25012 -[#25021]: https://github.com/JuliaLang/julia/issues/25021 -[#25056]: https://github.com/JuliaLang/julia/issues/25056 -[#25057]: https://github.com/JuliaLang/julia/issues/25057 -[#25100]: https://github.com/JuliaLang/julia/issues/25100 -[#25102]: https://github.com/JuliaLang/julia/issues/25102 -[#25113]: https://github.com/JuliaLang/julia/issues/25113 -[#25162]: https://github.com/JuliaLang/julia/issues/25162 -[#25165]: https://github.com/JuliaLang/julia/issues/25165 -[#25168]: https://github.com/JuliaLang/julia/issues/25168 -[#25227]: https://github.com/JuliaLang/julia/issues/25227 -[#25241]: https://github.com/JuliaLang/julia/issues/25241 -[#25249]: https://github.com/JuliaLang/julia/issues/25249 -[#25402]: https://github.com/JuliaLang/julia/issues/25402 -[#25458]: https://github.com/JuliaLang/julia/issues/25458 -[#25459]: https://github.com/JuliaLang/julia/issues/25459 -[#25479]: https://github.com/JuliaLang/julia/issues/25479 -[#25496]: https://github.com/JuliaLang/julia/issues/25496 -[#25522]: https://github.com/JuliaLang/julia/issues/25522 -[#25544]: https://github.com/JuliaLang/julia/issues/25544 -[#25545]: https://github.com/JuliaLang/julia/issues/25545 -[#25571]: https://github.com/JuliaLang/julia/issues/25571 -[#25615]: https://github.com/JuliaLang/julia/issues/25615 -[#25616]: https://github.com/JuliaLang/julia/issues/25616 -[#25622]: https://github.com/JuliaLang/julia/issues/25622 -[#25628]: https://github.com/JuliaLang/julia/issues/25628 -[#25629]: https://github.com/JuliaLang/julia/issues/25629 -[#25634]: https://github.com/JuliaLang/julia/issues/25634 -[#25646]: https://github.com/JuliaLang/julia/issues/25646 -[#25647]: https://github.com/JuliaLang/julia/issues/25647 -[#25654]: https://github.com/JuliaLang/julia/issues/25654 -[#25662]: https://github.com/JuliaLang/julia/issues/25662 -[#25701]: https://github.com/JuliaLang/julia/issues/25701 -[#25705]: https://github.com/JuliaLang/julia/issues/25705 -[#25706]: https://github.com/JuliaLang/julia/issues/25706 -[#25738]: https://github.com/JuliaLang/julia/issues/25738 -[#25780]: https://github.com/JuliaLang/julia/issues/25780 -[#25812]: https://github.com/JuliaLang/julia/issues/25812 -[#25819]: https://github.com/JuliaLang/julia/issues/25819 -[#25830]: https://github.com/JuliaLang/julia/issues/25830 -[#25873]: https://github.com/JuliaLang/julia/issues/25873 -[#25896]: https://github.com/JuliaLang/julia/issues/25896 -[#25935]: https://github.com/JuliaLang/julia/issues/25935 -[#25940]: https://github.com/JuliaLang/julia/issues/25940 -[#25959]: https://github.com/JuliaLang/julia/issues/25959 -[#25989]: https://github.com/JuliaLang/julia/issues/25989 -[#25990]: https://github.com/JuliaLang/julia/issues/25990 -[#25998]: https://github.com/JuliaLang/julia/issues/25998 -[#26009]: https://github.com/JuliaLang/julia/issues/26009 -[#26039]: https://github.com/JuliaLang/julia/issues/26039 -[#26069]: https://github.com/JuliaLang/julia/issues/26069 -[#26089]: https://github.com/JuliaLang/julia/issues/26089 -[#26149]: https://github.com/JuliaLang/julia/issues/26149 -[#26156]: https://github.com/JuliaLang/julia/issues/26156 -[#26283]: https://github.com/JuliaLang/julia/issues/26283 -[#26316]: https://github.com/JuliaLang/julia/issues/26316 -[#26365]: https://github.com/JuliaLang/julia/issues/26365 -[#26369]: https://github.com/JuliaLang/julia/issues/26369 -[#26436]: https://github.com/JuliaLang/julia/issues/26436 -[#26442]: https://github.com/JuliaLang/julia/issues/26442 -[#26486]: https://github.com/JuliaLang/julia/issues/26486 -[#26559]: https://github.com/JuliaLang/julia/issues/26559 -[#26634]: https://github.com/JuliaLang/julia/issues/26634 -[#26660]: https://github.com/JuliaLang/julia/issues/26660 -[#26670]: https://github.com/JuliaLang/julia/issues/26670 -[#26850]: https://github.com/JuliaLang/julia/issues/26850 -[#27077]: https://github.com/JuliaLang/julia/issues/27077 -[#27163]: https://github.com/JuliaLang/julia/issues/27163 -[#27253]: https://github.com/JuliaLang/julia/issues/27253 -[#27258]: https://github.com/JuliaLang/julia/issues/27258 -[#27298]: https://github.com/JuliaLang/julia/issues/27298 -[#27401]: https://github.com/JuliaLang/julia/issues/27401 -[#27711]: https://github.com/JuliaLang/julia/issues/27711 -[#27828]: https://github.com/JuliaLang/julia/issues/27828 -[#27834]: https://github.com/JuliaLang/julia/issues/27834 -[#28295]: https://github.com/JuliaLang/julia/issues/28295 -[#28302]: https://github.com/JuliaLang/julia/issues/28302 -[#28303]: https://github.com/JuliaLang/julia/issues/28303 -[#28708]: https://github.com/JuliaLang/julia/issues/28708 [#28850]: https://github.com/JuliaLang/julia/issues/28850 diff --git a/REQUIRE b/REQUIRE index 137767a42..859ad4616 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1 @@ -julia 0.6 +julia 0.7 diff --git a/appveyor.yml b/appveyor.yml index ef5aa8d77..ede8e2bd1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,5 @@ environment: matrix: - - julia_version: 0.6 - julia_version: 0.7 - julia_version: 1.0 - julia_version: 1.1 diff --git a/src/Compat.jl b/src/Compat.jl index d31790434..3e03d306a 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1,1840 +1,55 @@ -VERSION < v"0.7.0-beta2.199" && __precompile__() - module Compat -# https://github.com/JuliaLang/julia/pull/25935 -if VERSION < v"0.7.0-DEV.4442" - @eval module Sockets - import Base: - @ip_str, IPAddr, IPv4, IPv6, UDPSocket, TCPSocket, DNSError, - accept, connect, getaddrinfo, getipaddr, getsockname, listen, - listenany, recv, recvfrom, send, bind - - export - @ip_str, IPAddr, IPv4, IPv6, UDPSocket, TCPSocket, - accept, connect, getaddrinfo, getipaddr, getsockname, listen, - listenany, recv, recvfrom, send, bind - end -else - import Sockets -end +# Import stdlib packages to avoid breaking code that does e.g. `using Compat.Test` +import Base64 +import Dates +import DelimitedFiles +import Distributed +import InteractiveUtils +import LibGit2 +import Libdl +import LinearAlgebra +import Markdown +import Mmap +import Pkg +import Printf +import REPL +import Random +import Serialization +import SharedArrays +import Sockets +import SparseArrays +import Statistics +import SuiteSparse +import Test +import UUIDs +import Unicode + +# Bindings that were available at the top level in Compat +using Base: notnothing +using Dates: AbstractDateTime +using LinearAlgebra: dot, norm, opnorm, qr, rmul!, tr include("compatmacro.jl") -@static if !isdefined(Base, :devnull) #25959 - export devnull, stdout, stdin, stderr - const devnull = DevNull - for f in (:stdout, :stdin, :stderr) - F = Symbol(uppercase(string(f))) - rf = Symbol(string("_redirect_", f)) - @eval begin - $f = $F - # overload internal _redirect_std* functions - # so that they change Compat.std* - function Base.$rf(stream::IO) - ret = invoke(Base.$rf, Tuple{Any}, stream) - global $f = $F - return ret - end - end - end - # in __init__ because these can't be saved during precompiling - function __init__() - global stdout = STDOUT - global stdin = STDIN - global stderr = STDERR - end -end - -@static if !isdefined(Base, Symbol("@nospecialize")) - # 0.7 - macro nospecialize(arg) - if isa(arg, Symbol) - # @nospecialize(arg) - return :($(esc(arg))::ANY) - elseif isa(arg, Expr) && arg.head == :(::) - # @nospecialize(arg::typ) - # unsupported: needs ::ANY which would change dispatch as determined by ::typ - elseif isa(arg, Expr) && arg.head == :(=) - # @nospecialize(arg=val) - arg, val = arg.args - if isa(arg, Expr) && arg.head == :(::) - # @nospecialize(arg::typ=val) - # unsupported (see above), but generate a kw arg - arg, typ = arg.args - return Expr(:kw, :($(esc(arg))::$(esc(typ))), esc(val)) - else - return Expr(:kw, :($(esc(arg))::ANY), esc(val)) - end - end - return esc(arg) - end - export @nospecialize -end - -# https://github.com/JuliaLang/julia/pull/22064 -@static if !isdefined(Base, Symbol("@__MODULE__")) - # 0.7 - export @__MODULE__ - macro __MODULE__() - return current_module() - end - Base.expand(mod::Module, x::ANY) = eval(mod, :(expand($(QuoteNode(x))))) - Base.macroexpand(mod::Module, x::ANY) = eval(mod, :(macroexpand($(QuoteNode(x))))) - Base.include_string(mod::Module, code::String, fname::String) = - eval(mod, :(include_string($code, $fname))) - Base.include_string(mod::Module, code::AbstractString, fname::AbstractString="string") = - eval(mod, :(include_string($code, $fname))) -end - -@static if !isdefined(Base, :isabstracttype) # VERSION < v"0.7.0-DEV.3475" - const isabstracttype = Base.isabstract - export isabstracttype -end - -module TypeUtils - using Base: parameter_upper_bound, typename - using Compat: isabstracttype - const isabstract = isabstracttype - export isabstract, parameter_upper_bound, typename -end # module TypeUtils - -# https://github.com/JuliaLang/julia/pull/25646 -@static if VERSION < v"0.7.0-DEV.3510" - # not exported - # chomp parameter preserved for compatibility with earliear Compat versions - readline(s::IO=STDIN; chomp::Bool=true, keep::Bool=!chomp) = Base.readline(s; chomp=!keep) - eachline(s; keep::Bool=false) = Base.eachline(s; chomp=!keep) - - stripdelim(s, d::Union{Char,UInt8}) = s[end] == Char(d) ? s[1:prevind(s,lastindex(s))] : s - stripdelim(s, d::AbstractString) = endswith(s, d) ? s[1:prevind(s,lastindex(s),length(d))] : s - function readuntil(f, d; keep::Bool = false) - s = Base.readuntil(f, d) - if keep || isempty(s) - return s - else - return stripdelim(s, d) - end - end - readuntil(f, d::Vector{T}; keep::Bool = false) where {T<:Union{UInt8,Char}} = convert(Vector{T}, readuntil(f, String(d), keep=keep)) -end - -# https://github.com/JuliaLang/julia/pull/22646 -if VERSION < v"0.7.0-DEV.1139" - function invokelatest(f, args...; kwargs...) - inner() = f(args...; kwargs...) - Base.invokelatest(inner) - end -else - import Base.invokelatest -end - -# https://github.com/JuliaLang/julia/pull/21197 -if VERSION < v"0.7.0-DEV.257" - # allow the elements of the Cmd to be accessed as an array or iterator - for f in (:length, :endof, :start, :eachindex, :eltype, :first, :last) - @eval Base.$f(cmd::Cmd) = $f(cmd.exec) - end - for f in (:next, :done, :getindex) - @eval Base.$f(cmd::Cmd, i) = $f(cmd.exec, i) - end -end - -# https://github.com/JuliaLang/julia/pull/22475 -@static if VERSION < v"0.7.0-DEV.843" - import Base: Val - (::Type{Val})(x) = (Base.@_pure_meta; Val{x}()) - # Also add methods for Val(x) that were previously Val{x} - import Base: reshape - reshape{N}(parent::AbstractArray, ndims::Val{N}) = reshape(parent, Val{N}) - import Base: ntuple - ntuple{F,N}(f::F, ::Val{N}) = ntuple(f, Val{N}) -end - -# https://github.com/JuliaLang/julia/pull/22629 -if VERSION < v"0.7.0-DEV.848" - import Base: logdet - logdet(A) = log(det(A)) -end - -# https://github.com/JuliaLang/julia/pull/22633 -if VERSION < v"0.7.0-DEV.1041" - # these have been deprecated in Julia 0.7.0-DEV.5272; we keep them here to avoid - # breakage in packages already using them on Julia 0.6 - import Base.LinAlg: chol, chol! - chol!(J::UniformScaling, uplo) = UniformScaling(chol!(J.λ, uplo)) - chol(J::UniformScaling, args...) = UniformScaling(chol(J.λ, args...)) -end - -# https://github.com/JuliaLang/julia/pull/21746 -const macros_have_sourceloc = VERSION >= v"0.7-" && length(:(@test).args) == 2 - -# 0.7.0-DEV.3155 -@static if !isdefined(Base, :pushfirst!) - const pushfirst! = unshift! - const popfirst! = shift! - export pushfirst!, popfirst! -end - -# https://github.com/JuliaLang/julia/pull/22182 -module Sys - const KERNEL = Base.Sys.KERNEL - @static if VERSION < v"0.7.0-DEV.914" - isapple(k::Symbol=KERNEL) = k in (:Darwin, :Apple) - isbsd(k::Symbol=KERNEL) = isapple(k) || k in (:FreeBSD, :OpenBSD, :NetBSD, :DragonFly) - islinux(k::Symbol=KERNEL) = k == :Linux - isunix(k::Symbol=KERNEL) = isbsd(k) || islinux(k) - iswindows(k::Symbol=KERNEL) = k in (:Windows, :NT) - else - import Base.Sys: isapple, isbsd, islinux, isunix, iswindows - end - - @static if VERSION < v"0.7.0-DEV.5171" - using ..Compat: pushfirst! - - function isexecutable(path::AbstractString) - if iswindows() - isfile(path) - else - ccall(:access, Cint, (Ptr{UInt8}, Cint), path, 0x01) == 0 - end - end - - function which(program::AbstractString) - progs = String[] - base = basename(program) - if iswindows() - isempty(last(splitext(base))) || push!(progs, base) - for p = [".exe", ".com"] - push!(progs, base * p) - end - else - push!(progs, base) - end - dirs = String[] - dir = dirname(program) - if isempty(dir) - pathsep = iswindows() ? ';' : ':' - append!(dirs, map(abspath, split(get(ENV, "PATH", ""), pathsep))) - iswindows() && pushfirst!(dirs, pwd()) - else - push!(dirs, abspath(dir)) - end - for d in dirs, p in progs - path = joinpath(d, p) - isexecutable(path) && return realpath(path) - end - nothing - end - elseif VERSION < v"0.7.0-alpha.6" - import Base.Sys: isexecutable - - which(program::AbstractString) = try - Base.Sys.which(program) - catch err - err isa ErrorException || rethrow(err) - nothing - end - else - import Base.Sys: which, isexecutable - end - - # https://github.com/JuliaLang/julia/pull/25102 - # NOTE: This needs to be in an __init__ because JULIA_HOME is not - # defined when building system images. - function __init__() - global BINDIR = VERSION < v"0.7.0-DEV.3073" ? JULIA_HOME : Base.Sys.BINDIR - end -end - -@static if VERSION < v"0.7.0-DEV.892" - fieldcount(t) = nfields(t) - export fieldcount -end - -if VERSION < v"0.7.0-DEV.1053" - Base.read(obj::IO, ::Type{String}) = readstring(obj) - Base.read(obj::AbstractString, ::Type{String}) = readstring(obj) - Base.read(obj::Base.AbstractCmd, ::Type{String}) = readstring(obj) -end - -# https://github.com/JuliaLang/julia/pull/20005 -if VERSION < v"0.7.0-DEV.896" - Base.InexactError(name::Symbol, T, val) = InexactError() -end - -# https://github.com/JuliaLang/julia/pull/22751 -if VERSION < v"0.7.0-DEV.924" - Base.DomainError(val) = DomainError() - Base.DomainError(val, msg) = DomainError() -end - -# https://github.com/JuliaLang/julia/pull/22761 -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. - # TODO add deprecation warning to switch to StatsBase - let Tf = typeof(Base.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 - (::$Tkw)(kws::Vector{Any}, ::$Tf, x::AbstractVector) = Base.cov(x, _get_corrected(kws)) - (::$Tkw)(kws::Vector{Any}, ::$Tf, X::AbstractVector, Y::AbstractVector) = - Base.cov(X, Y, _get_corrected(kws)) - (::$Tkw)(kws::Vector{Any}, ::$Tf, x::AbstractMatrix, vardim::Int) = - Base.cov(x, vardim, _get_corrected(kws)) - (::$Tkw)(kws::Vector{Any}, ::$Tf, X::AbstractVecOrMat, Y::AbstractVecOrMat, - vardim::Int) = Base.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.1660 -@static if !isdefined(Base, :pairs) - pairs(collection) = Base.Generator(=>, keys(collection), values(collection)) - pairs(a::Associative) = a - - const IndexValue = Iterators.IndexValue - - pairs(::IndexLinear, A::AbstractArray) = IndexValue(A, linearindices(A)) - pairs(::IndexCartesian, A::AbstractArray) = IndexValue(A, CartesianRange(indices(A))) - - Base.keys(a::AbstractArray) = CartesianRange(indices(a)) - Base.keys(a::AbstractVector) = linearindices(a) - Base.keys(s::IndexStyle, A::AbstractArray, B::AbstractArray...) = eachindex(s, A, B...) - - Base.values(itr) = itr -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.3475 -@static if !isdefined(Base, :isconcretetype) - # 0.7.0-DEV.1775 - @static if !isdefined(Base, :isconcrete) - const isconcretetype = isleaftype - const isconcrete = isleaftype # for compatibility with earlier Compat versions - export isconcrete - else - const isconcretetype = isconcrete - end - export isconcretetype -end - -# 0.7.0-DEV.2005 -if VERSION < v"0.7.0-DEV.2005" - const Mmap = Base.Mmap - const Test = Base.Test - @eval module SharedArrays - if isdefined(Base, :Distributed) - using Base.Distributed.procs - else - using Base.procs - end - export SharedArray, SharedMatrix, SharedVector, indexpids, localindexes, sdata, - procs - end - const DelimitedFiles = Base.DataFmt -else - import Test, SharedArrays, Mmap, DelimitedFiles -end - -if VERSION < v"0.7.0-DEV.2575" - const Dates = Base.Dates -else - import Dates -end - -if VERSION < v"0.7.0-DEV.3382" - const Libdl = Base.Libdl -else - import Libdl -end - -# https://github.com/JuliaLang/julia/pull/24182 -if VERSION < v"0.7.0-DEV.2402" - const ConvertiblePeriod = Union{Compat.Dates.TimePeriod, Compat.Dates.Week, Compat.Dates.Day} - const TimeTypeOrPeriod = Union{Compat.Dates.TimeType, Compat.ConvertiblePeriod} - - """ - floor(x::Period, precision::T) where T <: Union{TimePeriod, Week, Day} -> T - - Rounds `x` down to the nearest multiple of `precision`. If `x` and `precision` are different - subtypes of `Period`, the return value will have the same type as `precision`. - - For convenience, `precision` may be a type instead of a value: `floor(x, Dates.Hour)` is a - shortcut for `floor(x, Dates.Hour(1))`. - - ```jldoctest - julia> floor(Dates.Day(16), Dates.Week) - 2 weeks - - julia> floor(Dates.Minute(44), Dates.Minute(15)) - 30 minutes - - julia> floor(Dates.Hour(36), Dates.Day) - 1 day - ``` - - Rounding to a `precision` of `Month`s or `Year`s is not supported, as these `Period`s are of - inconsistent length. - """ - function Base.floor(x::Compat.ConvertiblePeriod, precision::T) where T <: Compat.ConvertiblePeriod - Compat.Dates.value(precision) < 1 && throw(DomainError(precision)) - _x, _precision = promote(x, precision) - return T(_x - mod(_x, _precision)) - end - - """ - ceil(x::Period, precision::T) where T <: Union{TimePeriod, Week, Day} -> T - - Rounds `x` up to the nearest multiple of `precision`. If `x` and `precision` are different - subtypes of `Period`, the return value will have the same type as `precision`. - - For convenience, `precision` may be a type instead of a value: `ceil(x, Dates.Hour)` is a - shortcut for `ceil(x, Dates.Hour(1))`. - - ```jldoctest - julia> ceil(Dates.Day(16), Dates.Week) - 3 weeks - - julia> ceil(Dates.Minute(44), Dates.Minute(15)) - 45 minutes - - julia> ceil(Dates.Hour(36), Dates.Day) - 3 days - ``` - - Rounding to a `precision` of `Month`s or `Year`s is not supported, as these `Period`s are of - inconsistent length. - """ - function Base.ceil(x::Compat.ConvertiblePeriod, precision::Compat.ConvertiblePeriod) - f = Base.floor(x, precision) - return (x == f) ? f : f + precision - end - - """ - floorceil(x::Period, precision::T) where T <: Union{TimePeriod, Week, Day} -> (T, T) - - Simultaneously return the `floor` and `ceil` of `Period` at resolution `p`. More efficient - than calling both `floor` and `ceil` individually. - """ - function floorceil(x::Compat.ConvertiblePeriod, precision::Compat.ConvertiblePeriod) - f = Base.floor(x, precision) - return f, (x == f) ? f : f + precision - end - - """ - round(x::Period, precision::T, [r::RoundingMode]) where T <: Union{TimePeriod, Week, Day} -> T - - Rounds `x` to the nearest multiple of `precision`. If `x` and `precision` are different - subtypes of `Period`, the return value will have the same type as `precision`. By default - (`RoundNearestTiesUp`), ties (e.g., rounding 90 minutes to the nearest hour) will be rounded - up. - - For convenience, `precision` may be a type instead of a value: `round(x, Dates.Hour)` is a - shortcut for `round(x, Dates.Hour(1))`. - - ```jldoctest - julia> round(Dates.Day(16), Dates.Week) - 2 weeks - - julia> round(Dates.Minute(44), Dates.Minute(15)) - 45 minutes - - julia> round(Dates.Hour(36), Dates.Day) - 3 days - ``` - - Valid rounding modes for `round(::Period, ::T, ::RoundingMode)` are `RoundNearestTiesUp` - (default), `RoundDown` (`floor`), and `RoundUp` (`ceil`). - - Rounding to a `precision` of `Month`s or `Year`s is not supported, as these `Period`s are of - inconsistent length. - """ - function Base.round(x::Compat.ConvertiblePeriod, precision::Compat.ConvertiblePeriod, r::RoundingMode{:NearestTiesUp}) - f, c = floorceil(x, precision) - _x, _f, _c = promote(x, f, c) - return (_x - _f) < (_c - _x) ? f : c - end - - Base.round(x::Compat.TimeTypeOrPeriod, p::Compat.Dates.Period, r::RoundingMode{:Down}) = Base.floor(x, p) - Base.round(x::Compat.TimeTypeOrPeriod, p::Compat.Dates.Period, r::RoundingMode{:Up}) = Base.ceil(x, p) - - Base.round(::Compat.TimeTypeOrPeriod, p::Compat.Dates.Period, ::RoundingMode) = throw(DomainError(p)) - Base.round(x::Compat.TimeTypeOrPeriod, p::Compat.Dates.Period) = Base.round(x, p, RoundNearestTiesUp) - Base.floor(x::Compat.TimeTypeOrPeriod, ::Type{P}) where P <: Compat.Dates.Period = Base.floor(x, oneunit(P)) - Base.ceil(x::Compat.TimeTypeOrPeriod, ::Type{P}) where P <: Compat.Dates.Period = Base.ceil(x, oneunit(P)) - function Base.round(x::Compat.TimeTypeOrPeriod, ::Type{P}, r::RoundingMode=RoundNearestTiesUp) where P <: Compat.Dates.Period - return Base.round(x, oneunit(P), r) - end -end - -if VERSION < v"0.7.0-DEV.3216" - const AbstractDateTime = Compat.Dates.TimeType -else - const AbstractDateTime = Compat.Dates.AbstractDateTime -end - -if VERSION < v"0.7.0-DEV.3052" - const Printf = Base.Printf -else - import Printf -end - -if VERSION < v"0.7.0-DEV.2655" - @eval module IterativeEigensolvers - using Base: eigs, svds - export eigs, svds - end -elseif VERSION < v"0.7.0-DEV.3019" - @eval module IterativeEigensolvers - using IterativeEigenSolvers: eigs, svds - export eigs, svds - end -end - -@static if VERSION < v"0.7.0-DEV.3449" - const LinearAlgebra = Base.LinAlg -else - import LinearAlgebra -end - -if VERSION < v"0.7.0-DEV.3389" - const SparseArrays = Base.SparseArrays -else - import SparseArrays -end - - -# v"0.7.0-beta.234" introduced Random.gentype (formerly Base.eltype) -# v"0.7.0-beta2.171" deprecated Random.srand in favor of Random.seed! (unexported) -# v"0.7.0-DEV.3406" moved Base.Random to stdlib Random -if VERSION >= v"0.7.0-beta.234" - import Random -else - const exported_random_fields = [ - :AbstractRNG, :MersenneTwister, :RandomDevice, :bitrand, :rand, :rand!, - :randcycle, :randexp, :randexp!, :randjump, :randn!, - :randperm, :randstring, :randsubseq, :randsubseq!, :shuffle, - :shuffle! - ] - const unexported_random_fields = [ - :GLOBAL_RNG, :RangeGenerator - ] - const random_fields = [exported_random_fields; unexported_random_fields] - @eval module Random - if VERSION < v"0.7.0-DEV.3406" - $((:(using Base.Random: $f) for f in random_fields)...) - const seed! = Base.Random.srand - else - $((:(using Random: $f) for f in random_fields)...) - import Random - if VERSION < v"0.7.0-beta2.171" - const seed! = Random.srand - else - using Random: seed! - end - end - if VERSION < v"0.7.0-DEV.3666" - import ..Compat - Base.@deprecate uuid1() Compat.UUIDs.uuid1() false - Base.@deprecate uuid1(rng) Compat.UUIDs.uuid1(rng) false - Base.@deprecate uuid4() Compat.UUIDs.uuid4() false - Base.@deprecate uuid4(rng) Compat.UUIDs.uuid4(rng) false - Base.@deprecate uuid_version(u) Compat.UUIDs.uuid_version(u) false - end - - gentype(args...) = eltype(args...) - - export $(exported_random_fields...) - end -end - -if VERSION < v"0.7.0-DEV.3589" - const Markdown = Base.Markdown -else - import Markdown -end - -if VERSION < v"0.7.0-DEV.2609" - @eval module SuiteSparse - if Base.USE_GPL_LIBS - using Compat.SparseArrays: CHOLMOD, SPQR, UMFPACK - end - using Compat.SparseArrays: increment, increment!, decrement, decrement! - end -end - -@static if VERSION < v"0.7.0-DEV.3500" - const REPL = Base.REPL -else - import REPL -end - -if VERSION < v"0.7.0-DEV.3476" - @eval module Serialization - import Base.Serializer: serialize, deserialize, SerializationState, serialize_type - export serialize, deserialize - @static if VERSION < v"1.0.0-DEV.44" - export SerializationState - end - end -else - import Serialization -end - -if VERSION < v"0.7.0-beta.85" - @eval module Statistics - if VERSION < v"0.7.0-DEV.4064" - varm(A::AbstractArray, m; dims=nothing, kwargs...) = - dims===nothing ? Base.varm(A, m; kwargs...) : Base.varm(A, m, dims; kwargs...) - if VERSION < v"0.7.0-DEV.755" - cov(a::AbstractMatrix; dims=1, corrected=true) = Base.cov(a, dims, corrected) - cov(a::AbstractVecOrMat, b::AbstractVecOrMat; dims=1, corrected=true) = - Base.cov(a, b, dims, corrected) - else - cov(a::AbstractMatrix; dims=nothing, kwargs...) = - dims===nothing ? Base.cov(a; kwargs...) : Base.cov(a, dims; kwargs...) - cov(a::AbstractVecOrMat, b::AbstractVecOrMat; dims=nothing, kwargs...) = - dims===nothing ? Base.cov(a, b; kwargs...) : Base.cov(a, b, dims; kwargs...) - end - cor(a::AbstractMatrix; dims=nothing) = dims===nothing ? Base.cor(a) : Base.cor(a, dims) - cor(a::AbstractVecOrMat, b::AbstractVecOrMat; dims=nothing) = - dims===nothing ? Base.cor(a, b) : Base.cor(a, b, dims) - mean(a::AbstractArray; dims=nothing) = dims===nothing ? Base.mean(a) : Base.mean(a, dims) - median(a::AbstractArray; dims=nothing) = dims===nothing ? Base.median(a) : Base.median(a, dims) - var(a::AbstractArray; dims=nothing, kwargs...) = - dims===nothing ? Base.var(a; kwargs...) : Base.var(a, dims; kwargs...) - std(a::AbstractArray; dims=nothing, kwargs...) = - dims===nothing ? Base.std(a; kwargs...) : Base.std(a, dims; kwargs...) - end - export cor, cov, std, stdm, var, varm, mean!, mean, median!, median, middle, quantile!, quantile - end -else - import Statistics -end - -@static if VERSION < v"0.7.0-DEV.4592" - struct Fix2{F,T} <: Function - f::F - x::T - Fix2(f::F, x::T) where {F,T} = new{F,T}(f, x) - Fix2(f::Type{F}, x::T) where {F,T} = new{F,T}(f, x) - end - (f::Fix2)(y) = f.f(y, f.x) - - Base.:(==)(x) = Fix2(==, x) - @static if VERSION >= v"0.7.0-DEV.1993" - Base.isequal(x) = Base.equalto(x) - else - Base.isequal(x) = Fix2(isequal, x) - end - @static if VERSION >= v"0.7.0-DEV.3272" - Base.in(x) = Base.occursin(x) - else - Base.in(x) = Fix2(in, x) - end -else - import Base: Fix2 -end -# keep these definitions to be non breaking for 0.6 usage -@static if VERSION < v"0.7.0-DEV.1993" - const EqualTo{T} = Fix2{typeof(isequal),T} - export equalto - equalto(x) = isequal(x) -end -@static if VERSION < v"0.7.0-DEV.3272" - const OccursIn{T} = Fix2{typeof(in),T} - export occursin - occursin(x) = in(x) -end - -# PR #26283 -if VERSION < v"0.7.0-DEV.4639" - if isdefined(Base, :occursin) - import Base: occursin - else - export occursin - end - occursin(needle, haystack) = contains(haystack, needle) - if VERSION < v"0.7.0-DEV.3272" - occursin(r::Regex, s::AbstractString; offset::Integer = 0) = ismatch(r, s, offset) - else - occursin(r::Regex, s::AbstractString; offset::Integer = 0) = contains(s, r, offset) - end - # PR #22435 - if VERSION < v"0.7.0-DEV.702" - occursin(needle::Char, haystack::AbstractString) = searchindex(haystack,needle) != 0 - end -end - - -# 0.7.0-DEV.912 -if VERSION < v"0.7.0-DEV.912" - import Base.* - (*)(s1::Union{Char,AbstractString}, ss::Union{Char,AbstractString}...) = string(s1, ss...) -end - -# 0.7.0-DEV.2318 -@static if !isdefined(Base, :BitSet) - const BitSet = IntSet - export BitSet -end - -# 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 -else - import Base.Base64 -end - -@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...) - # needed for ambiguity resolution - Base.IOContext(io::IOContext, arg1::Pair, arg2::Pair) = IOContext(IOContext(io, arg1), arg2) -end - -# 0.7.0-DEV.4527 -@static if !isdefined(Base, :UndefInitializer) - import Base: Array, Matrix, Vector - @static if isdefined(Base, :Uninitialized) - useuninit(args) = (Base.uninitialized, args...) - else - useuninit(args) = args - end - struct UndefInitializer end - const undef = UndefInitializer() - export undef, UndefInitializer - Base.show(io::IO, ::UndefInitializer) = - print(io, "array initializer with undefined values") - Array{T}(::UndefInitializer, args...) where {T} = Array{T}(useuninit(args)...) - Array{T,N}(::UndefInitializer, args...) where {T,N} = Array{T,N}(useuninit(args)...) - Vector(::UndefInitializer, args...) = Vector(useuninit(args)...) - Matrix(::UndefInitializer, args...) = Matrix(useuninit(args)...) - - BitArray{N}(::UndefInitializer, args...) where {N} = BitArray{N}(useuninit(args)...) - BitArray(::UndefInitializer, args...) = BitArray(useuninit(args)...) -end -@static if VERSION < v"0.7.0-DEV.2581" - export uninitialized, Uninitialized - const uninitialized = undef - const Uninitialized = UndefInitializer -end - -# 0.7.0-DEV.1499 -if VERSION < v"0.7.0-DEV.1499" - function Base.get(f::Base.Callable, ::Base.EnvHash, k::AbstractString) - Base.access_env(k->f(), k) - end -end - -# 0.7.0-DEV.2919 -@static if !isdefined(Base, :ComplexF16) - const ComplexF16 = Complex{Float16} - export ComplexF16 -end -@static if !isdefined(Base, :ComplexF32) - const ComplexF32 = Complex{Float32} - export ComplexF32 -end -@static if !isdefined(Base, :ComplexF64) - const ComplexF64 = Complex{Float64} - export ComplexF64 -end - -# julia #26365 -@static if isdefined(LinearAlgebra, :tr) - const tr = LinearAlgebra.tr -else - # 0.6 - const tr = LinearAlgebra.trace -end - -if VERSION < v"0.7.0-DEV.1930" - # no textwidth definition in Base - export textwidth - textwidth(c::Char) = charwidth(c) - textwidth(c::AbstractString) = strwidth(c) -elseif v"0.7.0-DEV.2915" ≤ VERSION < v"0.7.0-DEV.3393" - # textwidth definition moved to Unicode module - import Unicode - const textwidth = Unicode.textwidth - export textwidth -end - -# 0.7.0-DEV.2915 -module Unicode - export graphemes, textwidth, isvalid, - islower, isupper, isalpha, isdigit, isxdigit, isnumeric, isalnum, - iscntrl, ispunct, isspace, isprint, isgraph, - lowercase, uppercase, titlecase, lcfirst, ucfirst - - if VERSION < v"0.7.0-DEV.2915" - if VERSION < v"0.7.0-DEV.1930" - import ..Compat: textwidth - end - - isnumeric(c::Char) = isnumber(c) - isassigned(c) = is_assigned_char(c) - normalize(s::AbstractString; kws...) = normalize_string(s; kws...) - normalize(s::AbstractString, nf::Symbol) = normalize_string(s, nf) - else - using Unicode - import Unicode: isassigned, normalize # not exported from Unicode module due to conflicts - end -end - -# 0.7.0-DEV.3393 -@static if VERSION < v"0.7.0-DEV.3393" - import .Unicode.isnumeric - export isnumeric -end - -# 0.7.0-DEV.2951 -@static if !isdefined(Base, :AbstractDict) - const AbstractDict = Associative - export AbstractDict -end - -# 0.7.0-DEV.2978 -@static if !isdefined(Base, :axes) - const axes = Base.indices - # NOTE: Intentionally not exported to avoid conflicts with AxisArrays - #export axes -end - -# 0.7.0-DEV.3137 -@static if !isdefined(Base, :Nothing) - const Nothing = Void - const Cvoid = Void - export Nothing, Cvoid -end - -@static if !isdefined(Base, :Some) - import Base: promote_rule, convert - struct Some{T} - value::T - end - promote_rule(::Type{Some{T}}, ::Type{Some{S}}) where {T,S<:T} = Some{T} - promote_rule(::Type{Some{T}}, ::Type{Nothing}) where {T} = Union{Some{T}, Nothing} - convert(::Type{Some{T}}, x::Some) where {T} = Some{T}(convert(T, x.value)) - convert(::Type{Union{Some{T}, Nothing}}, x::Some) where {T} = convert(Some{T}, x) - - convert(::Type{Union{T, Nothing}}, x::Any) where {T} = convert(T, x) - convert(::Type{Nothing}, x::Any) = throw(MethodError(convert, (Nothing, x))) - convert(::Type{Nothing}, x::Nothing) = nothing - - # Note: this is the definition of coalasce prior to 0.7.0-DEV.5278; kept to avoid - # breakage in packages already using it - coalesce(x::Any) = x - coalesce(x::Some) = x.value - coalesce(x::Nothing) = nothing - #coalesce(x::Missing) = missing - coalesce(x::Any, y...) = x - coalesce(x::Some, y...) = x.value - coalesce(x::Nothing, y...) = coalesce(y...) - #coalesce(x::Union{Nothing, Missing}, y...) = coalesce(y...) - - notnothing(x::Any) = x - notnothing(::Nothing) = throw(ArgumentError("nothing passed to notnothing")) - export Some, coalesce -else - import Base: notnothing -end - -# 0.7.0-DEV.3309 -@static if VERSION < v"0.7.0-DEV.3309" - const IteratorSize = Base.iteratorsize - const IteratorEltype = Base.iteratoreltype -else - const IteratorSize = Base.IteratorSize - const IteratorEltype = Base.IteratorEltype -end - -# 0.7.0-DEV.3173 -@static if !isdefined(Base, :invpermute!) - const invpermute! = ipermute! - export invpermute! -end - -@static if VERSION < v"0.7.0-DEV.3172" - Base.replace(s::AbstractString, pat_rep::Pair; count::Integer=typemax(Int)) = - replace(s, first(pat_rep), last(pat_rep), count) -end - -# 0.7.0-DEV.3057 -@static if !isdefined(Base, :copyto!) - const copyto! = Base.copy! - const unsafe_copyto! = Base.unsafe_copy! - export copyto!, unsafe_copyto! -end - -# 0.7.0-DEV.3272, keep this definition for 0.6 compatibility -@static if VERSION < v"0.7.0-DEV.3272" - Base.contains(str::AbstractString, r::Regex) = ismatch(r, str) -end - -@static if VERSION < v"0.7.0-DEV.3025" - import Base: convert, ndims, getindex, size, length, eltype, - start, next, done, first, last, in, tail - export CartesianIndices, LinearIndices - - struct CartesianIndices{N,R<:NTuple{N,AbstractUnitRange{Int}}} <: AbstractArray{CartesianIndex{N},N} - indices::R - end - - CartesianIndices(::Tuple{}) = CartesianIndices{0,typeof(())}(()) - CartesianIndices(inds::NTuple{N,AbstractUnitRange{Int}}) where {N} = - CartesianIndices{N,typeof(inds)}(inds) - CartesianIndices(inds::Vararg{AbstractUnitRange{Int},N}) where {N} = - CartesianIndices(inds) - CartesianIndices(inds::NTuple{N,AbstractUnitRange{<:Integer}}) where {N} = - CartesianIndices(map(r->convert(AbstractUnitRange{Int}, r), inds)) - CartesianIndices(inds::Vararg{AbstractUnitRange{<:Integer},N}) where {N} = - CartesianIndices(inds) - - CartesianIndices(index::CartesianIndex) = CartesianIndices(index.I) - CartesianIndices(sz::NTuple{N,<:Integer}) where {N} = CartesianIndices(map(Base.OneTo, sz)) - CartesianIndices(inds::NTuple{N,Union{<:Integer,AbstractUnitRange{<:Integer}}}) where {N} = - CartesianIndices(map(i->first(i):last(i), inds)) - - CartesianIndices(A::AbstractArray) = CartesianIndices(axes(A)) - - convert(::Type{Tuple{}}, R::CartesianIndices{0}) = () - convert(::Type{NTuple{N,AbstractUnitRange{Int}}}, R::CartesianIndices{N}) where {N} = - R.indices - - convert(::Type{NTuple{N,AbstractUnitRange}}, R::CartesianIndices{N}) where {N} = - convert(NTuple{N,AbstractUnitRange{Int}}, R) - convert(::Type{NTuple{N,UnitRange{Int}}}, R::CartesianIndices{N}) where {N} = - UnitRange{Int}.(convert(NTuple{N,AbstractUnitRange}, R)) - convert(::Type{NTuple{N,UnitRange}}, R::CartesianIndices{N}) where {N} = - UnitRange.(convert(NTuple{N,AbstractUnitRange}, R)) - convert(::Type{Tuple{Vararg{AbstractUnitRange{Int}}}}, R::CartesianIndices{N}) where {N} = - convert(NTuple{N,AbstractUnitRange{Int}}, R) - convert(::Type{Tuple{Vararg{AbstractUnitRange}}}, R::CartesianIndices) = - convert(Tuple{Vararg{AbstractUnitRange{Int}}}, R) - convert(::Type{Tuple{Vararg{UnitRange{Int}}}}, R::CartesianIndices{N}) where {N} = - convert(NTuple{N,UnitRange{Int}}, R) - convert(::Type{Tuple{Vararg{UnitRange}}}, R::CartesianIndices) = - convert(Tuple{Vararg{UnitRange{Int}}}, R) - - # AbstractArray implementation - Base.IndexStyle(::Type{CartesianIndices{N,R}}) where {N,R} = IndexCartesian() - @inline Base.getindex(iter::CartesianIndices{N,R}, I::Vararg{Int, N}) where {N,R} = CartesianIndex(first.(iter.indices) .- 1 .+ I) - - ndims(R::CartesianIndices) = ndims(typeof(R)) - ndims(::Type{CartesianIndices{N}}) where {N} = N - ndims(::Type{CartesianIndices{N,TT}}) where {N,TT} = N - - eltype(R::CartesianIndices) = eltype(typeof(R)) - eltype(::Type{CartesianIndices{N}}) where {N} = CartesianIndex{N} - eltype(::Type{CartesianIndices{N,TT}}) where {N,TT} = CartesianIndex{N} - Base.iteratorsize(::Type{<:CartesianIndices}) = Base.HasShape() - - @inline function start(iter::CartesianIndices) - iterfirst, iterlast = first(iter), last(iter) - if Base.any(map(>, iterfirst.I, iterlast.I)) - return iterlast+1 - end - iterfirst - end - @inline function next(iter::CartesianIndices, state) - state, CartesianIndex(inc(state.I, first(iter).I, last(iter).I)) - end - # increment & carry - @inline inc(::Tuple{}, ::Tuple{}, ::Tuple{}) = () - @inline inc(state::Tuple{Int}, start::Tuple{Int}, stop::Tuple{Int}) = (state[1]+1,) - @inline function inc(state, start, stop) - if state[1] < stop[1] - return (state[1]+1,Base.tail(state)...) - end - newtail = inc(Base.tail(state), Base.tail(start), Base.tail(stop)) - (start[1], newtail...) - end - @inline done(iter::CartesianIndices, state) = state.I[end] > last(iter.indices[end]) - - # 0-d cartesian ranges are special-cased to iterate once and only once - start(iter::CartesianIndices{0}) = false - next(iter::CartesianIndices{0}, state) = CartesianIndex(), true - done(iter::CartesianIndices{0}, state) = state - - size(iter::CartesianIndices) = map(dimlength, first(iter).I, last(iter).I) - dimlength(start, stop) = stop-start+1 - - length(iter::CartesianIndices) = Base.prod(size(iter)) - - first(iter::CartesianIndices) = CartesianIndex(map(first, iter.indices)) - last(iter::CartesianIndices) = CartesianIndex(map(last, iter.indices)) - - @inline function in(i::CartesianIndex{N}, r::CartesianIndices{N}) where {N} - _in(true, i.I, first(r).I, last(r).I) - end - _in(b, ::Tuple{}, ::Tuple{}, ::Tuple{}) = b - @inline _in(b, i, start, stop) = _in(b & (start[1] <= i[1] <= stop[1]), tail(i), tail(start), tail(stop)) - - struct LinearIndices{N,R<:NTuple{N,AbstractUnitRange{Int}}} <: AbstractArray{Int,N} - indices::R - end - - LinearIndices(inds::CartesianIndices{N,R}) where {N,R} = LinearIndices{N,R}(inds.indices) - LinearIndices(::Tuple{}) = LinearIndices(CartesianIndices(())) - LinearIndices(inds::NTuple{N,AbstractUnitRange{Int}}) where {N} = LinearIndices(CartesianIndices(inds)) - LinearIndices(inds::Vararg{AbstractUnitRange{Int},N}) where {N} = LinearIndices(CartesianIndices(inds)) - LinearIndices(inds::NTuple{N,AbstractUnitRange{<:Integer}}) where {N} = LinearIndices(CartesianIndices(inds)) - LinearIndices(inds::Vararg{AbstractUnitRange{<:Integer},N}) where {N} = LinearIndices(CartesianIndices(inds)) - LinearIndices(index::CartesianIndex) = LinearIndices(CartesianIndices(index)) - LinearIndices(sz::NTuple{N,<:Integer}) where {N} = LinearIndices(CartesianIndices(sz)) - LinearIndices(inds::NTuple{N,Union{<:Integer,AbstractUnitRange{<:Integer}}}) where {N} = LinearIndices(CartesianIndices(inds)) - LinearIndices(A::AbstractArray) = LinearIndices(CartesianIndices(A)) - - # AbstractArray implementation - Base.IndexStyle(::Type{LinearIndices{N,R}}) where {N,R} = IndexCartesian() - Compat.axes(iter::LinearIndices{N,R}) where {N,R} = iter.indices - Base.size(iter::LinearIndices{N,R}) where {N,R} = length.(iter.indices) - @inline function Base.getindex(iter::LinearIndices{N,R}, I::Vararg{Int, N}) where {N,R} - dims = length.(iter.indices) - #without the inbounds, this is slower than Base._sub2ind(iter.indices, I...) - @inbounds result = reshape(1:Base.prod(dims), dims)[(I .- first.(iter.indices) .+ 1)...] - return result - end -elseif VERSION < v"0.7.0-DEV.3395" - Base.size(iter::LinearIndices{N,R}) where {N,R} = length.(iter.indices) -end - -@static if !isdefined(Base, Symbol("@info")) - macro info(msg, args...) - return :(info($(esc(msg)), prefix = "Info: ")) - end -end -@static if !isdefined(Base, Symbol("@warn")) - macro warn(msg, args...) - return :(warn($(esc(msg)), prefix = "Warning: ")) - end -end - -const DEBUG = Ref(false) # debug printing off by default, as on 0.7 -enable_debug(x::Bool) = DEBUG[] = x -@static if !isdefined(Base, Symbol("@debug")) - function debug(msg) - DEBUG[] || return - buf = Base.IOBuffer() - iob = Base.redirect(IOContext(buf, STDERR), Base.log_info_to, :debug) - print_with_color(:blue, iob, "Debug: "; bold = true) - Base.println_with_color(:blue, iob, chomp(string(msg))) - print(STDERR, String(take!(buf))) - return - end - macro debug(msg, args...) - return :(debug($(esc(msg)))) - end -end -@static if !isdefined(Base, Symbol("@error")) - function _error(msg) - buf = Base.IOBuffer() - iob = Base.redirect(IOContext(buf, STDERR), Base.log_error_to, :error) - print_with_color(Base.error_color(), iob, "Error: "; bold = true) - Base.println_with_color(Base.error_color(), iob, chomp(string(msg))) - print(STDERR, String(take!(buf))) - return - end - macro error(msg, args...) - return :(_error($(esc(msg)))) - end -end - -# 0.7.0-DEV.3415 -if !isdefined(Base, :findall) - const findall = find - export findall -end - -@static if !isdefined(Base, :argmin) - if VERSION >= v"0.7.0-DEV.1660" # indmin/indmax return key - const argmin = indmin - const argmax = indmax - else - argmin(x::AbstractArray) = CartesianIndex(ind2sub(x, indmin(x))) - argmin(x::AbstractVector) = indmin(x) - argmin(x::Associative) = first(Iterators.drop(keys(x), indmin(values(x))-1)) - argmin(x::Tuple) = indmin(x) - argmax(x::AbstractArray) = CartesianIndex(ind2sub(x, indmax(x))) - argmax(x::AbstractVector) = indmax(x) - argmax(x::Associative) = first(Iterators.drop(keys(x), indmax(values(x))-1)) - argmax(x::Tuple) = indmax(x) - end - export argmin, argmax -end - -@static if !isdefined(Base, :parentmodule) - parentmodule(m::Module) = Base.module_parent(m) - parentmodule(f::Function) = Base.function_module(f) - parentmodule(@nospecialize(f), @nospecialize(t)) = Base.function_module(f, t) - parentmodule(t::DataType) = Base.datatype_module(t) - parentmodule(t::UnionAll) = Base.datatype_module(Base.unwrap_unionall(t)) - export parentmodule -end - -@static if !isdefined(Base, :codeunits) - codeunits(s::String) = Vector{UInt8}(s) - ncodeunits(s::Union{String,SubString{String}}) = sizeof(s) - codeunits(s::SubString{String}) = view(codeunits(s.string),1+s.offset:s.offset+sizeof(s)) - export codeunits, ncodeunits -end - -@static if !isdefined(Base, :nameof) - nameof(m::Module) = Base.module_name(m) - nameof(f::Function) = Base.function_name(f) - nameof(t::Union{DataType,UnionAll}) = Base.datatype_name(t) - export nameof -end - -# 0.7.0-DEV.3469 -@static if !isdefined(Base, :GC) - @eval module GC - using Base: gc - const enable = Base.gc_enable - end - export GC -end - -if VERSION < v"0.7.0-DEV.2954" - const Distributed = Base.Distributed -else - import Distributed -end - -@static if VERSION < v"0.7.0-DEV.3656" - const Pkg = Base.Pkg -else - import Pkg -end - -@static if VERSION < v"0.7.0-DEV.3630" - @eval module InteractiveUtils - using Base: @code_llvm, @code_lowered, @code_native, @code_typed, - @code_warntype, @edit, @functionloc, @less, @which, - apropos, code_llvm, code_native, code_warntype, edit, - less, methodswith, subtypes, versioninfo - export @code_llvm, @code_lowered, @code_native, @code_typed, - @code_warntype, @edit, @functionloc, @less, @which, - apropos, code_llvm, code_native, code_warntype, edit, - less, methodswith, subtypes, versioninfo - - @static if VERSION >= v"0.7.0-DEV.2582" - using Base: varinfo - export varinfo - else - const varinfo = whos - export varinfo - end - end -else - import InteractiveUtils -end - -@static if VERSION < v"0.7.0-DEV.3724" - const LibGit2 = Base.LibGit2 -else - import LibGit2 -end - -# 0.7.0-DEV.2695 -@static if !isdefined(Base, :AbstractDisplay) - const AbstractDisplay = Display - export AbstractDisplay -end - -# 0.7.0-DEV.3481 -@static if !isdefined(Base, :bytesavailable) - const bytesavailable = nb_available - export bytesavailable -end - -# 0.7.0-DEV.3583 -@static if !isdefined(Base, :lastindex) - const lastindex = endof - export lastindex - firstindex(a::AbstractArray) = (Base.@_inline_meta; first(linearindices(a))) - firstindex(c::Char) = 1 - firstindex(c::Number) = 1 - firstindex(p::Pair) = 1 - firstindex(cmd::Cmd) = firstindex(cmd.exec) - firstindex(s::AbstractString) = 1 - firstindex(t::Tuple) = 1 - export firstindex -end - -# 0.7.0-DEV.3585 -@static if !isdefined(Base, :printstyled) - printstyled(io::IO, msg...; bold=false, color=:normal) = - Base.print_with_color(color, io, msg...; bold=bold) - printstyled(msg...; bold=false, color=:normal) = - Base.print_with_color(color, STDOUT, msg...; bold=bold) - export printstyled -end - -# 0.7.0-DEV.3455 -@static if !isdefined(Base, :hasmethod) - const hasmethod = method_exists - export hasmethod -end -@static if !isdefined(Base, :objectid) - const objectid = object_id - export objectid -end - -@static if VERSION < v"0.7.0-DEV.3272" - zero2nothing(x::Integer) = x == 0 ? nothing : x - zero2nothing(x::AbstractUnitRange{<:Integer}) = x == 0:-1 ? nothing : x - zero2nothing(x) = x - - findnext(xs...) = zero2nothing(Base.findnext(xs...)) - findfirst(xs...) = zero2nothing(Base.findfirst(xs...)) - findprev(xs...) = zero2nothing(Base.findprev(xs...)) - findlast(xs...) = zero2nothing(Base.findlast(xs...)) - - Base.findnext(r::Regex, s::AbstractString, idx::Integer) = search(s, r, idx) - Base.findfirst(r::Regex, s::AbstractString) = search(s, r) - Base.findnext(c::Fix2{typeof(isequal),Char}, s::AbstractString, i::Integer) = search(s, c.x, i) - Base.findfirst(c::Fix2{typeof(isequal),Char}, s::AbstractString) = search(s, c.x) - Base.findnext(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}, i::Integer) = - search(a, b.x, i) - Base.findfirst(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}) = - search(a, b.x) - - Base.findnext(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}}, - s::AbstractString, i::Integer) = - search(s, c.x, i) - Base.findfirst(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}}, - s::AbstractString) = - search(s, c.x) - Base.findnext(t::AbstractString, s::AbstractString, i::Integer) = search(s, t, i) - Base.findfirst(t::AbstractString, s::AbstractString) = search(s, t) - - Base.findfirst(delim::Fix2{typeof(isequal),UInt8}, buf::Base.IOBuffer) = search(buf, delim.x) - - Base.findprev(c::Fix2{typeof(isequal),Char}, s::AbstractString, i::Integer) = rsearch(s, c.x, i) - Base.findlast(c::Fix2{typeof(isequal),Char}, s::AbstractString) = rsearch(s, c.x) - Base.findprev(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}, i::Integer) = - rsearch(a, b.x, i) - Base.findlast(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}) = - rsearch(a, b.x) - - Base.findprev(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}}, - s::AbstractString, i::Integer) = rsearch(s, c.x, i) - Base.findlast(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}}, - s::AbstractString) = rsearch(s, c.x) - Base.findprev(t::AbstractString, s::AbstractString, i::Integer) = rsearch(s, t, i) - Base.findlast(t::AbstractString, s::AbstractString) = rsearch(s, t) - - findall(b::Fix2{typeof(in)}, a) = findin(a, b.x) - # To fix ambiguity - findall(b::Fix2{typeof(in)}, a::Number) = a in b.x ? [1] : Vector{Int}() -end - -@static if VERSION < v"0.7.0-DEV.4047" #26089 - showable(mime, x) = mimewritable(mime, x) - export showable -end - -@static if VERSION < v"0.7.0-DEV.4010" #25990 - Base.repr(mime::Union{AbstractString,MIME}, x) = reprmime(mime, x) -end - -# https://github.com/JuliaLang/julia/pull/25647 -@static if VERSION < v"0.7.0-DEV.3526" - names(m; all=false, imported=false) = Base.names(m, all, imported) -end - -if VERSION >= v"0.7.0-DEV.3666" - import UUIDs -else - @eval module UUIDs - if VERSION < v"0.7.0-DEV.3406" - import Base.Random: uuid1, uuid4, uuid_version, UUID - else - import Random: uuid1, uuid4, uuid_version, UUID - end - export uuid1, uuid4, uuid_version, UUID - end -end - -# https://github.com/JuliaLang/julia/pull/26670 -@static if VERSION < v"0.7.0-DEV.4062" - trunc(x; digits = 0, base = 10) = Base.trunc(x, digits, base) - floor(x; digits = 0, base = 10) = Base.floor(x, digits, base) - ceil(x; digits = 0, base = 10) = Base.ceil(x, digits, base) - function round(x; digits = nothing, sigdigits = nothing, base = 10) - if digits === nothing - if sigdigits === nothing - Base.round(x, 0, base) - else - Base.signif(x, sigdigits, base) - end - else - sigdigits === nothing || throw(AgrumentError("`round` cannot use both `digits` and `sigdigits` arguments")) - Base.round(x, digits, base) - end - end -elseif VERSION < v"0.7.0-DEV.4804" - trunc(x; digits = 0, base = 10) = Base.trunc(x, digits, base = base) - floor(x; digits = 0, base = 10) = Base.floor(x, digits, base = base) - ceil(x; digits = 0, base = 10) = Base.ceil(x, digits, base = base) - function round(x; digits = nothing, sigdigits = nothing, base = 10) - if digits === nothing - if sigdigits === nothing - Base.round(x, 0, base = base) - else - Base.signif(x, sigdigits, base = base) - end - else - sigdigits === nothing || throw(AgrumentError("`round` cannot use both `digits` and `sigdigits` arguments")) - Base.round(x, digits, base = base) - end - end -elseif VERSION < v"0.7.0-beta2.86" - # https://github.com/JuliaLang/julia/pull/28199 - trunc(x; digits = 0, base = 10) = Base.trunc(x, digits = digits, base = base) - floor(x; digits = 0, base = 10) = Base.floor(x, digits = digits, base = base) - ceil(x; digits = 0, base = 10) = Base.ceil(x, digits = digits, base = base) - function round(x; digits = nothing, sigdigits = nothing, base = 10) - if digits === nothing && sigdigits === nothing - Base.round(x, digits = 0, base = base) - else - Base.round(x, digits = digits, sigdigits = sigdigits, base = base) - end - end -else - trunc(x; digits = 0, base = 10) = Base.trunc(x, digits = digits, base = base) - floor(x; digits = 0, base = 10) = Base.floor(x, digits = digits, base = base) - ceil(x; digits = 0, base = 10) = Base.ceil(x, digits = digits, base = base) - round(x; digits = nothing, sigdigits = nothing, base = 10) = Base.round(x, digits = digits, sigdigits = sigdigits, base = base) -end - -# https://github.com/JuliaLang/julia/pull/25872 -if VERSION < v"0.7.0-DEV.3734" - if isdefined(Base, :open_flags) - import Base.open_flags - else - # copied from Base: - function open_flags(; read=nothing, write=nothing, create=nothing, truncate=nothing, append=nothing) - if write === true && read !== true && append !== true - create === nothing && (create = true) - truncate === nothing && (truncate = true) - end - if truncate === true || append === true - write === nothing && (write = true) - create === nothing && (create = true) - end - write === nothing && (write = false) - read === nothing && (read = !write) - create === nothing && (create = false) - truncate === nothing && (truncate = false) - append === nothing && (append = false) - return (read, write, create, truncate, append) - end - end - function IOBuffer( - data::Union{AbstractVector{UInt8},Nothing}=nothing; - read::Union{Bool,Nothing}=data === nothing ? true : nothing, - write::Union{Bool,Nothing}=data === nothing ? true : nothing, - truncate::Union{Bool,Nothing}=data === nothing ? true : nothing, - maxsize::Integer=typemax(Int), - sizehint::Union{Integer,Nothing}=nothing) - flags = open_flags(read=read, write=write, append=nothing, truncate=truncate) - if maxsize < 0 - throw(ArgumentError("negative maxsize: $(maxsize)")) - end - if data !== nothing - if sizehint !== nothing - sizehint!(data, sizehint) - end - buf = Base.IOBuffer(data, flags[1], flags[2], Int(maxsize)) - else - size = sizehint !== nothing ? Int(sizehint) : maxsize != typemax(Int) ? Int(maxsize) : 32 - buf = Base.IOBuffer(Base.StringVector(size), flags[1], flags[2], Int(maxsize)) - buf.data[:] = 0 - end - if flags[4] # flags.truncate - buf.size = 0 - end - return buf - end -end - -@static if VERSION < v"0.7.0-DEV.3986" - const LinRange = Base.LinSpace - export LinRange - - function range(start; step=nothing, stop=nothing, length=nothing) - have_step = step !== nothing - have_stop = stop !== nothing - have_length = length !== nothing - - if !(have_stop || have_length) - throw(ArgumentError("At least one of `length` or `stop` must be specified")) - elseif have_step && have_stop && have_length - throw(ArgumentError("Too many arguments specified; try passing only one of `stop` or `length`")) - elseif start === nothing - throw(ArgumentError("Can't start a range at `nothing`")) - end - - if have_stop && !have_length - return have_step ? (start:step:stop) : (start:stop) - elseif have_length && !have_stop - return have_step ? Base.range(start, step, length) : Base.range(start, length) - elseif !have_step - return linspace(start, stop, length) - end - end -elseif VERSION < v"1.0.0-DEV.57" - import Base: LinRange - range(start; kwargs...) = Base.range(start; kwargs...) -else - import Base: range # import as it is further extended below -end - -@static if VERSION < v"0.7.0-DEV.3995" - cp(src::AbstractString, dst::AbstractString; force::Bool=false, follow_symlinks::Bool=false) = - Base.cp(src, dst; remove_destination = force, follow_symlinks = follow_symlinks) - mv(src::AbstractString, dst::AbstractString; force::Bool=false) = - Base.mv(src, dst; remove_destination = force) -end - -if VERSION < v"0.7.0-DEV.3972" - function indexin(a, b::AbstractArray) - inds = keys(b) - bdict = Dict{eltype(b),eltype(inds)}() - for (val, ind) in zip(b, inds) - get!(bdict, val, ind) - end - return Union{eltype(inds), Nothing}[ - get(bdict, i, nothing) for i in a - ] - end -end - -if VERSION < v"0.7.0-DEV.4585" - export isuppercase, islowercase, uppercasefirst, lowercasefirst - const isuppercase = isupper - const islowercase = islower - const uppercasefirst = ucfirst - const lowercasefirst = lcfirst -end - -if VERSION < v"0.7.0-DEV.4064" - for f in (:mean, :median, :var, :varm, :std, :cov, :cor) - @eval import .Statistics: $f # compatibility with old Compat versions - end - for f in (:cumsum, :cumprod, :sum, :prod, :maximum, :minimum, :all, :any) - @eval begin - $f(a::AbstractArray; dims=nothing) = - dims===nothing ? Base.$f(a) : Base.$f(a, dims) - end - end - for f in (:sum, :prod, :maximum, :minimum, :all, :any, :accumulate) - @eval begin - $f(f, a::AbstractArray; dims=nothing) = - dims===nothing ? Base.$f(f, a) : Base.$f(f, a, dims) - end - end - for f in (:findmax, :findmin) - @eval begin - $f(a::AbstractVector; dims=nothing) = - dims===nothing ? Base.$f(a) : Base.$f(a, dims) - function $f(a::AbstractArray; dims=nothing) - vs, inds = dims===nothing ? Base.$f(a) : Base.$f(a, dims) - cis = CartesianIndices(a) - return (vs, map(i -> cis[i], inds)) - end - end - end - @eval sort(a::AbstractArray; dims=nothing, kwargs...) = - dims===nothing ? Base.sort(a; kwargs...) : Base.sort(a, dims; kwargs...) - for f in (:cumsum!, :cumprod!) - @eval $f(out, a; dims=nothing) = - dims===nothing ? Base.$f(out, a) : Base.$f(out, a, dims) - end -end -if VERSION < v"0.7.0-DEV.4064" - mapreduce(f, op, a::AbstractArray; dims=nothing, init=nothing) = - init === nothing ? (dims===nothing ? Base.mapreduce(f, op, a) : Base.mapreducedim(f, op, a, dims)) : - (dims===nothing ? Base.mapreduce(f, op, init, a) : Base.mapreducedim(f, op, a, dims, init)) - reduce(op, a::AbstractArray; dims=nothing, init=nothing) = - init === nothing ? (dims===nothing ? Base.reduce(op, a) : Base.reducedim(op, a, dims)) : - (dims===nothing ? Base.reduce(op, init, a) : Base.reducedim(op, a, dims, init)) - accumulate!(op, out, a; dims=nothing) = - dims===nothing ? Base.accumulate!(op, out, a) : Base.accumulate!(op, out, a, dims) - # kept for compatibility with early adopters - mapreduce(f, op, v0, a::AbstractArray; dims=nothing) = - mapreduce(f, op, a, dims=dims, init=v0) - reduce(op, v0, a::AbstractArray; dims=nothing) = - reduce(op, a, dims=dims, init=v0) -elseif VERSION < v"0.7.0-beta.81" # julia#27711 - mapreduce(f, op, a::AbstractArray; dims=nothing, init=nothing) = - init === nothing ? (dims===nothing ? Base.mapreduce(f, op, a) : Base.mapreduce(f, op, a, dims=dims)) : - (dims===nothing ? Base.mapreduce(f, op, init, a) : Base.mapreduce(f, op, init, a, dims=dims)) - reduce(op, a::AbstractArray; dims=nothing, init=nothing) = - init === nothing ? (dims===nothing ? Base.reduce(op, a) : Base.reduce(op, a, dims=dims)) : - (dims===nothing ? Base.reduce(op, init, a) : Base.reduce(op, init, a, dims=dims)) -end -if VERSION < v"0.7.0-beta.81" # julia#27711 - mapreduce(f, op, itr; init=nothing) = - init === nothing ? Base.mapreduce(f, op, itr) : Base.mapreduce(f, op, init, itr) - reduce(op, itr; init=nothing) = - init === nothing ? Base.reduce(op, itr) : Base.reduce(op, init, itr) -end -if VERSION < v"0.7.0-DEV.4534" - reverse(a::AbstractArray; dims=nothing) = - dims===nothing ? Base.reverse(a) : Base.flipdim(a, dims) -end -if VERSION < v"0.7.0-DEV.4738" - Base.squeeze(A; dims=error("squeeze: keyword argument dims not assigned")) = squeeze(A, dims) -end -if VERSION < v"0.7.0-DEV.5165" # julia#27163 - cat(X...; dims = throw(UndefKeywordError("cat: keyword argument dims not assigned"))) = Base.cat(dims, X...) -end - -if !isdefined(Base, :selectdim) # 0.7.0-DEV.3976 - export selectdim - @inline selectdim(A::AbstractArray, d::Integer, i) = _selectdim(A, d, i, Base.setindex(map(Base.Slice, axes(A)), i, d)) - @noinline function _selectdim(A, d, i, idxs) - d >= 1 || throw(ArgumentError("dimension must be ≥ 1")) - nd = ndims(A) - d > nd && (i == 1 || throw(BoundsError(A, (ntuple(k->Colon(),d-1)..., i)))) - return view(A, idxs...) - end -end - -if VERSION < v"0.7.0-DEV.3977" #26039 - Base.repeat(A::AbstractArray, counts::Integer...) = Base.repeat(A, outer = counts) - Base.repeat(a::AbstractVecOrMat, m::Integer, n::Integer=1) = Base.repmat(a, m, n) - Base.repeat(a::AbstractVector, m::Integer) = Base.repmat(a, m) -end - -if VERSION < v"0.7.0-DEV.2337" - # qr doesn't take the full keyword anymore since 0.7.0-DEV.5211; we still support it - # here to avoid unneccesary breakage - if VERSION < v"0.7.0-DEV.843" - qr(A::Union{Number,AbstractMatrix}, pivot::Union{Val{false},Val{true}}=Val(false); full=false) = - Base.qr(A, typeof(pivot), thin=!full) - else - qr(A::Union{Number,AbstractMatrix}, pivot::Union{Val{false},Val{true}}=Val(false); full=false) = - Base.qr(A, pivot, thin=!full) - end -else - using LinearAlgebra: qr -end - -# rmul! (NOTE: Purposefully not exported) -if VERSION < v"0.7.0-DEV.3563" # scale! not deprecated - if VERSION >= v"0.7.0-DEV.3449" # LinearAlgebra in the stdlib - using LinearAlgebra: UnitUpperTriangular, UnitLowerTriangular, scale! - else - using Base.LinAlg: UnitUpperTriangular, UnitLowerTriangular, scale! - end - const Triangle = Union{UpperTriangular, UnitUpperTriangular, - LowerTriangular, UnitLowerTriangular} - if VERSION < v"0.7.0-DEV.3204" # A_mul_B! not deprecated - rmul!(A::AbstractMatrix, B::Triangle) = A_mul_B!(A, A, B) - else - rmul!(A::AbstractMatrix, B::Triangle) = mul!(A, A, B) - end - rmul!(A::AbstractArray, s::Number) = scale!(A, s) - rmul!(A::AbstractMatrix, D::Diagonal) = scale!(A, D.diag) - rmul!(A::Diagonal, B::Diagonal) = Diagonal(A.diag .*= B.diag) - rmul!(A::Triangle, B::Diagonal) = typeof(A)(rmul!(A.data, B)) -elseif v"0.7.0-DEV.3563" <= VERSION < v"0.7.0-DEV.3665" # scale! -> mul1! - using LinearAlgebra: mul1! - const rmul! = mul1! -elseif VERSION >= v"0.7.0-DEV.3665" # mul1! -> rmul! - using LinearAlgebra: rmul! -end - -@static if VERSION < v"0.7.0-DEV.3936" - Base.fetch(t::Task) = wait(t) -end - -# https://github.com/JuliaLang/julia/pull/27077 -@static if VERSION < v"0.7.0-DEV.5087" - export isletter - const isletter = isalpha -end - -# https://github.com/JuliaLang/julia/pull/26850 -if !isdefined(Base, :isbitstype) # 0.7.0-DEV.4905 - export isbitstype - isbitstype(::Type{T}) where {T} = isbits(T) -end - -# 0.7.0-DEV.4762 -@static if !isdefined(Base, Symbol("@cfunction")) - macro cfunction(f, rt, tup) - :(Base.cfunction($(esc(f)), $(esc(rt)), Tuple{$(esc(tup))...})) - end - export @cfunction -end - -if VERSION < v"0.7.0-DEV.2920" # julia#24999 - Base.length(s::AbstractString, i::Integer, j::Integer) = length(s, Int(i), Int(j)) - function Base.length(s::AbstractString, i::Int, j::Int) - @boundscheck begin - 0 < i ≤ ncodeunits(s)+1 || throw(BoundsError(s, i)) - 0 ≤ j < ncodeunits(s)+1 || throw(BoundsError(s, j)) - end - n = 0 - for k = i:j - @inbounds n += isvalid(s, k) - end - return n - end - Base.codeunit(s::String) = UInt8 - Base.codeunit(s::SubString) = codeunit(s.string) -end -if !isdefined(Base, :thisind) # #24414 - thisind(s::AbstractString, i::Integer) = thisind(s, Int(i)) - function thisind(s::AbstractString, i::Int) - z = ncodeunits(s) + 1 - i == z && return i - @boundscheck 0 ≤ i ≤ z || throw(BoundsError(s, i)) - @inbounds while 1 < i && !isvalid(s, i) - i -= 1 - end - return i - end - export thisind -end -if VERSION < v"0.7.0-DEV.2019" # julia#23805 - Base.prevind(s::AbstractString, i::Integer, n::Integer) = prevind(s, Int(i), Int(n)) - Base.nextind(s::AbstractString, i::Integer, n::Integer) = nextind(s, Int(i), Int(n)) - function Base.nextind(s::AbstractString, i::Int, n::Int) - n < 0 && throw(ArgumentError("n cannot be negative: $n")) - z = ncodeunits(s) - @boundscheck 0 ≤ i ≤ z || throw(BoundsError(s, i)) - n == 0 && return thisind(s, i) == i ? i : throw(BoundsError(s, i)) - while n > 0 && i < z - @inbounds n -= isvalid(s, i += 1) - end - return i + n - end - function Base.prevind(s::AbstractString, i::Int, n::Int) - n < 0 && throw(ArgumentError("n cannot be negative: $n")) - z = ncodeunits(s) + 1 - @boundscheck 0 < i ≤ z || throw(BoundsError(s, i)) - n == 0 && return thisind(s, i) == i ? i : throw(BoundsError(s, i)) - while n > 0 && 1 < i - @inbounds n -= isvalid(s, i -= 1) - end - return i - n - end -end - -if VERSION < v"0.7.0-DEV.5278" - something() = throw(ArgumentError("No value arguments present")) - something(x::Nothing, y...) = something(y...) - something(x::Some, y...) = x.value - something(x::Any, y...) = x - export something -end - -if !isdefined(LinearAlgebra, :opnorm) # julia#27401 - opnorm(A::AbstractMatrix, p::Real=2) = LinearAlgebra.norm(A, p) - const norm = LinearAlgebra.vecnorm - const dot = LinearAlgebra.vecdot -else - const opnorm = LinearAlgebra.opnorm - const norm = LinearAlgebra.norm - const dot = LinearAlgebra.dot -end -const ⋅ = dot - -if VERSION < v"0.7.0-DEV.2956" # julia#24839 - Base.permutedims(A::AbstractMatrix) = permutedims(A, (2,1)) - Base.permutedims(v::AbstractVector) = reshape(v, (1, length(v))) -end - -# https://github.com/JuliaLang/julia/pull/27253 -@static if VERSION < v"0.7.0-alpha.44" - Base.atan(x::Real, y::Real) = atan2(x, y) -end - -# https://github.com/JuliaLang/julia/pull/26647 -@static if VERSION < v"0.7.0-DEV.4724" - rsplit(s::AbstractString, splitter; limit::Integer=0, keepempty::Bool=false) = - Base.rsplit(s, splitter; limit=limit, keep=keepempty) - split(s::AbstractString, splitter; limit::Integer=0, keepempty::Bool=false) = - Base.split(s, splitter; limit=limit, keep=keepempty) -end - -# https://github.com/JuliaLang/julia/pull/27828 -if VERSION < v"0.7.0-beta.73" - Base.mapslices(f, A::AbstractArray; dims=error("required keyword argument `dims` missing")) = - mapslices(f, A, dims) -end - -# https://github.com/JuliaLang/julia/pull/28302 -if VERSION < v"0.7.0-beta2.169" - const floatmin = realmin - const floatmax = realmax - export floatmin, floatmax -end - -# https://github.com/JuliaLang/julia/pull/28303 -if VERSION < v"0.7.0-beta2.143" - export dropdims - # https://github.com/JuliaLang/julia/pull/26660 - if VERSION >= v"0.7.0-DEV.4738" - dropdims( - X; - dims = throw( - UndefKeywordError("dropdims: keyword argument dims not assigned")) - ) = squeeze(X, dims = dims) - else - dropdims( - X; - dims = throw( - UndefKeywordError("dropdims: keyword argument dims not assigned")) - ) = squeeze(X, dims) - end -end - -function rangedepwarn(;step=nothing, length=nothing, kwargs...) - if step===nothing && length===nothing - Base.depwarn("`range(start, stop)` (with neither `length` nor `step` given) is deprecated, use `range(start, stop=stop)` instead.", :range) - end -end - if VERSION < v"1.1.0-DEV.506" - function range(start, stop; kwargs...) - rangedepwarn(;kwargs...) - range(start; stop=stop, kwargs...) + function Base.range(start, stop; length=nothing, step=nothing) + if length === step === nothing + throw(ArgumentError("at least one of `length` or `step` must be provided")) + end + range(start; stop=stop, length=length, step=step) end end # https://github.com/JuliaLang/julia/pull/30496 -if VERSION < v"1.2.0-DEV.272" +if !isdefined(Base, :hasfield) # 1.2.0-DEV.272 Base.@pure hasfield(::Type{T}, name::Symbol) where T = Base.fieldindex(T, name, false) > 0 export hasfield - if VERSION >= v"0.7-DEV.5136" - hasproperty(x, s::Symbol) = s in propertynames(x) - export hasproperty - end +end +if !isdefined(Base, :hasproperty) + hasproperty(x, s::Symbol) = s in propertynames(x) + export hasproperty end include("deprecated.jl") diff --git a/src/deprecated.jl b/src/deprecated.jl index e76dc980f..1202bdfad 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -1,4 +1,5 @@ Base.@deprecate_binding StringVector Base.StringVector false +Base.@deprecate_binding macros_have_sourceloc true false # PR #17302 # Provide a non-deprecated version of `@vectorize_(1|2)arg` macro which defines @@ -56,29 +57,16 @@ else end end -# compatibility with https://github.com/JuliaLang/julia/pull/26156 -Base.@deprecate trunc(x, digits; base = 10) Compat.trunc(x, digits = digits, base = base) false -Base.@deprecate floor(x, digits; base = 10) Compat.floor(x, digits = digits, base = base) false -Base.@deprecate ceil(x, digits; base = 10) Compat.ceil(x, digits = digits, base = base) false -Base.@deprecate round(x, digits; base = 10) Compat.round(x, digits = digits, base = base) false -Base.@deprecate signif(x, digits; base = 10) Compat.round(x, sigdigits = digits, base = base) false - -if VERSION >= v"1.1.0-DEV.506" - # deprecation of range(start, stop) for earlier versions is done in Compat.jl - # This method is restricted to Number, since we don't - # want to overwrite the (::Any, ::Any) method in Base. - function range(start::Number, stop::Number; kwargs...) - rangedepwarn(;kwargs...) - range(start; stop=stop, kwargs...) - end -end - # this was defined for use with Julia versions prior to 0.5 # (see https://github.com/JuliaLang/Compat.jl/pull/316) macro dotcompat(x) - Base.depwarn("`@dotcompat x` is deprecated, use `@compat @. x` instead.", Symbol("@dotcompat")) - esc(:(Compat.@compat @. $x)) + Base.depwarn("`@dotcompat x` is deprecated, use `@. x` instead.", Symbol("@dotcompat")) + esc(:(@. $x)) end export @dotcompat -# Compat.Random.uuid1, uuid4, uuid_version are deprecated in Compat.jl +module TypeUtils + using Base: parameter_upper_bound, typename + const isabstract = isabstracttype + export isabstract, parameter_upper_bound, typename +end diff --git a/test/REQUIRE b/test/REQUIRE deleted file mode 100644 index dbe36550b..000000000 --- a/test/REQUIRE +++ /dev/null @@ -1 +0,0 @@ -OffsetArrays diff --git a/test/runtests.jl b/test/runtests.jl index 4832b717d..68c2519dd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,1476 +1,22 @@ using Compat -using Compat.Test -using Compat.LinearAlgebra -using Compat.SparseArrays +using Test @test isempty(detect_ambiguities(Base, Core, Compat)) -const struct_sym = VERSION < v"0.7.0-DEV.1263" ? :type : :struct - -for os in [:apple, :bsd, :linux, :unix, :windows] - from_base = if VERSION >= v"0.7.0-DEV.914" - Expr(:., Expr(:., :Base, Base.Meta.quot(:Sys)), Base.Meta.quot(Symbol("is", os))) - else - Expr(:., :Base, Base.Meta.quot(Symbol("is_", os))) - end - @eval @test Compat.Sys.$(Symbol("is", os))() == $from_base() -end - -let s = "Koala test: 🐨" - @test transcode(UInt16, s) == UInt16[75,111,97,108,97,32,116,101,115,116,58,32,55357,56360] - @test transcode(UInt32, s) == UInt32[75,111,97,108,97,32,116,101,115,116,58,32,128040] - for T in (UInt8,UInt16,UInt32,Cwchar_t) - @test transcode(Compat.String, transcode(T, s)) == s - @test transcode(UInt8, transcode(T, s)) == codeunits(s) - @test transcode(T, s) == transcode(T, codeunits(s)) == transcode(T, transcode(T, s)) - end -end - -# julia#26365 -@test Compat.tr([1 2; 3 5]) == 6 - -let - x = view(1:10, 2:4) - D = Diagonal(x) - @test D[1,1] == 2 - @test D[3,3] == 4 - A = view(rand(5,5), 1:3, 1:3) - @test D*A == Diagonal(copy(x)) * copy(A) - @test A*D == copy(A) * Diagonal(copy(x)) -end - -# 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 - -# julia#20006 -abstract type AbstractFoo20006 end -eval(Expr( - struct_sym, false, - Expr(:(<:), :(ConcreteFoo20006{T<:Int}), :AbstractFoo20006), - quote end)) -eval(Expr( - struct_sym, false, - Expr(:(<:), :(ConcreteFoo20006N{T<:Int,N}), :AbstractFoo20006), - quote end)) -@compat ConcreteFoo200061{T<:Int} = ConcreteFoo20006N{T,1} -@test Compat.TypeUtils.isabstract(AbstractFoo20006) -@test !Compat.TypeUtils.isabstract(ConcreteFoo20006) -@test !Compat.TypeUtils.isabstract(ConcreteFoo20006N) -@test !Compat.TypeUtils.isabstract(ConcreteFoo200061) -@test !Compat.TypeUtils.isabstract(StridedArray) -@test Compat.TypeUtils.parameter_upper_bound(ConcreteFoo20006, 1) == Int -@test isa(Compat.TypeUtils.typename(Array), Core.TypeName) -@test isabstracttype(AbstractFoo20006) -@test !isabstracttype(ConcreteFoo20006) -@test !isabstracttype(ConcreteFoo20006N) -@test !isabstracttype(ConcreteFoo200061) -@test !isabstracttype(StridedArray) - -# PR 20203 -@test Compat.readline(IOBuffer("Hello, World!\n")) == "Hello, World!" -@test Compat.readline(IOBuffer("x\n"), keep=false) == "x" -@test Compat.readline(IOBuffer("x\n"), keep=true) == "x\n" -@test collect(Compat.eachline(IOBuffer("x\ny"))) == ["x", "y"] -@test collect(Compat.eachline(IOBuffer("x\ny"), keep=false)) == ["x", "y"] -@test collect(Compat.eachline(IOBuffer("x\ny"), keep=true)) == ["x\n", "y"] - -# PR 25646 -for (t, s, m, kept) in [ - ("a", "ab", "a", "a"), - ("b", "ab", "b", "b"), - ("α", "αγ", "α", "α"), - ("ab", "abc", "ab", "ab"), - ("bc", "abc", "bc", "bc"), - ("αβ", "αβγ", "αβ", "αβ"), - ("aaabc", "ab", "aa", "aaab"), - ("aaabc", "ac", "aaabc", "aaabc"), - ("aaabc", "aab", "a", "aaab"), - ("aaabc", "aac", "aaabc", "aaabc"), - ("αααβγ", "αβ", "αα", "αααβ"), - ("αααβγ", "ααβ", "α", "αααβ"), - ("αααβγ", "αγ", "αααβγ", "αααβγ"), - ("barbarbarians", "barbarian", "bar", "barbarbarian"), - ("abcaabcaabcxl", "abcaabcx", "abca", "abcaabcaabcx"), - ("abbaabbaabbabbaax", "abbaabbabbaax", "abba", "abbaabbaabbabbaax"), - ("abbaabbabbaabbaabbabbaax", "abbaabbabbaax", "abbaabbabba", "abbaabbabbaabbaabbabbaax"), - ] - local t, s, m, kept - @test Compat.readuntil(IOBuffer(t), s) == m - @test Compat.readuntil(IOBuffer(t), s, keep=true) == kept - @test Compat.readuntil(IOBuffer(t), SubString(s, firstindex(s))) == m - @test Compat.readuntil(IOBuffer(t), SubString(s, firstindex(s)), keep=true) == kept - @test Compat.readuntil(IOBuffer(t), GenericString(s)) == m - @test Compat.readuntil(IOBuffer(t), GenericString(s), keep=true) == kept - @test Compat.readuntil(IOBuffer(t), Vector{UInt8}(codeunits(s))) == Vector{UInt8}(codeunits(m)) - @test Compat.readuntil(IOBuffer(t), Vector{UInt8}(codeunits(s)), keep=true) == Vector{UInt8}(codeunits(kept)) - @test Compat.readuntil(IOBuffer(t), collect(s)::Vector{Char}) == Vector{Char}(m) - @test Compat.readuntil(IOBuffer(t), collect(s)::Vector{Char}, keep=true) == Vector{Char}(kept) -end - -# PR 22064 -module Test22064 -using Compat -using Compat.Test -@test (@__MODULE__) === Test22064 -end - -# invokelatest with keywords -pr22646(x; y=0) = 1 -let foo() = begin - eval(:(pr22646(x::Int; y=0) = 2)) - return Compat.invokelatest(pr22646, 0, y=1) - end - @test foo() == 2 -end - -# PR #21197 -let c = `ls -l "foo bar"` - @test collect(c) == ["ls", "-l", "foo bar"] - @test first(c) == "ls" == c[1] - @test last(c) == "foo bar" == c[3] == c[end] - @test c[1:2] == ["ls", "-l"] - @test eltype(c) == String - @test length(c) == 3 - @test eachindex(c) == 1:3 -end - -# PR 22629 -@test logdet(0.5) == log(det(0.5)) - -# PR 22633 -if VERSION < v"0.7.0-DEV.5272" - # chol(A::UniformScaling) has been deprecated in Julia, we still test it to avoid - # accidental breakage in packages using the Compat vesion of it on Julia 0.6 - for T in (Float64, ComplexF32, BigFloat, Int) - λ = T(4) - @test chol(λ*I).λ ≈ √λ - @test_throws Union{ArgumentError,Compat.LinearAlgebra.PosDefException} chol(-λ*I) - end -end - -let - @compat cr(::CartesianIndices{2}) = 2 - @test cr(CartesianIndices((5, 3))) == 2 - @test_throws MethodError cr(CartesianIndices((5, 3, 2))) -end -if VERSION < v"0.7.0-DEV.880" - # ensure we don't bork any non-updated expressions - let - @compat cr(::CartesianRange{CartesianIndex{2}}) = 2 - @test cr(CartesianRange((5, 3))) == 2 - @test_throws MethodError cr(CartesianRange((5, 3, 2))) - end -end - -# PR 22350 -eval(Expr(struct_sym, false, :TestType, Expr(:block, :(a::Int), :b))) -@test fieldcount(TestType) == 2 -@test fieldcount(Int) == 0 - -# PR 20005 -@test_throws InexactError throw(InexactError(:func, Int, 3.2)) - -# PR 22751 -@test_throws DomainError throw(DomainError(-2)) -@test_throws DomainError throw(DomainError(-2, "negative")) - -# PR 22761 -@test_throws OverflowError throw(OverflowError("overflow")) - -# PR 22907 -using Compat: pairs - -# keys, values, pairs -for A in (rand(2), rand(2,3)) - local A - for (i, v) in pairs(A) - @test A[i] == v - end - @test collect(values(A)) == collect(A) -end - -let A = Dict(:foo=>1, :bar=>3) - for (k, v) in pairs(A) - @test A[k] == v - end - @test sort!(collect(pairs(A))) == sort!(collect(A)) -end - -let - A14 = [11 13; 12 14] - R = CartesianIndices(Compat.axes(A14)) - @test vec([a for (a,b) in pairs(IndexLinear(), A14)]) == [1,2,3,4] - @test vec([a for (a,b) in pairs(IndexCartesian(), A14)]) == vec(collect(R)) - @test vec([b for (a,b) in pairs(IndexLinear(), A14)]) == [11,12,13,14] - @test vec([b for (a,b) in pairs(IndexCartesian(), A14)]) == [11,12,13,14] -end - -# Val(x) -# 0.7 -begin - local firstlast - firstlast(::Val{true}) = "First" - firstlast(::Val{false}) = "Last" - - @test firstlast(Val(true)) == "First" - @test firstlast(Val(false)) == "Last" -end - -# Reshape to a given number of dimensions using Val(N) -# 0.7 -let - for A in (rand(Float64, ()), rand(2), rand(2,3), rand(2,3,5), rand(2,3,5,7)), N in (1,2,3,4,5,6) - B = @inferred reshape(A, Val(N)) - @test ndims(B) == N - if N < ndims(A) - new_sz = (size(A)[1:N-1]..., prod(size(A)[N:end])) - elseif N == ndims(A) - new_sz = size(A) - else - new_sz = (size(A)..., ntuple(x->1, N-ndims(A))...) - end - @test size(B) == new_sz - @test B == reshape(A, new_sz) - end -end - -# ntuple with Val(N) -# 0.7 -@test @inferred(ntuple(x->1, Val(3))) == (1,1,1) -@test @inferred(ntuple(x->x, Val(0))) == () -@test @inferred(ntuple(x->x, Val(5))) == (1,2,3,4,5) - -# @nospecialize -# 0.7 -no_specialize(@nospecialize(x)) = sin(1) -no_specialize(@nospecialize(x::Integer)) = sin(2) -@test no_specialize(1.0) == sin(1) -@test no_specialize(1) == sin(2) -no_specialize_kw1(@nospecialize(x=0)) = sin(1) -no_specialize_kw1(@nospecialize(x::Integer)) = sin(2) -@test no_specialize_kw1(1.0) == sin(1) -@test no_specialize_kw1(1) == sin(2) -@test no_specialize_kw1() == sin(2) -no_specialize_kw2(@nospecialize(x)) = sin(1) -no_specialize_kw2(@nospecialize(x::Integer=0)) = sin(2) -@test no_specialize_kw2(1.0) == sin(1) -@test no_specialize_kw2(1) == sin(2) -@test no_specialize_kw2() == sin(2) - -# 0.7 -@test read(IOBuffer("aaaa"), String) == "aaaa" -@test occursin("read(@__FILE__, String)", read(@__FILE__, String)) -let cmd = `$(Base.julia_cmd()) --startup-file=no -e "println(:aaaa)"` - @test read(cmd, String) == "aaaa\n" - @test read(pipeline(cmd, stderr=devnull), String) == "aaaa\n" -end - -# 0.7 -@test isa(1:2, AbstractRange) - -# 0.7 -let M = [1 + 2im 3 + 4im; 5 + 6im 7 + 8im], - M2 = adjoint(copy(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 -if VERSION < v"0.7.0-DEV.5238" - # Test the extended cov if cov is part of Base. In the future, this will be dealt with - # in StatsBase - @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] - @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 isconcretetype(Int) - -# 0.7 -module Test23876 - using Compat - using Compat.Test - import Compat.DelimitedFiles - using Compat.Mmap, Compat.SharedArrays - using Compat.Distributed - @test isdefined(@__MODULE__, :DelimitedFiles) - @test isdefined(SharedArrays, :SharedArray) - @test isdefined(@__MODULE__, :SharedArray) - @test isdefined(@__MODULE__, :procs) - @test isdefined(@__MODULE__, :remote_do) - @test isdefined(Mmap, :mmap) -end - -# 0.7 -module Test24459 - using Compat - using Compat.Test - using Compat.Dates - @test isdefined(@__MODULE__, :Dates) -end - -# 0.7 -module Test25056 - using Compat - using Compat.Test - using Compat.Printf - @test isdefined(@__MODULE__, :Printf) - @test isdefined(@__MODULE__, Symbol("@printf")) - @test isdefined(@__MODULE__, Symbol("@sprintf")) -end - -# 0.7 - -let a = [0,1,2,3,0,1,2,3] - # curried isequal - @test findfirst(isequal(3), [1,2,4,1,2,3,4]) == 6 - @test findfirst(!isequal(1), [1,2,4,1,2,3,4]) == 2 - @test findnext(isequal(1), a, 4) == 6 - # @test findnext(isequal(5), a, 4) == 0 - @test findlast(isequal(3), [1,2,4,1,2,3,4]) == 6 - @test findprev(isequal(1), a, 4) == 2 - @test findprev(isequal(1), a, 8) == 6 - if VERSION < v"0.7.0-DEV.4592" - # test that equalto work on 0.6 - @test findfirst(equalto(3), [1,2,4,1,2,3,4]) == 6 - @test findfirst(!equalto(1), [1,2,4,1,2,3,4]) == 2 - end - # curried == - @test findfirst(==(3), [1,2,4,1,2,3,4]) == 6 - @test findfirst(!(==(1)), [1,2,4,1,2,3,4]) == 2 - @test findnext(==(1), a, 4) == 6 - @test findlast(==(3), [1,2,4,1,2,3,4]) == 6 - @test findprev(==(1), a, 4) == 2 - @test findprev(==(1), a, 8) == 6 -end - -# 0.7 -@test 'a'*"b" == "a"*'b' == 'a'*'b' == "ab" - -# 0.7 -@test 1 in BitSet(1:10) - -# 0.7.0-DEV.1930 -@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 - @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}) -@test isa(Matrix(undef, 2, 2), Matrix{Any}) -@test isa(Matrix{Float64}(undef, 2, 2), Matrix{Float64}) -@test isa(Array{Float64}(undef, 2, 2), Matrix{Float64}) -@test isa(Array{Float64,3}(undef, 2, 2, 2), Array{Float64,3}) - -# 0.7.0-DEV.2687, 0.7.0-DEV.4527 -@test isa(BitVector(undef, 2), BitVector) -@test isa(BitArray(undef, 2, 2), BitMatrix) - -# 0.7.0-DEV.1472 -@test get(IOContext(IOBuffer(), :arg1=>true, :arg2=>true, :arg3=>true), :arg3, false) -@test get(IOContext(IOBuffer(), :arg1=>true, :arg2=>true), :arg2, false) - -# 0.7.0-DEV.2338 -module Test24361 - using Compat - using Compat.Test - @test String(Compat.Base64.base64decode("SGVsbG8h")) == "Hello!" -end - -# 0.7 -let A = [1] - local x = 0 - @compat finalizer(a->(x+=1), A) - finalize(A) - @test x == 1 - A = 0 - GC.gc(); GC.gc() - @test x == 1 -end - -# 0.7.0-DEV.1499 -let key = "TEST_23412" - @test !haskey(ENV, key) - @test get(() -> "default", ENV, key) == "default" -end - -# 0.7.0-DEV.2919 -@test ComplexF16 === Complex{Float16} -@test ComplexF32 === Complex{Float32} -@test ComplexF64 === Complex{Float64} - -# 0.7.0-DEV.3073 -if VERSION < v"0.7.0-DEV.3073" - @test Compat.Sys.BINDIR == JULIA_HOME -else - @test Compat.Sys.BINDIR == Sys.BINDIR -end - -# 0.7.0-DEV.2915 -module Test25021 - using Compat - using Compat.Test - using Compat.Unicode - @test isdefined(@__MODULE__, :Unicode) - - @test !isnumeric('a') - @test isnumeric('1') - @test titlecase("firstname lastname") == "Firstname Lastname" - @test Compat.Unicode.isassigned('柒') && !Compat.Unicode.isassigned(0xfffe) - @test Compat.Unicode.normalize("\U1e9b\U0323", :NFKC) == "\U1e69" - @test Compat.Unicode.normalize("\t\r", stripcc=true) == " " -end - -# 0.7.0-DEV.3393 -@test !isnumeric('a') -@test isnumeric('1') - -# 0.7.0-DEV.2951 -@test AbstractDict === (isdefined(Base, :AbstractDict) ? Base.AbstractDict : Base.Associative) - -# 0.7.0-DEV.2978 -@test Compat.axes === (isdefined(Base, :axes) ? Base.axes : Base.indices) -@test Compat.axes(1) == () -@test Compat.axes(1,1) == 1:1 - -# 0.7.0-DEV.3137 -@test Nothing === (isdefined(Base, :Nothing) ? Base.Nothing : Base.Void) -@test Nothing === Cvoid - -# 0.7.0-DEV.3017 -@test isa(Some(1), Some{Int}) -@test convert(Some{Float64}, Some(1)) == Some(1.0) -@test convert(Nothing, nothing) == nothing -@test_throws MethodError convert(Nothing, 1) -@test Some(nothing) != nothing -if VERSION < v"0.7.0-DEV.5278" - # coalesce has changed; old behavior kept and tested to avoid accidental breakage - @test coalesce(Some(1)) == 1 - @test coalesce(nothing) == nothing - @test coalesce(nothing, Some(1), Some(2)) == 1 -end -@test Compat.notnothing(1) == 1 -@test_throws ArgumentError Compat.notnothing(nothing) - -# 0.7.0-DEV.3155 -let coolvec = [1,2,3] - @test pushfirst!(coolvec, 0) == [0,1,2,3] - @test popfirst!(coolvec) == 0 -end - -# 0.7.0-DEV.3309 -let v = [1, 2, 3] - @test Compat.IteratorSize(v) isa Base.HasShape - @test Compat.IteratorEltype(v) == Base.HasEltype() -end - -# 0.7.0-DEV.3057 -let A = [0, 0, 0], B = [1, 2, 3] - @test copyto!(A, B) === A == B -end -let A = [0, 0, 0], B = [1, 2, 3] - @test unsafe_copyto!(A, 2, B, 1, 1) === A == [0, 1, 0] -end - -# 0.7.0-DEV.3406 -using Compat.Random -@test rand(MersenneTwister(1234)) == 0.5908446386657102 - -# 0.7, make sure this works on 0.6 -if VERSION < v"0.7.0-DEV.3272" - @test contains("Hello, World!", r"World") -end - -# 0.7.0-DEV.4639 -@test occursin(r"World", "Hello, World!") -@test occursin(r"World", "Hello, World!", offset = 4) -@test occursin("World", "Hello, World!") -# 0.7.0-DEV.912 -@test occursin('W', "Hello, World!") - -# 0.7.0-DEV.3449 -let A = [2.0 1.0; 1.0 3.0], b = [2.0, 3.0] - @test diag(A) == b -end - -# 0.7.0-DEV.3173 -@test invpermute!(permute!([1, 2], 2:-1:1), 2:-1:1) == [1, 2] - -# 0.7.0-DEV.3172 -@test replace("abcb", "b"=>"c") == "accc" -@test replace("abcb", "b"=>"c", count=1) == "accb" -# 0.7.0-DEV.3216 -@test Compat.AbstractDateTime === (isdefined(Compat.Dates, :AbstractDateTime) ? Compat.Dates.AbstractDateTime : Compat.Dates.TimeType) -@test Compat.AbstractDateTime <: Compat.Dates.TimeType -@test Compat.Dates.DateTime <: Compat.AbstractDateTime - -# 0.7.0-DEV.2402 - -x = Compat.Dates.Second(172799) -@test floor(x, Compat.Dates.Week) == Compat.Dates.Week(0) -@test floor(x, Compat.Dates.Day) == Compat.Dates.Day(1) -@test floor(x, Compat.Dates.Hour) == Compat.Dates.Hour(47) -@test floor(x, Compat.Dates.Minute) == Compat.Dates.Minute(2879) -@test floor(x, Compat.Dates.Second) == Compat.Dates.Second(172799) -@test floor(x, Compat.Dates.Millisecond) == Compat.Dates.Millisecond(172799000) -@test ceil(x, Compat.Dates.Week) == Compat.Dates.Week(1) -@test ceil(x, Compat.Dates.Day) == Compat.Dates.Day(2) -@test ceil(x, Compat.Dates.Hour) == Compat.Dates.Hour(48) -@test ceil(x, Compat.Dates.Minute) == Compat.Dates.Minute(2880) -@test ceil(x, Compat.Dates.Second) == Compat.Dates.Second(172799) -@test ceil(x, Compat.Dates.Millisecond) == Compat.Dates.Millisecond(172799000) -@test round(x, Compat.Dates.Week) == Compat.Dates.Week(0) -@test round(x, Compat.Dates.Day) == Compat.Dates.Day(2) -@test round(x, Compat.Dates.Hour) == Compat.Dates.Hour(48) -@test round(x, Compat.Dates.Minute) == Compat.Dates.Minute(2880) -@test round(x, Compat.Dates.Second) == Compat.Dates.Second(172799) -@test round(x, Compat.Dates.Millisecond) == Compat.Dates.Millisecond(172799000) - -x = Compat.Dates.Nanosecond(2000999999) -@test floor(x, Compat.Dates.Second) == Compat.Dates.Second(2) -@test floor(x, Compat.Dates.Millisecond) == Compat.Dates.Millisecond(2000) -@test floor(x, Compat.Dates.Microsecond) == Compat.Dates.Microsecond(2000999) -@test floor(x, Compat.Dates.Nanosecond) == x -@test ceil(x, Compat.Dates.Second) == Compat.Dates.Second(3) -@test ceil(x, Compat.Dates.Millisecond) == Compat.Dates.Millisecond(2001) -@test ceil(x, Compat.Dates.Microsecond) == Compat.Dates.Microsecond(2001000) -@test ceil(x, Compat.Dates.Nanosecond) == x -@test round(x, Compat.Dates.Second) == Compat.Dates.Second(2) -@test round(x, Compat.Dates.Millisecond) == Compat.Dates.Millisecond(2001) -@test round(x, Compat.Dates.Microsecond) == Compat.Dates.Microsecond(2001000) -@test round(x, Compat.Dates.Nanosecond) == x - - -for x in [Compat.Dates.Week(3), Compat.Dates.Day(14), Compat.Dates.Second(604800)] - local x - for p in [Compat.Dates.Week, Compat.Dates.Day, Compat.Dates.Hour, Compat.Dates.Second, Compat.Dates.Millisecond, Compat.Dates.Microsecond, Compat.Dates.Nanosecond] - local p - @test floor(x, p) == p(x) - @test ceil(x, p) == p(x) - end -end - -x = Compat.Dates.Hour(36) -@test round(x, Compat.Dates.Day, RoundNearestTiesUp) == Compat.Dates.Day(2) -@test round(x, Compat.Dates.Day, RoundUp) == Compat.Dates.Day(2) -@test round(x, Compat.Dates.Day, RoundDown) == Compat.Dates.Day(1) -@test_throws DomainError round(x, Compat.Dates.Day, RoundNearest) -@test_throws DomainError round(x, Compat.Dates.Day, RoundNearestTiesAway) -@test_throws DomainError round(x, Compat.Dates.Day, RoundToZero) -@test round(x, Compat.Dates.Day) == round(x, Compat.Dates.Day, RoundNearestTiesUp) - -x = Compat.Dates.Hour(86399) -for p in [Compat.Dates.Week, Compat.Dates.Day, Compat.Dates.Hour, Compat.Dates.Second, Compat.Dates.Millisecond, Compat.Dates.Microsecond, Compat.Dates.Nanosecond] - local p - for v in [-1, 0] - @test_throws DomainError floor(x, p(v)) - @test_throws DomainError ceil(x, p(v)) - @test_throws DomainError round(x, p(v)) - end -end -for p in [Compat.Dates.Year, Compat.Dates.Month] - local p - for v in [-1, 0, 1] - @test_throws MethodError floor(x, p(v)) - @test_throws MethodError ceil(x, p(v)) - @test_throws DomainError round(x, p(v)) - end -end - -# 0.7.0-DEV.3025 -let c = CartesianIndices((1:3, 1:2)), l = LinearIndices((1:3, 1:2)) - @test LinearIndices(c) == collect(l) - @test CartesianIndices(l) == collect(c) - @test first(c) == CartesianIndex(1, 1) - @test CartesianIndex(1, 1) in c - @test first(l) == 1 - @test size(c) == size(l) == (3, 2) - @test c == collect(c) == [CartesianIndex(1, 1) CartesianIndex(1, 2) - CartesianIndex(2, 1) CartesianIndex(2, 2) - CartesianIndex(3, 1) CartesianIndex(3, 2)] - @test l == collect(l) == reshape(1:6, 3, 2) - @test c[1:6] == vec(c) - @test l[1:6] == vec(l) - # TODO the following test fails on current Julia master (since 0.7.0-DEV.4742), and - # it's not clear yet whether it should work or not. See - # https://github.com/JuliaLang/julia/pull/26682#issuecomment-379762632 and the - # discussion following it - #@test l == l[c] == map(i -> l[i], c) - @test l[vec(c)] == collect(1:6) - @test CartesianIndex(1, 1) in CartesianIndices((3, 4)) -end - -if !isdefined(Base, Symbol("@info")) - let fname = tempname() - try - open(fname, "w") do fout - redirect_stderr(fout) do - Compat.@info "A" - Compat.@warn "B" - oldstate = Compat.DEBUG[] - Compat.enable_debug(false) - Compat.@debug "C" - Compat.enable_debug(true) - Compat.@debug "D" - Compat.enable_debug(oldstate) - Compat.@error "E" - end - end - @test read(fname, String) == (Base.have_color ? "\e[1m\e[36mInfo: \e[39m\e[22m\e[36mA\n\e[39m\e[1m\e[33mWarning: \e[39m\e[22m\e[33mB\e[39m\n\e[1m\e[34mDebug: \e[39m\e[22m\e[34mD\n\e[39m\e[1m\e[91mError: \e[39m\e[22m\e[91mE\n\e[39m" : - "Info: A\nWarning: B\nDebug: D\nError: E\n") - finally - rm(fname, force=true) - end - end -end - -# 0.7.0-DEV.3460 -@test parentmodule(Compat.Sys) == Compat -@test parentmodule(sin) == Base -@test parentmodule(sin, Tuple{Int}) == Base.Math -@test parentmodule(Int) == Core -@test parentmodule(Array) == Core - -@test codeunits("foo") == [0x66,0x6f,0x6f] == codeunits(SubString("fooαβγ",1,3)) -@test ncodeunits("αβγ") == 6 == ncodeunits(SubString("fooαβγ",4,8)) -@test codeunit("foo") == codeunit(SubString("fooαβγ",1,3)) == UInt8 - -# 0.7.0-DEV.3539 -@test nameof(Compat.Sys) == :Sys -@test nameof(sin) == :sin -@test nameof(Float64) == :Float64 -@test nameof(Array) == :Array - -# 0.7.0-DEV.3382 -module TestLibdl - using Compat - using Compat.Libdl - using Compat.Test - @test isdefined(@__MODULE__, :Libdl) -end - -# 0.7.0-DEV.3516 -@test argmax([10,12,9,11]) == 2 -@test argmax([10 12; 9 11]) == CartesianIndex(1, 2) -@test argmax(Dict(:z=>10, :y=>12, :x=>9, :w=>11)) == :y -@test argmax((-5, 6, 10)) == 3 -@test argmin([10,12,9,11]) == 3 -@test argmin([10 12; 9 11]) == CartesianIndex(2, 1) -@test argmin(Dict(:z=>10, :y=>12, :x=>9, :w=>11)) == :x -@test argmin((1.0, -3, 0.f0)) == 2 - -# 0.7.0-DEV.3415 -@test findall(x -> x==1, [1, 2, 3, 2, 1]) == [1, 5] - -# 0.7.0-DEV.3500 -module TestREPL - using Compat - using Compat.REPL - using Compat.Test - @test isdefined(@__MODULE__, :REPL) -end - -# 0.7.0-DEV.3476 -module TestSerialization - using Compat - using Compat.Serialization - using Compat.Test - @test isdefined(@__MODULE__, :Serialization) - @test isdefined(@__MODULE__, :serialize) - @test isdefined(@__MODULE__, :deserialize) - if VERSION < v"1.0.0-DEV.44" - @test isdefined(@__MODULE__, :SerializationState) - end -end - -module TestPkg - using Compat - using Compat.Pkg - using Compat.Test - @test isdefined(@__MODULE__, :Pkg) - @test isdefined(Compat.Pkg, :add) -end - -module TestInteractiveUtils - using Compat - using Compat.InteractiveUtils - using Compat.Test - @test isdefined(@__MODULE__, :InteractiveUtils) - @test isdefined(@__MODULE__, :varinfo) -end - -module TestLibGit2 - using Compat - using Compat.LibGit2 - using Compat.Test - @test isdefined(@__MODULE__, :LibGit2) - @test isdefined(@__MODULE__, :GitRepo) -end - -# 0.7.0-DEV.3469 -@test GC.enable(true) -@test GC.enable(false) -@test !GC.enable(false) -@test !GC.enable(true) -@test GC.enable(true) - -@test eltype(Base.Multimedia.displays) <: AbstractDisplay - -# 0.7.0-DEV.3481 -let b = IOBuffer() - write(b, "hi") - @test bytesavailable(b) == 0 -end - -# 0.7.0-DEV.3583 -@test lastindex(zeros(4)) == 4 -@test lastindex(zeros(4,4)) == 16 -@test all(x -> firstindex(x) == 1, ([1, 2], [1 2; 3 4], 'a', 1, 1=>2, `foo`, "foo", (1, 2))) - -# 0.7.0-DEV.3585 -let buf = IOBuffer() - if VERSION < v"0.7.0-DEV.3077" - col = Base.have_color - eval(Base, :(have_color = true)) - printstyled(buf, "foo", color=:red) - eval(Base, :(have_color = $col)) - else - printstyled(IOContext(buf, :color=>true), "foo", color=:red) - end - @test startswith(String(take!(buf)), Base.text_colors[:red]) -end - -# 0.7.0-DEV.3455 -@test hasmethod(sin, Tuple{Float64}) -let x = y = 1 - @test objectid(x) == objectid(y) -end - -# 0.7.0-DEV.3415 -for (f1, f2, i) in ((Compat.findfirst, Compat.findnext, 1), - (Compat.findlast, Compat.findprev, 2)) - # Generic methods - @test f1(isequal(0), [1, 0]) == f2(isequal(0), [1, 0], i) == 2 - @test f1(isequal(9), [1, 0]) == f2(isequal(9), [1, 0], i) == nothing - @test f1(in([0, 2]), [1, 0]) == f2(in([0, 2]), [1, 0], i) == 2 - @test f1(in([0, 2]), [1, 9]) == f2(in([0, 2]), [1, 9], i) == nothing - if VERSION < v"0.7.0-DEV.4592" - # test that occursin work on 0.6 - @test f1(occursin([0, 2]), [1, 0]) == f2(occursin([0, 2]), [1, 0], i) == 2 - @test f1(occursin([0, 2]), [1, 9]) == f2(occursin([0, 2]), [1, 9], i) == nothing - end - @test f1([true, false]) == f2([true, false], i) == 1 - @test f1([false, false]) == f2([false, false], i) == nothing - - # Specific methods - @test f2(isequal('a'), "ba", i) == f1(isequal('a'), "ba") == 2 - for S in (Int8, UInt8), T in (Int8, UInt8) - # Bug in Julia 0.6 - f1 === Compat.findlast && VERSION < v"0.7.0-DEV.3272" && continue - @test f2(isequal(S(1)), T[0, 1], i) == f1(isequal(S(1)), T[0, 1]) == 2 - @test f2(isequal(S(9)), T[0, 1], i) == f1(isequal(S(9)), T[0, 1]) == nothing - end - for chars in (['a', 'z'], Set(['a', 'z']), ('a', 'z')) - @test f2(in(chars), "ba", i) == f1(in(chars), "ba") == 2 - @test f2(in(chars), "bx", i) == f1(in(chars), "bx") == nothing - if VERSION < v"0.7.0-DEV.4592" - # test that occursin work on 0.6 - @test f2(occursin(chars), "ba", i) == f1(occursin(chars), "ba") == 2 - @test f2(occursin(chars), "bx", i) == f1(occursin(chars), "bx") == nothing - end - end -end -@test findnext("a", "ba", 1) == findfirst("a", "ba") == 2:2 -@test findnext("z", "ba", 1) == findfirst("z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) -@test findprev("a", "ba", 2) == findlast("a", "ba") == 2:2 -@test findprev("z", "ba", 2) == findlast("z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) -@test Compat.findnext("a", "ba", 1) == Compat.findfirst("a", "ba") == 2:2 -@test Compat.findnext("z", "ba", 1) == Compat.findfirst("z", "ba") == nothing -@test Compat.findprev("a", "ba", 2) == Compat.findlast("a", "ba") == 2:2 -@test Compat.findprev("z", "ba", 2) == Compat.findlast("z", "ba") == nothing - -@test findnext(r"a", "ba", 1) == findfirst(r"a", "ba") == 2:2 -@test findnext(r"z", "ba", 1) == findfirst(r"z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) -@test Compat.findnext(r"a", "ba", 1) == Compat.findfirst(r"a", "ba") == 2:2 -@test Compat.findnext(r"z", "ba", 1) == Compat.findfirst(r"z", "ba") == nothing - -@test findall([true, false, true]) == [1, 3] -@test findall(in([1, 2]), [1]) == [1] -if VERSION < v"0.7.0-DEV.4592" - # test that occursin work on 0.6 - @test findall(occursin([1, 2]), [1]) == [1] -end - -# 0.7.0-DEV.3666 -module TestUUIDs - using Compat - using Compat.UUIDs - using Compat.Test - @test isdefined(@__MODULE__, :uuid1) - @test isdefined(@__MODULE__, :uuid4) - @test isdefined(@__MODULE__, :uuid_version) - - @test uuid_version(uuid1()) == 1 - @test uuid_version(uuid4()) == 4 - @test uuid1() isa UUID - @test uuid4() isa UUID -end - -# 0.7.0-DEV.3589 -import Compat.Markdown -@test isa(Markdown.parse("foo"), Markdown.MD) - -@test repr("text/plain", "string") == "\"string\"" #25990 -@test showable("text/plain", 3.14159) #26089 - -# 25959 -@test all(x -> isa(x, IO), (devnull, stdin, stdout, stderr)) -@static if !isdefined(Base, :devnull) - @test stdin === STDIN - @test stdout === STDOUT - @test stderr === STDERR -end - -# 0.7.0-DEV.3666 -module TestSockets - using Compat - using Compat.Sockets - using Compat.Test - - @test isdefined(@__MODULE__, :UDPSocket) - @test isdefined(@__MODULE__, :connect) - @test isdefined(@__MODULE__, :listen) - @test isdefined(@__MODULE__, :recv) - - @test ip"127.0.0.1".host == UInt32(2130706433) -end - -# 0.7.0-DEV.3526 -module TestNames - export foo - function bar end +@testset "range with positional stop" begin + @test range(0, 5, length=6) == 0.0:1.0:5.0 + @test range(0, 10, step=2) == 0:2:10 end -@test :foo in Compat.names(TestNames) -@test :bar in Compat.names(TestNames, all=true) - -# 0.7.0-DEV.4804 -@test Compat.trunc(pi) == 3.0 -@test Compat.floor(pi) == 3.0 -@test Compat.ceil(pi) == 4.0 -@test Compat.round(pi) == 3.0 -@test Compat.trunc(pi, digits = 3) == 3.141 -@test Compat.floor(pi, digits = 3) == 3.141 -@test Compat.ceil(pi, digits = 3) == 3.142 -@test Compat.round(pi, digits = 3) == 3.142 -@test Compat.round(pi, sigdigits = 5) == 3.1416 -@test Compat.trunc(pi, base = 2) == 3.0 -@test Compat.floor(pi, base = 2) == 3.0 -@test Compat.ceil(pi, base = 2) == 4.0 -@test Compat.round(pi, base = 2) == 3.0 -@test Compat.trunc(pi, digits = 3, base = 2) == 3.125 -@test Compat.floor(pi, digits = 3, base = 2) == 3.125 -@test Compat.ceil(pi, digits = 3, base = 2) == 3.25 -@test Compat.round(pi, digits = 3, base = 2) == 3.125 -@test Compat.round(pi, sigdigits = 5, base = 2) == 3.125 - -# 0.7.0-DEV.3734 -let buf = Compat.IOBuffer(read=true, write=false, maxsize=25) - @test buf.readable - @test !buf.writable - @test buf.maxsize == 25 -end -let buf = Compat.IOBuffer(zeros(UInt8, 4), write=true) # issue #502 - write(buf, 'a') - @test take!(buf) == [0x61] -end -let buf = Compat.IOBuffer(sizehint=20) - println(buf, "Hello world.") - @test String(take!(buf)) == "Hello world.\n" -end - -# 0.7.0-DEV.3986 -@test_throws ArgumentError Compat.range(1) -@test_throws ArgumentError Compat.range(nothing) -@test_throws ArgumentError Compat.range(1, step=1) -@test_throws ArgumentError Compat.range(1, step=1, stop=4, length=3) -@test Compat.range(2, step=2, stop=8) == 2:2:8 -@test Compat.range(2, stop=8) == 2:8 -@test Compat.range(2, step=2, length=8) == 2:2:16 -@test Compat.range(1.0, stop=2.0, length=3) == 1.0:0.5:2.0 - -# 0.7.0-DEV.3995 -mktempdir(@__DIR__) do dir - src = joinpath(dir, "src.jl") - touch(src) - dest = joinpath(dir, "dest.jl") - touch(dest) - open(src, "w") do f - write(f, "Hello, world!") - end - Compat.cp(src, dest, force = true) - open(dest, "r") do f - @test read(f, String) == "Hello, world!" - end - Compat.mv(src, dest, force = true) - open(dest, "r") do f - @test read(f, String) == "Hello, world!" - end - @test readdir(dir) == ["dest.jl"] -end - -# 0.7.0-DEV.3972 -@test Compat.indexin([1, 2], [1, 0, 1]) == [1, nothing] - -# 0.7.0-DEV.4585 -@test isuppercase('A') -@test !isuppercase('a') -@test islowercase('a') -@test !islowercase('A') -@test uppercasefirst("qwerty") == "Qwerty" -@test lowercasefirst("Qwerty") == "qwerty" - -# 0.7.0-DEV.4064 -# some tests are behind a version check below because Julia gave -# the wrong result between 0.7.0-DEV.3262 and 0.7.0-DEV.4646 -# see https://github.com/JuliaLang/julia/issues/26488 -Issue26488 = VERSION < v"0.7.0-DEV.3262" || VERSION >= v"0.7.0-DEV.4646" -@test Compat.Statistics.mean([1 2; 3 4]) == 2.5 -@test Compat.Statistics.mean([1 2; 3 4], dims=1) == [2 3] -@test Compat.Statistics.mean([1 2; 3 4], dims=2) == hcat([1.5; 3.5]) -@test Compat.cumsum([1 2; 3 4], dims=1) == [1 2; 4 6] -@test Compat.cumsum([1 2; 3 4], dims=2) == [1 3; 3 7] -@test Compat.cumprod([1 2; 3 4], dims=1) == [1 2; 3 8] -@test Compat.cumprod([1 2; 3 4], dims=2) == [1 2; 3 12] -@test Compat.sum([1 2; 3 4]) == 10 -@test Compat.sum([1 2; 3 4], dims=1) == [4 6] -@test Compat.sum([1 2; 3 4], dims=2) == hcat([3; 7]) -@test Compat.sum(x -> x+1, [1 2; 3 4]) == 14 -Issue26488 && @test Compat.sum(x -> x+1, [1 2; 3 4], dims=1) == [6 8] -Issue26488 && @test Compat.sum(x -> x+1, [1 2; 3 4], dims=2) == hcat([5; 9]) -@test Compat.prod([1 2; 3 4]) == 24 -@test Compat.prod([1 2; 3 4], dims=1) == [3 8] -@test Compat.prod([1 2; 3 4], dims=2) == hcat([2; 12]) -@test Compat.prod(x -> x+1, [1 2; 3 4]) == 120 -Issue26488 && @test Compat.prod(x -> x+1, [1 2; 3 4], dims=1) == [8 15] -Issue26488 && @test Compat.prod(x -> x+1, [1 2; 3 4], dims=2) == hcat([6; 20]) -@test Compat.maximum([1 2; 3 4]) == 4 -@test Compat.maximum([1 2; 3 4], dims=1) == [3 4] -@test Compat.maximum([1 2; 3 4], dims=2) == hcat([2; 4]) -@test Compat.maximum(x -> x+1, [1 2; 3 4]) == 5 -@test Compat.maximum(x -> x+1, [1 2; 3 4], dims=1) == [4 5] -@test Compat.maximum(x -> x+1, [1 2; 3 4], dims=2) == hcat([3; 5]) -@test Compat.minimum([1 2; 3 4]) == 1 -@test Compat.minimum([1 2; 3 4], dims=1) == [1 2] -@test Compat.minimum([1 2; 3 4], dims=2) == hcat([1; 3]) -@test Compat.minimum(x -> x+1, [1 2; 3 4]) == 2 -@test Compat.minimum(x -> x+1, [1 2; 3 4], dims=1) == [2 3] -@test Compat.minimum(x -> x+1, [1 2; 3 4], dims=2) == hcat([2; 4]) -@test Compat.all([true false; true false]) == false -@test Compat.all([true false; true false], dims=1) == [true false] -@test Compat.all([true false; true false], dims=2) == hcat([false; false]) -@test Compat.all(isodd, [1 2; 3 4]) == false -@test Compat.all(isodd, [1 2; 3 4], dims=1) == [true false] -@test Compat.all(isodd, [1 2; 3 4], dims=2) == hcat([false; false]) -@test Compat.any([true false; true false]) == true -@test Compat.any([true false; true false], dims=1) == [true false] -@test Compat.any([true false; true false], dims=2) == hcat([true; true]) -@test Compat.any(isodd, [1 2; 3 4]) == true -@test Compat.any(isodd, [1 2; 3 4], dims=1) == [true false] -@test Compat.any(isodd, [1 2; 3 4], dims=2) == hcat([true; true]) -@test Compat.findmax([3, 2, 7, 4]) == (7, 3) -@test Compat.findmax([3, 2, 7, 4], dims=1) == ([7], [3]) -@test Compat.findmax([1 2; 3 4], dims=1) == ([3 4], [CartesianIndex(2, 1) CartesianIndex(2, 2)]) -@test Compat.findmax([1 2; 3 4]) == (4, CartesianIndex(2, 2)) -@test Compat.findmax([1 2; 3 4], dims=1) == ([3 4], [CartesianIndex(2, 1) CartesianIndex(2, 2)]) -@test Compat.findmax([1 2; 3 4], dims=2) == (hcat([2; 4]), hcat([CartesianIndex(1, 2); CartesianIndex(2, 2)])) -@test Compat.findmin([3, 2, 7, 4]) == (2, 2) -@test Compat.findmin([3, 2, 7, 4], dims=1) == ([2], [2]) -@test Compat.findmin([1 2; 3 4]) == (1, CartesianIndex(1, 1)) -@test Compat.findmin([1 2; 3 4], dims=1) == ([1 2], [CartesianIndex(1, 1) CartesianIndex(1, 2)]) -@test Compat.findmin([1 2; 3 4], dims=2) == (hcat([1; 3]), hcat([CartesianIndex(1, 1); CartesianIndex(2, 1)])) -if VERSION < v"0.7.0-DEV.5238" - # Test these functions if their counterparts are defined in Base. In the future, this - # will be dealt with in StatsBase - @test Compat.Statistics.varm([1 2; 3 4], -1) == 18 - @test Compat.Statistics.varm([1 2; 3 4], [-1 -2], dims=1) == [20 52] - @test Compat.Statistics.varm([1 2; 3 4], [-1, -2], dims=2) == hcat([13, 61]) - @test Compat.Statistics.var([1 2; 3 4]) == 5/3 - @test Compat.Statistics.var([1 2; 3 4], dims=1) == [2 2] - @test Compat.Statistics.var([1 2; 3 4], dims=2) == hcat([0.5, 0.5]) - @test Compat.Statistics.var([1 2; 3 4], corrected=false) == 1.25 - @test Compat.Statistics.var([1 2; 3 4], corrected=false, dims=1) == [1 1] - @test Compat.Statistics.var([1 2; 3 4], corrected=false, dims=2) == hcat([0.25, 0.25]) - @test Compat.Statistics.std([1 2; 3 4]) == sqrt(5/3) - @test Compat.Statistics.std([1 2; 3 4], dims=1) == [sqrt(2) sqrt(2)] - @test Compat.Statistics.std([1 2; 3 4], dims=2) == hcat([sqrt(0.5), sqrt(0.5)]) - @test Compat.Statistics.std([1 2; 3 4], corrected=false) == sqrt(1.25) - @test Compat.Statistics.std([1 2; 3 4], corrected=false, dims=1) == [sqrt(1) sqrt(1)] - @test Compat.Statistics.std([1 2; 3 4], corrected=false, dims=2) == hcat([sqrt(0.25), sqrt(0.25)]) - @test Compat.Statistics.cov([1 2; 3 4]) == [2 2; 2 2] - @test Compat.Statistics.cov([1 2; 3 4], dims=1) == [2 2; 2 2] - @test Compat.Statistics.cov([1 2; 3 4], dims=2) == [0.5 0.5; 0.5 0.5] - @test Compat.Statistics.cov([1 2; 3 4], [4; 5]) == hcat([1; 1]) - @test Compat.Statistics.cov([1 2; 3 4], [4; 5], dims=1) == hcat([1; 1]) - @test Compat.Statistics.cov([1 2; 3 4], [4; 5], dims=2) == hcat([0.5; 0.5]) - @test Compat.Statistics.cov([1 2; 3 4], [4; 5], corrected=false) == hcat([0.5; 0.5]) - @test Compat.Statistics.cov([1 2; 3 4], [4; 5], corrected=false, dims=1) == hcat([0.5; 0.5]) - @test Compat.Statistics.cov([1 2; 3 4], [4; 5], corrected=false, dims=2) == hcat([0.25; 0.25]) - @test Compat.Statistics.cor([1 2; 3 4]) ≈ [1 1; 1 1] - @test Compat.Statistics.cor([1 2; 3 4], dims=1) ≈ [1 1; 1 1] - @test Compat.Statistics.cor([1 2; 3 4], dims=2) ≈ [1 1; 1 1] - @test Compat.Statistics.cor([1 2; 3 4], [4; 5]) ≈ [1; 1] - @test Compat.Statistics.cor([1 2; 3 4], [4; 5], dims=1) ≈ [1; 1] - @test Compat.Statistics.cor([1 2; 3 4], [4; 5], dims=2) ≈ [1; 1] -end -@test Compat.Statistics.median([1 2; 3 4]) == 2.5 -@test Compat.Statistics.median([1 2; 3 4], dims=1) == [2 3] -@test Compat.Statistics.median([1 2; 3 4], dims=2) == hcat([1.5; 3.5]) -@test Compat.mapreduce(string, *, [1 2; 3 4]) == "1324" -Issue26488 && @test Compat.mapreduce(string, *, [1 2; 3 4], dims=1) == ["13" "24"] -Issue26488 && @test Compat.mapreduce(string, *, [1 2; 3 4], dims=2) == hcat(["12", "34"]) -@test Compat.mapreduce(string, *, [1 2; 3 4], init="z") == "z1324" -@test Compat.mapreduce(string, *, (1, 2, 3, 4), init="z") == "z1234" -@test Compat.mapreduce(string, *, [1 2; 3 4], dims=1, init="z") == ["z13" "z24"] -@test Compat.mapreduce(string, *, [1 2; 3 4], dims=2, init="z") == hcat(["z12", "z34"]) -@test Compat.reduce(*, [1 2; 3 4]) == 24 -@test Compat.reduce(*, [1 2; 3 4], dims=1) == [3 8] -@test Compat.reduce(*, [1 2; 3 4], dims=2) == hcat([2, 12]) -@test Compat.reduce(*, [1 2; 3 4], init=10) == 240 -@test Compat.reduce(*, (1, 2, 3, 4), init=10) == 240 -@test Compat.reduce(*, [1 2; 3 4], dims=1, init=10) == [30 80] -@test Compat.reduce(*, [1 2; 3 4], dims=2, init=10) == hcat([20, 120]) -@test Compat.sort([1, 2, 3, 4]) == [1, 2, 3, 4] -@test Compat.sort([1 2; 3 4], dims=1) == [1 2; 3 4] -@test Compat.sort([1 2; 3 4], dims=2) == [1 2; 3 4] -@test Compat.sort([1, 2, 3, 4], rev=true) == [4, 3, 2, 1] -@test Compat.sort([1 2; 3 4], rev=true, dims=1) == [3 4; 1 2] -@test Compat.sort([1 2; 3 4], rev=true, dims=2) == [2 1; 4 3] -@test Compat.accumulate(*, [1 2; 3 4], dims=1) == [1 2; 3 8] -@test Compat.accumulate(*, [1 2; 3 4], dims=2) == [1 2; 3 12] -@test Compat.cumsum([1 2; 3 4], dims=1) == [1 2; 4 6] -@test Compat.cumsum([1 2; 3 4], dims=2) == [1 3; 3 7] -@test Compat.cumprod([1 2; 3 4], dims=1) == [1 2; 3 8] -@test Compat.cumprod([1 2; 3 4], dims=2) == [1 2; 3 12] -let b = zeros(2,2) - Compat.accumulate!(*, b, [1 2; 3 4], dims=1) - @test b == [1 2; 3 8] - Compat.accumulate!(*, b, [1 2; 3 4], dims=2) - @test b == [1 2; 3 12] - Compat.cumsum!(b, [1 2; 3 4], dims=1) - @test b == [1 2; 4 6] - Compat.cumsum!(b, [1 2; 3 4], dims=2) - @test b == [1 3; 3 7] - Compat.cumprod!(b, [1 2; 3 4], dims=1) - @test b == [1 2; 3 8] - Compat.cumprod!(b, [1 2; 3 4], dims=2) - @test b == [1 2; 3 12] -end -@test Compat.reverse([1, 2, 3, 4]) == [4, 3, 2, 1] -@test Compat.reverse([1 2; 3 4], dims=1) == [3 4; 1 2] -@test Compat.reverse([1 2; 3 4], dims=2) == [2 1; 4 3] -# Issue #523 -@test length(Compat.CartesianIndices((1:1,))) == 1 -@test length(Compat.CartesianIndices((1:2,))) == 2 -@test length(Compat.CartesianIndices((1:2, -1:1))) == 6 - -# 0.7.0-DEV.4738 -if VERSION < v"0.7.0-beta2.143" - @test squeeze([1 2], dims=1) == [1, 2] - @test_throws ArgumentError squeeze([1 2], dims=2) - @test_throws ArgumentError squeeze(hcat([1, 2]), dims=1) - @test squeeze(hcat([1, 2]), dims=2) == [1, 2] - @test_throws Exception squeeze([1,2]) -end - -# 0.7.0-DEV.5165 -@test Compat.cat([1, 2], [3, 4, 5], dims = 1) == [1, 2, 3, 4, 5] -@test Compat.cat([1, 2], [3, 4], dims = 2) == [1 3; 2 4] -if VERSION < v"0.7.0-DEV.5165" - @test_throws UndefKeywordError Compat.cat([1, 2], [3, 4]) -end - -# 0.7.0-DEV.3976 -let A = rand(5,5) - @test selectdim(A, 1, 3) == A[3, :] - @test selectdim(A, 1, 1:3) == A[1:3, :] - @test selectdim(A, 2, 3) == A[:, 3] - @test selectdim(A, 2, 1:3) == A[:, 1:3] - selectdim(A, 1, 3)[3] = 42 - @test A[3,3] == 42 - if VERSION < v"0.7.0-DEV.3976" || VERSION >= v"0.7.0-DEV.4739" - # in the omitted version range, Julia's selectdim always gives IndexCartesian() - B = rand(4, 3, 2) - @test IndexStyle(selectdim(B, 1, 1)) == IndexStyle(view(B, 1, :, :)) == IndexLinear() - @test IndexStyle(selectdim(B, 2, 1)) == IndexStyle(view(B, :, 1, :)) == IndexCartesian() - @test IndexStyle(selectdim(B, 3, 1)) == IndexStyle(view(B, :, :, 1)) == IndexLinear() - end -end - -# 0.7.0-DEV.843 / 0.7.0-DEV.2337 -let A = [1 2; 1 2; 1 2] - if VERSION < v"0.7.0-DEV.5211" - # the full keyword was only temporarily available in Base, so these methods don't - # work on 0.7 anymore, but we test them for the time being to avoid accidentally - # breaking anyone's code - f = Compat.qr(A, Val(false), full=false) - @test f == Compat.qr(A, Val(false)) - @test length(f) == 2 - @test size(f[1]) == (3, 2) - @test f[1] * f[2] ≈ A - f = Compat.qr(A, Val(false), full=true) - @test length(f) == 2 - @test size(f[1]) == (3, 3) - @test f[1] * [f[2]; [0 0]] ≈ A - f = Compat.qr(A, Val(true), full=false) - @test f == Compat.qr(A, Val(true)) - @test length(f) == 3 - @test size(f[1]) == (3, 2) - @test f[1] * f[2] ≈ A[:,f[3]] - f = Compat.qr(A, Val(true), full=true) - @test length(f) == 3 - @test size(f[1]) == (3, 3) - @test f[1] * [f[2]; [0 0]] ≈ A[:,f[3]] - else - f = Compat.qr(A, Val(false)) - @test size(f.Q) == (3, 3) - @test f.Q * [f.R; [0 0]] ≈ A - f = Compat.qr(A, Val(true)) - @test size(f.Q) == (3, 3) - @test f.Q * [f.R; [0 0]] ≈ A[:,f.p] - end -end - -let A = [1 2; 3 4] - @test Compat.rmul!(A, 2) == [2 4; 6 8] - @test Compat.rmul!(A, Diagonal([1, 2])) == [2 8; 6 16] - @test Compat.rmul!(A, UpperTriangular([2 2; 3 3])) == [4 28; 12 60] - @test Compat.rmul!(LowerTriangular(A), Diagonal([1, 2])) == LowerTriangular([4 0; 12 120]) - @test Compat.rmul!(Diagonal(A), Diagonal([2, 1])) == Diagonal([8, 120]) -end - -# 0.7.0-DEV.3936 -@test let ct = current_task(), t = @task true - schedule(ct) - yieldto(t) - fetch(t) -end - -# 0.7.0-DEV.5087 -@test isletter('a') -@test isletter('β') -@test !isletter('3') - -# 0.7.0-DEV.4905 -@test isbitstype(Int) -@test !isbitstype(Vector{Int}) - -# 0.7.0-DEV.4762 -let ptr = @cfunction(+, Int, (Int, Int)) - @test ptr isa Ptr{Cvoid} - @test ptr != C_NULL - @test ccall(ptr, Int, (Int, Int), 2, 3) == 5 -end -# issue #565 -issue565(x) = x + 1 -const Issue565 = Int -let bar() = @cfunction(issue565, Issue565, (Issue565,)), ptr = bar() - @test ptr isa Ptr{Cvoid} - @test ptr != C_NULL - @test ccall(ptr, Int, (Int,), 2) === 3 -end - -# 0.7.0-DEV.5278 -@test something(nothing, 1) === 1 -@test something(Some(2)) === 2 -@test something(Some(2), 1) === 2 -@test something(nothing, Some(1)) === 1 - -# julia#24999 -let s = "∀α>β:α+" - @test [length(s,i,j) for i=1:ncodeunits(s)+1, j=0:ncodeunits(s)] == - [0 1 1 1 2 2 3 4 4 5 6 6 7; 0 0 0 0 1 1 2 3 3 4 5 5 6; 0 0 0 0 1 1 2 3 3 4 5 5 6; 0 0 0 0 1 1 2 3 3 4 5 5 6; 0 0 0 0 0 0 1 2 2 3 4 4 5; 0 0 0 0 0 0 1 2 2 3 4 4 5; 0 0 0 0 0 0 0 1 1 2 3 3 4; 0 0 0 0 0 0 0 0 0 1 2 2 3; 0 0 0 0 0 0 0 0 0 1 2 2 3; 0 0 0 0 0 0 0 0 0 0 1 1 2; 0 0 0 0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 0 0 0 0 0] -end -@test_throws BoundsError length("hello", 1, -1) -@test_throws BoundsError length("hellø", 1, -1) -@test_throws BoundsError length("hello", 1, 10) -@test_throws BoundsError length("hellø", 1, 10) == 9 -@test_throws BoundsError prevind("hello", 0, 1) -@test_throws BoundsError prevind("hellø", 0, 1) -@test nextind("hello", 0, 10) == 10 -# julia#24414 -let strs = Any["∀α>β:α+1>β", SubString("123∀α>β:α+1>β123", 4, 18)] - for s in strs - @test_throws BoundsError thisind(s, -2) - @test_throws BoundsError thisind(s, -1) - @test thisind(s, 0) == 0 - @test thisind(s, 1) == 1 - @test thisind(s, 2) == 1 - @test thisind(s, 3) == 1 - @test thisind(s, 4) == 4 - @test thisind(s, 5) == 4 - @test thisind(s, 6) == 6 - @test thisind(s, 15) == 15 - @test thisind(s, 16) == 15 - @test thisind(s, 17) == 17 - @test_throws BoundsError thisind(s, 18) - @test_throws BoundsError thisind(s, 19) - end -end -let strs = Any["", SubString("123", 2, 1)] - for s in strs - @test_throws BoundsError thisind(s, -1) - @test thisind(s, 0) == 0 - @test thisind(s, 1) == 1 - @test_throws BoundsError thisind(s, 2) - end -end -# prevind and nextind, julia#23805 -let s = "∀α>β:α+1>β" - @test_throws BoundsError prevind(s, 0, 0) - @test_throws BoundsError prevind(s, 0, 1) - @test prevind(s, 1, 1) == 0 - @test prevind(s, 1, 0) == 1 - @test prevind(s, 2, 1) == 1 - @test prevind(s, 4, 1) == 1 - @test prevind(s, 5, 1) == 4 - @test prevind(s, 5, 2) == 1 - @test prevind(s, 5, 3) == 0 - @test prevind(s, 15, 1) == 14 - @test prevind(s, 15, 2) == 13 - @test prevind(s, 15, 3) == 12 - @test prevind(s, 15, 4) == 10 - @test prevind(s, 15, 10) == 0 - @test prevind(s, 15, 9) == 1 - @test prevind(s, 16, 1) == 15 - @test prevind(s, 16, 2) == 14 - @test prevind(s, 17, 1) == 15 - @test prevind(s, 17, 2) == 14 - @test_throws BoundsError prevind(s, 18, 0) - @test_throws BoundsError prevind(s, 18, 1) - @test_throws BoundsError nextind(s, -1, 0) - @test_throws BoundsError nextind(s, -1, 1) - @test nextind(s, 0, 2) == 4 - @test nextind(s, 0, 20) == 26 - @test nextind(s, 0, 10) == 15 - @test nextind(s, 1, 1) == 4 - @test nextind(s, 1, 2) == 6 - @test nextind(s, 1, 9) == 15 - @test nextind(s, 1, 10) == 17 - @test nextind(s, 2, 1) == 4 - @test nextind(s, 3, 1) == 4 - @test nextind(s, 4, 1) == 6 - @test nextind(s, 14, 1) == 15 - @test nextind(s, 15, 1) == 17 - @test nextind(s, 15, 2) == 18 - @test nextind(s, 16, 1) == 17 - @test nextind(s, 16, 2) == 18 - @test nextind(s, 16, 3) == 19 - @test_throws BoundsError nextind(s, 17, 0) - @test_throws BoundsError nextind(s, 17, 1) - for k in 0:ncodeunits(s)+1 - n = p = k - for j in 1:40 - if 1 ≤ p - p = prevind(s, p) - @test prevind(s, k, j) == p - end - if n ≤ ncodeunits(s) - n = nextind(s, n) - @test nextind(s, k, j) == n - end - end - end -end - -# 0.7.0-DEV.5171 -let sep = Compat.Sys.iswindows() ? ';' : ':' - withenv("PATH" => string(Compat.Sys.BINDIR, sep, get(ENV, "PATH", ""))) do - jl = joinpath(Compat.Sys.BINDIR, "julia") * (Compat.Sys.iswindows() ? ".exe" : "") - @test Compat.Sys.which("julia") == realpath(jl) - @test Compat.Sys.isexecutable(jl) - @test Compat.Sys.which("reallyseriouslynotathingyoushouldhave") === nothing - end -end - -# julia#24839 -@test permutedims([1 2; 3 4]) == [1 3; 2 4] -@test permutedims([1,2,3]) == [1 2 3] - -# julia#27401 -import Compat: ⋅ -@test Compat.opnorm([1 2;3 4]) ≈ 5.464985704219043 -@test Compat.opnorm([1 2;3 4], 1) ≈ 6 -@test Compat.norm([1 2;3 4]) ≈ 5.477225575051661 -@test Compat.norm([1 2;3 4], 1) ≈ 10 -@test Compat.dot([1 2;3 4], [5 6;7 8]) == [1 2;3 4] ⋅ [5 6;7 8] ≈ 70 - -# 0.7.0-alpha.44 -@test atan(1, 2) == atan(0.5) -@test atan(1.0, 2.0) == atan(0.5) -@test atan(-1.0, -2.0) ≈ atan(0.5) - π -@test atan(big"-1.0", big"-2.0") ≈ atan(big"0.5") - π - -# 0.7.0-DEV.4724 -let - @test Compat.split("", ',' ; keepempty=false) == [] - @test Compat.split(",", ',' ; keepempty=false) == [] - @test Compat.split(",,", ','; keepempty=false) == [] - @test Compat.rsplit("", ',' ; keepempty=false) == [] - @test Compat.rsplit(",", ',' ; keepempty=false) == [] - @test Compat.rsplit(",,", ','; keepempty=false) == [] - - str = "a.:.ba..:..cba.:.:.dcba.:." - @test Compat.split(str, ".:."; keepempty=false) == ["a","ba.",".cba",":.dcba"] - @test Compat.split(str, ".:."; keepempty=true) == ["a","ba.",".cba",":.dcba",""] - @test Compat.split(str, ".:."; limit=3, keepempty=false) == ["a","ba.",".cba.:.:.dcba.:."] - @test Compat.split(str, ".:."; limit=3, keepempty=true) == ["a","ba.",".cba.:.:.dcba.:."] - @test Compat.rsplit(str, ".:."; keepempty=false) == ["a","ba.",".cba.:","dcba"] - @test Compat.rsplit(str, ".:."; keepempty=true) == ["a","ba.",".cba.:","dcba",""] - @test Compat.rsplit(str, ".:."; limit=3, keepempty=false) == ["a.:.ba.",".cba.:","dcba"] - @test Compat.rsplit(str, ".:."; limit=3, keepempty=true) == ["a.:.ba..:..cba.:","dcba",""] - - @test Compat.split(str, r"\.(:\.)+"; keepempty=false) == ["a","ba.",".cba","dcba"] - @test Compat.split(str, r"\.(:\.)+"; keepempty=true) == ["a","ba.",".cba","dcba",""] - @test Compat.split(str, r"\.(:\.)+"; limit=3, keepempty=false) == ["a","ba.",".cba.:.:.dcba.:."] - @test Compat.split(str, r"\.(:\.)+"; limit=3, keepempty=true) == ["a","ba.",".cba.:.:.dcba.:."] - @test Compat.split(str, r"\.+:\.+"; keepempty=false) == ["a","ba","cba",":.dcba"] - @test Compat.split(str, r"\.+:\.+"; keepempty=true) == ["a","ba","cba",":.dcba",""] - @test Compat.split(str, r"\.+:\.+"; limit=3, keepempty=false) == ["a","ba","cba.:.:.dcba.:."] - @test Compat.split(str, r"\.+:\.+"; limit=3, keepempty=true) == ["a","ba","cba.:.:.dcba.:."] -end - -let - # test required keyword arguments - @compat func1() = 1 - @test func1() == 1 # using the function works - @compat func2(x) = x - @test func2(3) == 3 # using the function works - @compat func3(;y) = y - @test func3(y=2) == 2 # using the function works - @test_throws UndefKeywordError func3() - @compat func4(x; z) = x*z - @test func4(2,z=3) == 6 # using the function works - @test_throws UndefKeywordError func4(2) - @compat func5(;x=1, y) = x*y - @test func5(y=3) == 3 - @test func5(y=3, x=2) == 6 - @test_throws UndefKeywordError func5(x=2) -end - -# 0.7.0-beta.73 -let a = rand(5,5) - s = mapslices(sort, a, dims=[1]) - S = mapslices(sort, a, dims=[2]) - for i = 1:5 - @test s[:,i] == sort(a[:,i]) - @test vec(S[i,:]) == sort(vec(a[i,:])) - end -end - -# 0.7.0-beta2.171 -Random.seed!(1) -rng = MersenneTwister(0) -Random.seed!(rng, 1) -@test rand(rng) ≈ 0.23603334566204692 -@test 0 < rand(Random.GLOBAL_RNG, Random.RangeGenerator(1:3)) < 4 - -# 0.7.0-beta2.169 -@test floatmin(Float16) == @eval $(Core.Intrinsics.bitcast(Float16, 0x0400)) -@test floatmax(Float32) == @eval $(Core.Intrinsics.bitcast(Float32, 0x7f7fffff)) -@test floatmin(zero(Float64)) == floatmin(Float64) - -# 0.7.0-beta2.143 -if VERSION < v"0.7.0-beta2.143" - let a = reshape(Vector(1:4),(2,2,1,1)), b = reshape(Vector(1:4), (2,2,1)) - @test dropdims(a; dims=3) == b - @test_throws UndefKeywordError dropdims(a) - end -end - -@test repeat([1, 2], 3) == [1, 2, 1, 2, 1, 2] -@test repeat(1:4, 2) == [1, 2, 3, 4, 1, 2, 3, 4] -@test repeat([1 2; 3 4], 2, 3) == [1 2 1 2 1 2 - 3 4 3 4 3 4 - 1 2 1 2 1 2 - 3 4 3 4 3 4] -@test repeat([1, 2], 1, 2, 3) == [x for x in 1:2, y in 1:2, z in 1:3] - -# Support for positional `stop` -@test Compat.range(0, 5, length = 6) == 0.0:1.0:5.0 -@test Compat.range(0, 10, step = 2) == 0:2:10 mutable struct TLayout x::Int8 y::Int16 z::Int32 end -tlayout = TLayout(5,7,11) -@test hasfield(TLayout, :y) -@test !hasfield(TLayout, :a) -if VERSION >= v"0.7-" +@testset "hasfield and hasproperty" begin + tlayout = TLayout(5,7,11) + @test hasfield(TLayout, :y) + @test !hasfield(TLayout, :a) @test hasproperty(tlayout, :x) @test !hasproperty(tlayout, :p) end - -nothing