@@ -35,7 +35,7 @@ def __repr__(self):
3535 return 'RangesMatrix(' + ',' .join (map (str , self .shape )) + ')'
3636
3737 def __len__ (self ):
38- return self .shape [ 0 ]
38+ return len ( self .ranges )
3939
4040 def copy (self ):
4141 return RangesMatrix ([x .copy () for x in self .ranges ],
@@ -44,7 +44,7 @@ def copy(self):
4444 def zeros_like (self ):
4545 return RangesMatrix ([x .zeros_like () for x in self .ranges ],
4646 child_shape = self .shape [1 :])
47-
47+
4848 def ones_like (self ):
4949 return RangesMatrix ([x .ones_like () for x in self .ranges ],
5050 child_shape = self .shape [1 :])
@@ -53,7 +53,7 @@ def buffer(self, buff):
5353 [x .buffer (buff ) for x in self .ranges ]
5454 ## just to make this work like Ranges.buffer()
5555 return self
56-
56+
5757 def buffered (self , buff ):
5858 out = self .copy ()
5959 [x .buffer (buff ) for x in out .ranges ]
@@ -93,6 +93,10 @@ def __getitem__(self, index):
9393 new_rm = rm[..., :]
9494
9595 """
96+ # Short-circuit return if this is a simple integer index.
97+ if isinstance (index , (int , np .int32 , np .int64 )):
98+ return self .ranges [index ]
99+
96100 if not isinstance (index , tuple ):
97101 index = (index ,)
98102
@@ -128,7 +132,7 @@ def __add__(self, x):
128132 elif self .shape [0 ] == x .shape [0 ]:
129133 return self .__class__ ([r + d for r , d in zip (self .ranges , x )], skip_shape_check = True )
130134 return self .__class__ ([r + x for r in self .ranges ], skip_shape_check = True )
131-
135+
132136 def __mul__ (self , x ):
133137 if isinstance (x , Ranges ):
134138 return self .__class__ ([d * x for d in self .ranges ], skip_shape_check = True )
@@ -247,7 +251,7 @@ def full(shape, fill_value):
247251 return r
248252 return RangesMatrix ([RangesMatrix .full (shape [1 :], fill_value )
249253 for i in range (shape [0 ])],
250- child_shape = shape [1 :])
254+ child_shape = shape [1 :], skip_shape_check = True )
251255
252256 @classmethod
253257 def zeros (cls , shape ):
0 commit comments