-
Notifications
You must be signed in to change notification settings - Fork 0
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
WIP: Add dropdims(f, args..; dims, kwargs..)
for reductions to drop dims
#4
Changes from all commits
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 |
---|---|---|
|
@@ -303,6 +303,37 @@ end | |
@test_throws ArgumentError dropdims(a, dims=4) | ||
@test_throws ArgumentError dropdims(a, dims=6) | ||
|
||
# dropdims with reductions. issue #16606 | ||
@test (@inferred(dropdims(sum, a, dims=1)) == | ||
@inferred(dropdims(sum, a, dims=(1,))) == | ||
reshape(sum(a, dims=1), (1, 8, 8, 1))) | ||
@test (@inferred(dropdims(sum, a, dims=3)) == | ||
@inferred(dropdims(sum, a, dims=(3,))) == | ||
reshape(sum(a, dims=3), (1, 1, 8, 1))) | ||
@test (@inferred(dropdims(sum, a, dims=4)) == | ||
@inferred(dropdims(sum, a, dims=(4,))) == | ||
reshape(sum(a, dims=4), (1, 1, 8, 1))) | ||
@test (@inferred(dropdims(sum, a, dims=(1, 5))) == | ||
dropdims(sum, a, dims=(5, 1)) == | ||
reshape(sum(a, (5, 1)), (1, 8, 8))) | ||
@test (@inferred(dropdims(sum, a, dims=(1, 2, 5))) == | ||
dropdims(sum, a, dims=(5, 2, 1)) == | ||
reshape(sum(a, dims=(5, 2, 1)), (8, 8))) | ||
@test (@inferred(dropdims(sum, abs2, a, dims=1)) == | ||
@inferred(dropdims(sum, abs2, a, dims=(1,))) == | ||
reshape(sum(a, dims=1), (1, 8, 8, 1))) | ||
_sumplus(x; dims, plus) = sum(x; dims=dims) .+ plus # reduction with keywords | ||
@test (@inferred(dropdims(_sumplus, a, dims=4, plus=1)) == | ||
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. Couldn't think of / find a Base function that takes both (Of course, plenty of function outside Base do, e.g. Statistics.std takes 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.
But idk that it is one that you would use dropdims with 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,! good find ... but yeah, agree - not sure that one will make the tests here nicer... |
||
@inferred(dropdims(_sumplus, a, dims=(4,), plus=1)) == | ||
reshape(sum(a, dims=4) .+ 1, (1, 1, 8, 1))) | ||
@test_throws UndefKeywordError dropdims(sum, a) | ||
@test_throws UndefKeywordError dropdims(sum, a, 1) | ||
@test_throws ArgumentError dropdims(sum, a, dims=0) | ||
@test_throws ArgumentError dropdims(sum, a, dims=(1, 1)) | ||
@test_throws ArgumentError dropdims(sum, a, dims=(1, 2, 1)) | ||
@test_throws ArgumentError dropdims(sum, a, dims=(1, 1, 2)) | ||
@test_throws ArgumentError dropdims(sum, a, dims=6) | ||
|
||
sz = (5,8,7) | ||
A = reshape(1:prod(sz),sz...) | ||
@test A[2:6] == [2:6;] | ||
|
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.
Not sure on expected style here... just wanted something short and clear
Also, using
Float
s notInt
s sinceInt
is different on 32 and 64 bit systems