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

Indexing behavior on shape mismatches #306

Closed
goretkin opened this issue Dec 13, 2011 · 2 comments
Closed

Indexing behavior on shape mismatches #306

goretkin opened this issue Dec 13, 2011 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior needs decision A decision on this change is needed

Comments

@goretkin
Copy link
Contributor

make sure to run this with more than just a single node.

assert(nprocs() > 1)
particles = dzeros(10*nprocs(),2);

println(particles[5,:])
println(particles[15,:])

#these should both work or not work.
particles[5,:]=[1,2]      #this works
particles[15,:]=[1,2]     #this doesn't work,
                            #error: in _F_: arrayref: index out of range

#these both work                                         
particles[5,:] = [1,2]' 
particles[15,:] = [1,2]'
@goretkin
Copy link
Contributor Author

In my opinion, something like particles[5,:]=[1,2] should work even though size(particles[5,:]) != size([1,2]).

Also, particles[15,:] = 2 does work (it's equivalent to size(particles[15,:]) = [2,2]' )

@JeffBezanson
Copy link
Member

There are more general issues here we haven't worked out.

How should using too few or too many indexes behave? Currently, if A is 2d, A[1,1,1] happens to work because the 3d ref method doesn't need to access size(A,3), but this is an accident. Should we pad sizes with ones, or require an exact match?

assign for Array currently accesses the right-hand-side array with linear indexing, so it is effectively doing a reshape. In fact, a vector can currently be reshaped to 2d using v[:,1:1], but you can't reshape it to 3d this way.

Generally our behavior is for the result of non-scalar ref to have rank equal to the number of indexes, but it doesn't always work. I'd propose we just allow this in full generality.

JeffBezanson added a commit that referenced this issue Feb 10, 2012
StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Oct 11, 2021
Fix miswritten "maximum" to read "median".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

2 participants