From 2ba8f604ac1714c884737ae6ef562257d3cd4150 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Wed, 3 Apr 2024 12:31:22 +0530 Subject: [PATCH] zeros/ones/fill/trues/falses may accept AbstractUnitRange dims --- base/array.jl | 6 ++++++ base/bitarray.jl | 2 ++ 2 files changed, 8 insertions(+) diff --git a/base/array.jl b/base/array.jl index ef91077dd6e96..e4092c08bd2a8 100644 --- a/base/array.jl +++ b/base/array.jl @@ -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) """ @@ -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 diff --git a/base/bitarray.jl b/base/bitarray.jl index 079dbefe03a94..dc3fa141fa359 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -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) """ @@ -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)