Skip to content

Commit

Permalink
zeros/ones/fill/trues/falses may accept AbstractUnitRange dims
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Apr 5, 2024
1 parent 5f4dec1 commit 2ba8f60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ function fill end
fill(v, dims::DimOrInd...) = fill(v, dims)
fill(v, dims::NTuple{N, Union{Integer, OneTo}}) where {N} = fill(v, map(to_dim, dims))
fill(v, dims::NTuple{N, Integer}) where {N} = (a=Array{typeof(v),N}(undef, dims); fill!(a, v); a)
fill(v, dims::NTuple{N, DimOrInd}) where {N} = (a=similar(Array{typeof(v),N}, dims); fill!(a, v); a)
fill(v, dims::Tuple{}) = (a=Array{typeof(v),0}(undef, dims); fill!(a, v); a)

"""
Expand Down Expand Up @@ -589,6 +590,11 @@ for (fname, felt) in ((:zeros, :zero), (:ones, :one))
fill!(a, $felt(T))
return a
end
function $fname(::Type{T}, dims::NTuple{N, DimOrInd}) where {T,N}
a = similar(Array{T,N}, dims)
fill!(a, $felt(T))
return a
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ julia> falses(2,3)
falses(dims::DimOrInd...) = falses(dims)
falses(dims::NTuple{N, Union{Integer, OneTo}}) where {N} = falses(map(to_dim, dims))
falses(dims::NTuple{N, Integer}) where {N} = fill!(BitArray(undef, dims), false)
falses(dims::NTuple{N, DimOrInd}) where {N} = fill!(BitArray(undef, dims), false)
falses(dims::Tuple{}) = fill!(BitArray(undef, dims), false)

"""
Expand All @@ -421,6 +422,7 @@ julia> trues(2,3)
trues(dims::DimOrInd...) = trues(dims)
trues(dims::NTuple{N, Union{Integer, OneTo}}) where {N} = trues(map(to_dim, dims))
trues(dims::NTuple{N, Integer}) where {N} = fill!(BitArray(undef, dims), true)
trues(dims::NTuple{N, DimOrInd}) where {N} = fill!(BitArray(undef, dims), true)
trues(dims::Tuple{}) = fill!(BitArray(undef, dims), true)

function one(x::BitMatrix)
Expand Down

0 comments on commit 2ba8f60

Please sign in to comment.