Read a `selection`. Reorder if necessary.
(
self,
selection: list[tuple[int, int, int, int, str]],
reorder: tuple[int, npt.ArrayLike] | None,
shape: tuple[int, ...],
)
| 789 | return nparr |
| 790 | |
| 791 | def _read_selection( |
| 792 | self, |
| 793 | selection: list[tuple[int, int, int, int, str]], |
| 794 | reorder: tuple[int, npt.ArrayLike] | None, |
| 795 | shape: tuple[int, ...], |
| 796 | ) -> np.ndarray: |
| 797 | """Read a `selection`. |
| 798 | |
| 799 | Reorder if necessary. |
| 800 | |
| 801 | """ |
| 802 | # Create the container for the slice |
| 803 | nparr = np.empty(dtype=self.atom.dtype, shape=shape) |
| 804 | # Arrays that have non-zero dimensionality |
| 805 | self._g_read_selection(selection, nparr) |
| 806 | # For zero-shaped arrays, return the scalar |
| 807 | if nparr.shape == (): |
| 808 | nparr = nparr[()] |
| 809 | elif reorder is not None: |
| 810 | # We need to reorder the array |
| 811 | idx, neworder = reorder |
| 812 | k = [slice(None)] * len(shape) |
| 813 | k[idx] = neworder.argsort() |
| 814 | # Apparently, a copy is not needed here, but doing it |
| 815 | # for symmetry with the `_write_selection()` method. |
| 816 | nparr = nparr[tuple(k)].copy() |
| 817 | return nparr |
| 818 | |
| 819 | def _write_slice( |
| 820 | self, |