Skip to content

Commit

Permalink
ENH: add public methods Dataset.get_host_cell_index and Dataset.is_so…
Browse files Browse the repository at this point in the history
…rted
  • Loading branch information
neutrinoceros committed Sep 4, 2023
1 parent 89a0173 commit 78f3ad6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/gpgi/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,30 @@ def _setup_host_cell_index(self, verbose: bool = False) -> None:
f"Indexed {self.particles.count:.4g} particles in {(tstop-tstart)/1e9:.2f} s"
)

def get_host_cell_index(self) -> np.ndarray[Any, np.dtype("uint16")]:
r"""
Return a copy of the host cell index (HCI), representing the ndimensional index
of the host cell for each particle.
The return array has shape (particles.count, grid.ndim).
"""
self._setup_host_cell_index()
return self._hci.copy()

def is_sorted(self) -> bool:
r"""
Return True if particles memory layout matches the spatial distribution, False
otherwise.
"""
self._setup_host_cell_index()
hci = self._hci
if self.grid.ndim == 1:
ind = np.lexsort((hci[:, 0],))
elif self.grid.ndim == 2:
ind = np.lexsort((hci[:, 0], hci[:, 1]))
else:
ind = np.lexsort((hci[:, 0], hci[:, 1], hci[:, 2]))
return np.all(hci == hci[ind])

def deposit(
self,
particle_field_key: Name,
Expand Down

0 comments on commit 78f3ad6

Please sign in to comment.