- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zeros #19635
Zeros #19635
Changes from 2 commits
39a3bde
b3a93f2
38d34e7
8f824a2
259668b
757e7ac
b71e9e0
e80a695
85c3f0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,9 +207,15 @@ fill(v, dims::Integer...) = fill!(Array{typeof(v)}(dims...), v) | |
|
||
for (fname, felt) in ((:zeros,:zero), (:ones,:one)) | ||
@eval begin | ||
($fname)(T::Type, dims...) = fill!(Array{T}(dims...), ($felt)(T)) | ||
($fname)(dims...) = fill!(Array{Float64}(dims...), ($felt)(Float64)) | ||
($fname){T}(A::AbstractArray{T}) = fill!(similar(A), ($felt)(T)) | ||
function ($fname)(a::AbstractArray, T::Type=eltype(a), dims::Tuple=size(a)) | ||
fill!(similar(a,T,dims), $felt(T)) | ||
end | ||
($fname)(T::Type, dims::Tuple) = ($fname)(Array{T}(dims...), T, dims) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't right: it allocates an I think you just want ($fname)(T::Type, dims::Tuple) = fill!(Array{T}(dims...), $felt(T)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
($fname)(dims::Tuple) = ($fname)(Float64, dims) | ||
|
||
($fname)(a::AbstractArray,T::Type,dims::DimOrInd...) = ($fname)(a,T,dims) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I stole this from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I stole this from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay... abstractarray.jl calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would be better to just define: $fname(a::AbstractArray, T::Type, dims::Tuple) = fill!(similar(a,T,dims), $felt(T))
$fname(a::AbstractArray, T::Type, dims...) = fill!(similar(a,T,dims...), $felt(T))
$fname(a::AbstractArray, T::Type=eltype(a)) = fill!(similar(a,T), $felt(T)) so that it can take any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mhh okay, I was not aware of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
($fname)(T::Type,dims::DimOrInd...) = ($fname)(T,dims) | ||
($fname)(dims::DimOrInd...) = ($fname)(dims) | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -564,9 +564,10 @@ julia> ones(Complex128, 2, 3) | |
ones(t,dims) | ||
|
||
""" | ||
ones(A) | ||
ones(A::AbstractArray, T=eltype(A)::Type, dims=size(A)::DimOrInd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this type signature isn't right for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right! |
||
|
||
Create an array of all ones with the same element type and shape as `A`. | ||
Create an array of all ones with the same layout as `A`. Element type and size | ||
can optionally be adjusted. | ||
|
||
```jldoctest | ||
julia> A = [1 2; 3 4] | ||
|
@@ -578,6 +579,17 @@ julia> ones(A) | |
2×2 Array{Int64,2}: | ||
1 1 | ||
1 1 | ||
|
||
julia> ones(A, Float64) | ||
2×2 Array{Float64,2}: | ||
1. 1. | ||
1. 1. | ||
|
||
julia> ones(A, Bool, (3,)) | ||
3-element Array{Bool,1}: | ||
true | ||
true | ||
true | ||
``` | ||
""" | ||
ones(A) | ||
|
@@ -2704,9 +2716,10 @@ julia> zeros(Int8, 2, 3) | |
zeros(t,dims) | ||
|
||
""" | ||
zeros(A) | ||
zeros(A::AbstractArray, T=eltype(A)::Type, dims=size(A)::DimOrInd) | ||
|
||
Create an array of all zeros with the same element type and shape as `A`. | ||
Create an array of all zeros with the same layout as `A`. Element type and size | ||
can optionally be adjusted. | ||
|
||
```jldoctest | ||
julia> A = [1 2; 3 4] | ||
|
@@ -2718,6 +2731,17 @@ julia> zeros(A) | |
2×2 Array{Int64,2}: | ||
0 0 | ||
0 0 | ||
|
||
julia> zeros(A, Float64) | ||
2×2 Array{Float64,2}: | ||
0.0 0.0 | ||
0.0 0.0 | ||
|
||
julia> zeros(A, Bool, (3,)) | ||
3-element Array{Bool,1}: | ||
false | ||
false | ||
false | ||
``` | ||
""" | ||
zeros(A) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.