(self, index)
| 420 | return self.__getitem__(args) |
| 421 | |
| 422 | def __getitem__(self, index): |
| 423 | tensor = self.tensor |
| 424 | |
| 425 | def neg_step(i, s): |
| 426 | if not (isinstance(s, slice) and s.step is not None and s.step < 0): |
| 427 | return s |
| 428 | |
| 429 | nonlocal tensor |
| 430 | tensor = torch.flip(tensor, (i,)) |
| 431 | |
| 432 | # Account for the fact that a slice includes the start but not the end |
| 433 | assert isinstance(s.start, int) or s.start is None |
| 434 | assert isinstance(s.stop, int) or s.stop is None |
| 435 | start = s.stop + 1 if s.stop else None |
| 436 | stop = s.start + 1 if s.start else None |
| 437 | |
| 438 | return slice(start, stop, -s.step) |
| 439 | |
| 440 | if isinstance(index, Sequence): |
| 441 | index = type(index)(neg_step(i, s) for i, s in enumerate(index)) |
| 442 | else: |
| 443 | index = neg_step(0, index) |
| 444 | index = _util.ndarrays_to_tensors(index) |
| 445 | index = _upcast_int_indices(index) |
| 446 | return ndarray(tensor.__getitem__(index)) |
| 447 | |
| 448 | def __setitem__(self, index, value): |
| 449 | index = _util.ndarrays_to_tensors(index) |
no test coverage detected