Skip to content

Commit

Permalink
Add generic fill method accepting return type as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Jun 13, 2016
1 parent c574b4d commit deae75b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ this is equivalent to `collect(a)`.
"""
copymutable

fill{T<:AbstractArray}(::Type{T}, v, dims::Dims) = fill!(fixate_eltype(T, typeof(v))(dims), v)

zero{T}(x::AbstractArray{T}) = fill!(similar(x), zero(T))

## iteration support for arrays by iterating over `eachindex` in the array ##
Expand Down
4 changes: 2 additions & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ function fill!{T<:Union{Integer,AbstractFloat}}(a::Array{T}, x)
return a
end

fill(v, dims::Dims) = fill!(Array{typeof(v)}(dims), v)
fill(v, dims::Integer...) = fill!(Array{typeof(v)}(dims...), v)
fill(v, dims::Dims) = fill(Array, v, dims)
fill(v, dims::Integer...) = fill(Array, v, convert(Dims, dims))

for (fname, felt) in ((:zeros,:zero), (:ones,:one))
@eval begin
Expand Down

0 comments on commit deae75b

Please sign in to comment.