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

Have squeeze(A) remove all singleton dimensions #11838

Closed
lstagner opened this issue Jun 24, 2015 · 6 comments
Closed

Have squeeze(A) remove all singleton dimensions #11838

lstagner opened this issue Jun 24, 2015 · 6 comments

Comments

@lstagner
Copy link
Contributor

It seems like the most common use of squeeze is to remove all of the singleton dimensions. I would be nice to have squeeze called without the dims argument do this. Perhaps something like this.

function squeeze(A::AbstractArray)
    s = size(A)
    dims = tuple(find([dim == 1 for dim in s])...)
    return squeeze(A,dims)
end
@timholy timholy closed this as completed Jun 24, 2015
@StefanKarpinski
Copy link
Member

Maybe we could just have this. Using it isn't always advisable since the result type isn't predictable and your code will therefore have corner cases when dimensions are accidentally singletons, but that could just be stated in the documentation for the squeeze function.

@lstagner
Copy link
Contributor Author

I am not sure I agree with the argument against it because it would sometimes remove wanted singleton dimensions. If a user complains about a function doing the thing it was designed to do whose fault is it really? So long there is proper documentation I don't think its a problem.

But perhaps we should distinguish it from squeeze to help protect users from themselves. How about calling it collapse or more controversially calling it squeeze and renaming the current version to something else, say unsplice

@ivarne
Copy link
Member

ivarne commented Jun 25, 2015

A separate function would just make things harder to learn. It seems easier to remember a performance tip to specify squeezed dimensions, than to also have to remember to use a different function. Documentation also read better without cross references.

@tknopp
Copy link
Contributor

tknopp commented Jun 25, 2015

+1 for adding the squeeze function that removes all singleton dimensions. I use this quite often in plotting code where I do not care in which direction a 3D dataset is sliced. One should aware of the issues but for REPL usage its handy

@timholy
Copy link
Member

timholy commented Jun 25, 2015

Given that the more careful version is available, given adequate documentation of the dangers I can be persuaded.

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

No branches or pull requests

5 participants