Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

nickrobinson251
Copy link

mbauman and others added 3 commits August 31, 2019 12:36
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.
@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)) ==
Copy link
Author

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)

Copy link
Member

@oxinabox oxinabox Aug 31, 2019

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

Copy link
Author

@nickrobinson251 nickrobinson251 Aug 31, 2019

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];
Copy link
Author

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 Floats not Ints since Int is different on 32 and 64 bit systems

@nickrobinson251
Copy link
Author

thanks for review -- moved to JuliaLang#33130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants