-
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
Conversation
nickrobinson251
commented
Aug 31, 2019
- attempt to address array reductions (sum, mean, etc.) and dropping dimensions JuliaLang/julia#16606
- (credit Matt Bauman and Stefan Karpinski for suggesting this approach)
This simple definition makes it easier to write reductions that drops the dimensions over which they reduce. Fixes JuliaLang#16606, addresses part of the root issue in JuliaLang#22000.
4d84d00
to
29945f3
Compare
@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 comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't think of / find a Base function that takes both dims
and another keyword. Any suggestions?
(Of course, plenty of function outside Base do, e.g. Statistics.std takes dims
and corrected
keywords)
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.
sort(A::AbstractArray; dims, alg, lt, by, rev, order) in Base.Sort at sort.jl:972
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 comment
The 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...
```jldoctest | ||
julia> a = [3.0 2.0 6.0 8.0 | ||
6.0 1.0 4.0 2.0 | ||
3.0 0.0 7.0 6.0]; |
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 not Int
s since Int
is different on 32 and 64 bit systems
thanks for review -- moved to JuliaLang#33130 |