Skip to content

Commit

Permalink
Support new zeros/ones methods from #19635 (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored and TotalVerb committed Mar 24, 2017
1 parent ac46027 commit 86bd62b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `broadcast` is supported on tuples of the same lengths on 0.5. ([#16986])

* `zeros` and `ones` support an interface the same as `similar` ([#19635])

## Renamed functions

* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively
Expand Down Expand Up @@ -346,3 +348,4 @@ includes this fix. Find the minimum version from there.
[#20414]: https://github.com/JuliaLang/julia/issues/20414
[#20418]: https://github.com/JuliaLang/julia/issues/20418
[#20500]: https://github.com/JuliaLang/julia/issues/20500
[#19635]: https://github.com/JuliaLang/julia/issues/19635
11 changes: 11 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,17 @@ if VERSION < v"0.6.0-dev.2840"
IndexStyle(args...) = Base.linearindexing(args...)
end

if VERSION < v"0.6.0-dev.1653"
for (fname, felt) in ((:zeros,:zero), (:ones,:one))
@eval begin
# allow signature of similar
Base.$fname(a::AbstractArray, T::Type, dims::Tuple) = fill!(similar(a, T, dims), $felt(T))
Base.$fname(a::AbstractArray, T::Type, dims...) = fill!(similar(a,T,dims...), $felt(T))
Base.$fname(a::AbstractArray, T::Type=eltype(a)) = fill!(similar(a,T), $felt(T))
end
end
end

# https://github.com/JuliaLang/julia/pull/20203
if VERSION < v"0.6.0-dev.2283"
# not exported
Expand Down
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1773,9 +1773,22 @@ let a = CompatArray.CartesianArray(rand(2,3)), b = CompatArray.LinearArray(rand(
@test IndexStyle(b) === IndexLinear()
end

for (A,val) in ((zeros(1:5, Float32, 3, 2), 0),
(ones(1:5, Float32, 3, 2), 1),
(zeros(1:5, Float32, (3, 2)), 0),
(ones(1:5, Float32, (3, 2)), 1))
@test isa(A, Matrix{Float32}) && size(A) == (3,2) && all(x->x==val, A)
end
for (A,val) in ((zeros(1:5, Float32), 0),
(ones(1:5, Float32), 1))
@test isa(A, Vector{Float32}) && size(A) == (5,) && all(x->x==val, A)
end

# PR 20203
@test Compat.readline(IOBuffer("Hello, World!\n")) == "Hello, World!"
@test Compat.readline(IOBuffer("x\n"), chomp=true) == "x"
@test Compat.readline(IOBuffer("x\n"), chomp=false) == "x\n"

include("to-be-deprecated.jl")

nothing

0 comments on commit 86bd62b

Please sign in to comment.