Why was a fundamental indexing inconsistency introduced in 0.5?

256 views
Skip to first unread message

Joshua Jones

unread,
Sep 25, 2016, 6:32:28 PM9/25/16
to 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

unread,
Sep 25, 2016, 7:35:21 PM9/25/16
to 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

unread,
Sep 25, 2016, 7:36:40 PM9/25/16
to 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

unread,
Sep 26, 2016, 4:25:26 AM9/26/16
to 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

unread,
Sep 26, 2016, 4:59:11 AM9/26/16
to 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.
Reply all
Reply to author
Forward
0 new messages