We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ac46027 commit 86bd62bCopy full SHA for 86bd62b
README.md
@@ -153,6 +153,8 @@ Currently, the `@compat` macro supports the following syntaxes:
153
154
* `broadcast` is supported on tuples of the same lengths on 0.5. ([#16986])
155
156
+* `zeros` and `ones` support an interface the same as `similar` ([#19635])
157
+
158
## Renamed functions
159
160
* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively
@@ -346,3 +348,4 @@ includes this fix. Find the minimum version from there.
346
348
[#20414]: https://github.com/JuliaLang/julia/issues/20414
347
349
[#20418]: https://github.com/JuliaLang/julia/issues/20418
350
[#20500]: https://github.com/JuliaLang/julia/issues/20500
351
+[#19635]: https://github.com/JuliaLang/julia/issues/19635
src/Compat.jl
@@ -1421,6 +1421,17 @@ if VERSION < v"0.6.0-dev.2840"
1421
IndexStyle(args...) = Base.linearindexing(args...)
1422
end
1423
1424
+if VERSION < v"0.6.0-dev.1653"
1425
+ for (fname, felt) in ((:zeros,:zero), (:ones,:one))
1426
+ @eval begin
1427
+ # allow signature of similar
1428
+ Base.$fname(a::AbstractArray, T::Type, dims::Tuple) = fill!(similar(a, T, dims), $felt(T))
1429
+ Base.$fname(a::AbstractArray, T::Type, dims...) = fill!(similar(a,T,dims...), $felt(T))
1430
+ Base.$fname(a::AbstractArray, T::Type=eltype(a)) = fill!(similar(a,T), $felt(T))
1431
+ end
1432
1433
+end
1434
1435
# https://github.com/JuliaLang/julia/pull/20203
1436
if VERSION < v"0.6.0-dev.2283"
1437
# not exported
test/runtests.jl
@@ -1773,9 +1773,22 @@ let a = CompatArray.CartesianArray(rand(2,3)), b = CompatArray.LinearArray(rand(
1773
@test IndexStyle(b) === IndexLinear()
1774
1775
1776
+for (A,val) in ((zeros(1:5, Float32, 3, 2), 0),
1777
+ (ones(1:5, Float32, 3, 2), 1),
1778
+ (zeros(1:5, Float32, (3, 2)), 0),
1779
+ (ones(1:5, Float32, (3, 2)), 1))
1780
+ @test isa(A, Matrix{Float32}) && size(A) == (3,2) && all(x->x==val, A)
1781
1782
+for (A,val) in ((zeros(1:5, Float32), 0),
1783
+ (ones(1:5, Float32), 1))
1784
+ @test isa(A, Vector{Float32}) && size(A) == (5,) && all(x->x==val, A)
1785
1786
1787
# PR 20203
1788
@test Compat.readline(IOBuffer("Hello, World!\n")) == "Hello, World!"
1789
@test Compat.readline(IOBuffer("x\n"), chomp=true) == "x"
1790
@test Compat.readline(IOBuffer("x\n"), chomp=false) == "x\n"
1791
1792
include("to-be-deprecated.jl")
1793
1794
+nothing
0 commit comments