Skip to content

Commit 0dedc4d

Browse files
committed
Support new zeros/ones methods from #19635
1 parent 9a95537 commit 0dedc4d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Compat.jl

+12
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,18 @@ if VERSION < v"0.6.0-dev.2840"
14111411
IndexStyle(args...) = Base.linearindexing(args...)
14121412
end
14131413

1414+
if VERSION < v"0.6.0-dev.1653"
1415+
for (fname, felt) in ((:zeros,:zero), (:ones,:one))
1416+
@eval begin
1417+
# allow signature of similar
1418+
Base.$fname(a::AbstractArray, T::Type, dims::Tuple) = fill!(similar(a, T, dims), $felt(T))
1419+
Base.$fname(a::AbstractArray, T::Type, dims...) = fill!(similar(a,T,dims...), $felt(T))
1420+
Base.$fname(a::AbstractArray, T::Type=eltype(a)) = fill!(similar(a,T), $felt(T))
1421+
end
1422+
end
1423+
end
1424+
1425+
14141426
include("to-be-deprecated.jl")
14151427

14161428
end # module Compat

test/runtests.jl

+13
Original file line numberDiff line numberDiff line change
@@ -1763,4 +1763,17 @@ let a = CompatArray.CartesianArray(rand(2,3)), b = CompatArray.LinearArray(rand(
17631763
@test IndexStyle(b) === IndexLinear()
17641764
end
17651765

1766+
for (A,val) in ((zeros(1:5, Float32, 3, 2), 0),
1767+
(ones(1:5, Float32, 3, 2), 1),
1768+
(zeros(1:5, Float32, (3, 2)), 0),
1769+
(ones(1:5, Float32, (3, 2)), 1))
1770+
@test isa(A, Matrix{Float32}) && size(A) == (3,2) && all(x->x==val, A)
1771+
end
1772+
for (A,val) in ((zeros(1:5, Float32), 0),
1773+
(ones(1:5, Float32), 1))
1774+
@test isa(A, Vector{Float32}) && size(A) == (5,) && all(x->x==val, A)
1775+
end
1776+
17661777
include("to-be-deprecated.jl")
1778+
1779+
nothing

0 commit comments

Comments
 (0)