@@ -375,15 +375,24 @@ def __getitem__(self, args):
375
375
if not all (len (x ) == vectorlength for x in sequenceargs .values ()):
376
376
raise TypeError ("All sequence arguments must have the same length %s" % sequenceargs )
377
377
378
- # Now generate a vector of selection lists,
378
+ # Now generate a vector of simple selection lists,
379
379
# consisting only of slices and ints
380
-
381
- argvector = []
382
- for idx in xrange (vectorlength ):
380
+ # e.g. [0:5, [1, 3]] is expanded to [[0:5, 1], [0:5, 3]]
381
+
382
+ if vectorlength > 0 :
383
+ argvector = []
384
+ for idx in xrange (vectorlength ):
385
+ entry = list (args )
386
+ for position , seq in six .iteritems (sequenceargs ):
387
+ entry [position ] = seq [idx ]
388
+ argvector .append (entry )
389
+ else :
390
+ # Empty sequence: translate to empty slice to get the correct shape
391
+ # [0:5, []] -> [0:5, 0:0]
383
392
entry = list (args )
384
- for position , seq in six . iteritems ( sequenceargs ) :
385
- entry [position ] = seq [ idx ]
386
- argvector . append ( entry )
393
+ for position in sequenceargs :
394
+ entry [position ] = slice ( 0 , 0 )
395
+ argvector = [ entry ]
387
396
388
397
# "OR" all these selection lists together to make the final selection
389
398
@@ -400,9 +409,9 @@ def __getitem__(self, args):
400
409
if idx in sequenceargs :
401
410
mshape [idx ] = len (sequenceargs [idx ])
402
411
elif scalar [idx ]:
403
- mshape [idx ] = 0
412
+ mshape [idx ] = - 1
404
413
405
- self ._mshape = tuple (x for x in mshape if x ! = 0 )
414
+ self ._mshape = tuple (x for x in mshape if x > = 0 )
406
415
407
416
def broadcast (self , target_shape ):
408
417
if not target_shape == self .mshape :
0 commit comments