-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Merged
Merged
Zeros #19635
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
39a3bde
Add methods to zeros, ones.
jw3126 b3a93f2
news
jw3126 38d34e7
fix
jw3126 8f824a2
fix
jw3126 259668b
fix
jw3126 757e7ac
fix
jw3126 b71e9e0
fix
jw3126 e80a695
fix
jw3126 85c3f0a
fix
jw3126 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1927,6 +1927,46 @@ using TestHelpers.OAs | |
@test accumulate(op, [10 20 30], 2) == [10 op(10, 20) op(op(10, 20), 30)] == [10 40 110] | ||
end | ||
|
||
@testset "zeros and ones" begin | ||
@test ones([1,2], Float64, (2,3)) == ones(2,3) | ||
@test ones(2) == ones(Int, 2) == ones([2,3], Float32, 2) == [1,1] | ||
@test isa(ones(2), Vector{Float64}) | ||
@test isa(ones(Int, 2), Vector{Int}) | ||
@test isa(ones([2,3], Float32, 2), Vector{Float32}) | ||
|
||
function test_zeros(arr, T, s) | ||
@test all(arr .== 0) | ||
@test isa(arr, T) | ||
@test size(arr) == s | ||
end | ||
test_zeros(zeros(), Array{Float64, 0}, ()) | ||
test_zeros(zeros(2), Vector{Float64}, (2,)) | ||
test_zeros(zeros(2,3), Matrix{Float64}, (2,3)) | ||
test_zeros(zeros((2,3)), Matrix{Float64}, (2,3)) | ||
|
||
test_zeros(zeros(Int, 6), Vector{Int}, (6,)) | ||
test_zeros(zeros(Int, 2, 3), Matrix{Int}, (2,3)) | ||
test_zeros(zeros(Int, (2, 3)), Matrix{Int}, (2,3)) | ||
|
||
test_zeros(zeros([1 2; 3 4]), Matrix{Int}, (2, 2)) | ||
test_zeros(zeros([1 2; 3 4], Float64), Matrix{Float64}, (2, 2)) | ||
|
||
zs = zeros(SparseMatrixCSC([1 2; 3 4]), Complex{Float64}, (2,3)) | ||
test_zeros(zs, SparseMatrixCSC{Complex{Float64}}, (2, 3)) | ||
|
||
@testset "#19265" begin | ||
@test_throws MethodError zeros(Float64, [1.]) | ||
x = [1.] | ||
test_zeros(zeros(x, Float64), Vector{Float64}, (1,)) | ||
@test x == [1.] | ||
end | ||
|
||
# exotic indexing | ||
oarr = zeros(randn(3), UInt16, 1:3, -1:0) | ||
@test indices(oarr) == (1:3, -1:0) | ||
test_zeros(oarr.parent, Matrix{UInt16}, (3, 2)) | ||
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. @stevengj Here is a test that shows why |
||
end | ||
|
||
# issue #11053 | ||
type T11053 | ||
a::Float64 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"variadic form" is not very clear, we don't use that terminology anywhere else
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.
How would you call it instead?
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.
I'd spell out an example
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.
Maybe:
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.
There are examples where
dims...
is used already e.g.zeros(Int8, 2, 3)
. But I can open a new PR with stevengj's suggestion if you like.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.
Also I think if we don't have a terminology for
dims...
, we should introduce one. It occurs quite frequently and feels cumbersome not having a word for it.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.
I think "variadic form" is fine, but it should be spelled out with an example as well.
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.
without any explanation that's terribly jargony and not very clear
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.
Then please make a PR that improves it.