Пример #1
0
 def descr_getitem(self, space, w_idx):
     if not (space.isinstance_w(w_idx, space.w_int) or space.isinstance_w(w_idx, space.w_slice)):
         raise oefmt(space.w_IndexError, "unsupported iterator index")
     try:
         start, stop, step, length = space.decode_index4(w_idx, self.iter.size)
         state = self.iter.goto(start)
         if length == 1:
             return self.iter.getitem(state)
         base = self.base
         res = W_NDimArray.from_shape(space, [length], base.get_dtype(), base.get_order(), w_instance=base)
         return loop.flatiter_getitem(res, self.iter, state, step)
     finally:
         self.iter.reset(self.state, mutate=True)
Пример #2
0
 def descr_getitem(self, space, w_idx):
     if not (space.isinstance_w(w_idx, space.w_int) or
             space.isinstance_w(w_idx, space.w_slice)):
         raise oefmt(space.w_IndexError, 'unsupported iterator index')
     self.reset()
     base = self.base
     start, stop, step, length = space.decode_index4(w_idx, base.get_size())
     base_iter, base_state = base.create_iter()
     base_state = base_iter.next_skip_x(base_state, start)
     if length == 1:
         return base_iter.getitem(base_state)
     res = W_NDimArray.from_shape(space, [length], base.get_dtype(),
                                  base.get_order(), w_instance=base)
     return loop.flatiter_getitem(res, base_iter, base_state, step)
Пример #3
0
 def descr_getitem(self, space, w_idx):
     if not (space.isinstance_w(w_idx, space.w_int) or
         space.isinstance_w(w_idx, space.w_slice)):
         raise OperationError(space.w_IndexError,
                              space.wrap('unsupported iterator index'))
     self.reset()
     base = self.base
     start, stop, step, length = space.decode_index4(w_idx, base.get_size())
     base_iter = base.create_iter()
     base_iter.next_skip_x(start)
     if length == 1:
         return base_iter.getitem()
     res = W_NDimArray.from_shape(space, [length], base.get_dtype(),
                                  base.get_order(), w_instance=base)
     return loop.flatiter_getitem(res, base_iter, step)
Пример #4
0
 def descr_getitem(self, space, w_idx):
     if not (space.isinstance_w(w_idx, space.w_int) or
             space.isinstance_w(w_idx, space.w_slice)):
         raise oefmt(space.w_IndexError, 'unsupported iterator index')
     try:
         start, stop, step, length = space.decode_index4(w_idx, self.iter.size)
         state = self.iter.goto(start)
         if length == 1:
             return self.iter.getitem(state)
         base = self.base
         res = W_NDimArray.from_shape(space, [length], base.get_dtype(),
                                      base.get_order(), w_instance=base)
         return loop.flatiter_getitem(res, self.iter, state, step)
     finally:
         self.iter.reset(self.state, mutate=True)