Skip to content

Commit

Permalink
ones should call oneunit
Browse files Browse the repository at this point in the history
According to docstring, `ones` creates an array of `T`, hence it should
call `oneunit` rather than `one`. See JuliaLang#16116 and JuliaLang#20268.
  • Loading branch information
Mayeul d'Avezac committed Sep 13, 2017
1 parent 8158a1b commit 6fdbda3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ See also [`zeros`](@ref), [`similar`](@ref).
"""
function ones end

for (fname, felt) in ((:zeros,:zero), (:ones,:one))
for (fname, felt) in ((:zeros,:zero), (:ones,:oneunit))
@eval begin
# allow signature of similar
$fname(a::AbstractArray, T::Type, dims::Tuple) = fill!(similar(a, T, dims), $felt(T))
Expand Down
6 changes: 5 additions & 1 deletion test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Array test
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
using TestHelpers.OAs
using TestHelpers: OAs, Furlong

@testset "basics" begin
@test length([1, 2, 3]) == 3
Expand Down Expand Up @@ -2175,6 +2175,10 @@ end
oarr = zeros(randn(3), UInt16, 1:3, -1:0)
@test indices(oarr) == (1:3, -1:0)
test_zeros(oarr.parent, Matrix{UInt16}, (3, 2))

# works with oneunit rather than one
@test eltype(ones(Furlong{3, Int16}, 2)) === Furlong{3, Int16}
@test eltype(zeros(Furlong{2, Int32}, 2)) === Furlong{2, Int32}
end

# issue #11053
Expand Down

0 comments on commit 6fdbda3

Please sign in to comment.