Why was a fundamental indexing inconsistency introduced in 0.5?

256 ogledov
Preskoči na prvo neprebrano sporočilo

Joshua Jones

neprebran,
25. sep. 2016, 18:32:2825. 9. 16
do julia-users
The change to indexing within matrices in 0.5.0 is fundamentally counterintuitive. For example:

julia> frame32 = randn(16,7);

julia> size(frame32[1,:])
(7,)

julia> size(frame32[1:1,:])
(1,7)


To be quite blunt, I think this is a terrible contradiction. It completely breaks the repmat syntax that people have used in other languages for more than 20 years. To obtain what my code was doing last week, I now need to do one of:
julia> repmat(frame32[1,:]', 16, 1)
julia> repmat(frame32[1:1,:], 16, 1)


In plain English, my code needs to take the transpose of an extracted row for the result to be a row vector. Isn't this the very definition of nonreflexive syntax?

Mauro

neprebran,
25. sep. 2016, 19:35:2125. 9. 16
do julia...@googlegroups.com
This was discussed at length here:
https://github.com/JuliaLang/julia/issues/5949

And is featured in NEWS.md:
https://github.com/JuliaLang/julia/blob/master/NEWS.md#julia-v050-release-notes

Many languages do drop scalar-indexed dimensions, for instance
Python/Numpy.

On Mon, 2016-09-26 at 00:32, Joshua Jones <highly.creat...@gmail.com> wrote:
> The change to indexing within matrices in 0.5.0 is fundamentally
> counterintuitive. For example:
>
> julia> frame32 = randn(16,7);
>
> julia> size(frame32[1,:])
> (7,)
>
> julia> size(frame32[1:1,:])
> (1,7)
>
> To be quite blunt, I think this is a terrible contradiction. It completely
> breaks the repmat syntax that people have used in other languages for more
> than 20 years. To obtain what my code *was* doing last week, I now need to

Randy Zwitch

neprebran,
25. sep. 2016, 19:36:4025. 9. 16
do julia-users
As someone who has never used repmat, I can't comment on that, but the "automatic squashing" makes perfect sense to me. The first syntax simplifies the structure down to a 1-D instead of a 2-D array with only one row (repmat aside, why would I want to keep the extra dimension if it doesn't contain any information?)

Christoph Ortner

neprebran,
26. sep. 2016, 04:25:2626. 9. 16
do julia-users
I am largely a fan of Matlab-idioms, but  repmat  is an exception, it leads to code that only the person who wrote it will understand (at least for a few days after they wrote it)

Tim Holy

neprebran,
26. sep. 2016, 04:59:1126. 9. 16
do julia...@googlegroups.com
Try explaining both indexing behaviors to a newcomer and you'll see the difference.

Old behavior: `3:3` causes the dimension to be retained; `3` causes the dimension to be dropped if it's a 'trailing dimension' (all the later indices are also scalars) but retained if it's a 'leading dimension' (there's at least one vector dimension after this one).

New behavior: `3:3` causes the dimension to be retained; `3` causes the dimension to be dropped.

A lot simpler, no? If the former rule seemed better, it's surely because of habit, not because it's actually simpler.
Odgovori vsem
Odgovori avtorju
Posreduj
0 novih sporočil