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

Allow : in reshape #16790

Closed
cortner opened this issue Jun 6, 2016 · 12 comments
Closed

Allow : in reshape #16790

cortner opened this issue Jun 6, 2016 · 12 comments
Labels
arrays [a, r, r, a, y, s]

Comments

@cortner
Copy link

cortner commented Jun 6, 2016

I find myself writing a lot of this:

A = reshape(A, N, div(length(A), N))

Instead, I'd like to write

A = reshape(A, N, :)
@gasagna
Copy link
Contributor

gasagna commented Jun 6, 2016

IIRC, Python uses a -1 to achieve what you propose. I have to say that I never really liked it so much, and : looks way cleaner.

@cortner
Copy link
Author

cortner commented Jun 6, 2016

More generally,

B = reshape(A,  N1, N2, N3, :)

etc; (should be a fairly easy hack?)

@KristofferC
Copy link
Member

Yes I love this. Have wanted it so many times.

@andyferris
Copy link
Member

Even more generally, allow a single colon in any position:

B = reshape(A, N1, :, N3, N4)

Should still be perfectly implementable.

@malmaud
Copy link
Contributor

malmaud commented Jun 6, 2016

I remember proposing this a while ago in some issue and it wasn't generally liked.

@StefanKarpinski
Copy link
Member

I forget what the objection was before. Seems like a reasonable thing to me. It's possible that it was before : became a thing we could dispatch on.

@tkelman
Copy link
Contributor

tkelman commented Jun 7, 2016

didn't : use to have to be handled by the parser until not that long ago?

@ivarne
Copy link
Member

ivarne commented Jun 7, 2016

@malmaud I think it was #4263 (search term)

@cortner
Copy link
Author

cortner commented Jun 7, 2016

sorry I missed PR - anyhow it would be great if this feature could now be added

@malmaud
Copy link
Contributor

malmaud commented Jun 7, 2016

I can revamp that PR, but maybe one of the array experts like @mbauman or @timholy can way in on what they think of this idea.

@mbauman
Copy link
Member

mbauman commented Jun 7, 2016

+1. I think it's handy and useful. That's why I tried resurrecting your PR… but it got no traction at the time. Anyone's welcome to update either of my old commits and try it again. At a minimum the tests should be useful.

@tlnagy
Copy link
Contributor

tlnagy commented Aug 9, 2016

I feel like this is a common usage pattern and would be nice to have in Julia. MATLAB, for example, uses empty [] to tell reshape to compute the missing dimension: https://www.mathworks.com/help/matlab/ref/reshape.html#examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s]
Projects
None yet
Development

No branches or pull requests