def try_recompute_cache(indices, previous_cache): """Compute new axis-length cache for the masked frame based on its previous cache.""" if not isinstance(indices, slice): return len(indices) if not isinstance(previous_cache, int): return None return compute_sliced_len(indices, previous_cache)
def is_full_axis_mask(index, axis_length): """Check whether `index` mask grabs `axis_length` amount of elements.""" if isinstance(index, slice): return index == slice(None) or ( isinstance(axis_length, int) and compute_sliced_len(index, axis_length) == axis_length) return (hasattr(index, "__len__") and isinstance(axis_length, int) and len(index) == axis_length)
def compute_length(indices, length): if not isinstance(indices, slice): return len(indices) return compute_sliced_len(indices, length)