-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Omitted and additionally indexed dimensions in getindex #5396
Comments
Both of these are completely intentional. In many cases I only wish they fell out of the implementation :) |
Yeah, please remove this. :-) It sounds way too powerful not to prove dangerous in many cases. |
The first one is the evil linear indexing, and I'd be happy to remove that. The second one is unobjectionable. |
+1 for removing linear indexing when we are ready. Or perhaps, tuck away the functionality under a more cumbersome and forbidding syntax. |
Linear indexing should be removed only when we can provide equally efficient way for the most performance-critical applications. The performance difference between |
Linear indexing with a single index sounds fine, I was referring to this feature, highlighted by @mschauer above, which doesn't make sense to me (maybe somebody can explain what's the point): A = cat(3, [1:3 11:13], [21:23 31:33])
3x2x2 Array{Int64,3}:
[:, :, 1] =
1 11
2 12
3 13
[:, :, 2] =
21 31
22 32
23 33
julia> A[1, 1]
1
julia> A[1, 2]
11
julia> A[1, 3]
21 To me, this sounds dangerous and confusing. Why not require people to use explicitly |
Not that Matlab's indexing behaviors are worth emulating for the sake of being like Matlab, but it's worth noting that this is their behavior, too. It's very obliquely documented, I think (just not very well described?). I can't imagine any use cases for this… my mind is clearly not evil enough.
|
Ah, I do know enough about matlab to see that connection. Apparently matlab has a further quirky feature, which julia has not (if I can trust octave in this regard) and which nobody is missing I guess ;-) I just leave it here for documentation purposes.
|
You can; I just verified this is true in R2013a (though I was already pretty sure of that.) Note that this is a "feature" unique to using indices on the LHS, as you observed in the test posted. |
@lindahua, in a recent test (#5393) I saw surprisingly little difference on my personal machine, but perhaps I was doing something wrong. For the reducedim code, I spent some time trying to erase the gap between your version and the original Cartesian implementation. It turns out that it was not fixed by introducing linear indexing along these lines, but it was by accumulating to a stack-allocated variable when dimension 1 was being reduced (i.e., |
Uh, note how linear indexing interacts with that "feature", maybe that is part of the design rationale
|
I happened upon this issue when searching for another. Now, I know I'm a heavy MATLAB user, to put it mildly. But I just want to add that I personally find linear indexing and the the two cited conventions to be entirely natural and convenient, and would strongly request they not be considered for removal. I actually use the first "flattening" convention with surprising frequency. |
I agree with @nalimilan above and I'm surprised that julia "auto-resizes" arrays on demand. E.G.,
While no doubt very handy and powerful, this strikes me as a bit too magical. Maybe I'm too careless but it seems to me in the majority of cases when I subscript an array by the incorrect number of indices it is done by accident and getting an error message is the fastest way to get on with my life. Thus,
should produce an error since A is 4-dimensional. However, since dimensional juggling is sometimes very handy some provisions should be added to allow it:
then
With these three the 1st case at the top of this thread becomes
or
for |
Subsumed by #14770. |
There are some aspects of
getindex
.Let
A
is an
-dimensional array, say 4-dimensional withsize(A) == (2,3,2,2)
,A[i, k]==A[i,:,:,:][k] for k in 1:12
This seems to be a consistent generalization of A[:] transforming the array to a vector.
1
,:
and equivalent1:1
(additional to then
dimensions) can be provided. For exampleA[2,3,2,2, 1, 1] ~ Int64 A[2,3,2,2, :, 1] ~ 1x1x1x1x1 Array{Int64,5}
(In both cases as usual the trailing integer-indexed dimension are removed)
Which behaviors are desired, which are artifacts from the implementation, which should be documented?
The text was updated successfully, but these errors were encountered: