Internal Utilities§
Warning
This module is internal and not part of the stable public API.
Module for utilities.
Functions§
- typed_lisa_toolkit.utils.get_subset_slice(increasing_array: Array[Any, ModuleType] | ndarray[tuple[Any, ...], dtype[Any]], /, min: float, max: float)[source]§
Return the index slice for the subset [min, max] of the increasing array.
Examples
>>> get_subset_slice(0.5 * np.arange(10), 1.0, 3.0) slice(2, 7, None)
- typed_lisa_toolkit.utils.get_subset_mask(array: ArrayT, /, min: float, max: float) ArrayT[source]§
Return a boolean mask for the subset [min, max] of the array.
Examples
>>> get_subset_mask(0.5 * np.arange(10), 1.0, 3.0) array([False, False, True, True, True, True, True, False, False, False])
- typed_lisa_toolkit.utils.get_support_slice(array: Array[Any, ModuleType] | ndarray[tuple[Any, ...], dtype[Any]])[source]§
Return the index slice for the support of the array.
If the array is all zeros, the slice returned is empty.
Examples
>>> get_support_slice(np.array([0, 0, 1, 2, 0, 0])) slice(2, 4, None)
- typed_lisa_toolkit.utils.promote_slice(_slice: slice | tuple[slice, ...], /)[source]§
Promote a slice or tuple of slices to a full indexing tuple for canonical shape.
- typed_lisa_toolkit.utils.extend_to(target_grid: tuple[AT, ...] | AT, *, known_slices: tuple[slice, ...] | None = None)[source]§
Return a function that extends the entries to the target grid.
The returned function has the signature:
def get_extension(grid: tuple[AnyAxis, ...], entries: AnyArray) -> AnyArray: ...
The function extends the entries to the target grid by setting the entries outside the input grid to zero. Both the input grid and the target grid are assumed to be increasing, and the input grid is assumed to be a connected subset of the target grid. Both grids should be tuples of arrays.
The entries are assumed to have canonical shape:
(n_batches, n_channels, n_harmonics, n_features, *grid_dims)- Parameters:
target_grid (
The gridtowhich the entries should be extended. Can be a tuple) – of arrays or a single array (for 1D grid).known_slices (
Optional tupleofslices for) – the support of the input grid in the target grid. If provided, it will be used directly instead of computing the support slices from the input grid.
Examples
>>> grid = (2 + np.arange(5),) >>> entries = np.array([1, 2, 3, 4, 5]).reshape(1, 1, 1, 1, 5) >>> target_grid = (np.arange(10),) >>> result = extend_to(target_grid)(grid, entries) >>> result.shape (1, 1, 1, 1, 10)