Get the valid indexes of arr neighbouring virtual_indexes. Note This is a companion function to linear interpolation of Quantiles Returns ------- (previous_indexes, next_indexes): Tuple A Tuple of virtual_indexes neighbouring indexes
(arr, virtual_indexes, valid_values_count)
| 4689 | |
| 4690 | |
| 4691 | def _get_indexes(arr, virtual_indexes, valid_values_count): |
| 4692 | """ |
| 4693 | Get the valid indexes of arr neighbouring virtual_indexes. |
| 4694 | Note |
| 4695 | This is a companion function to linear interpolation of |
| 4696 | Quantiles |
| 4697 | |
| 4698 | Returns |
| 4699 | ------- |
| 4700 | (previous_indexes, next_indexes): Tuple |
| 4701 | A Tuple of virtual_indexes neighbouring indexes |
| 4702 | """ |
| 4703 | previous_indexes = floor(virtual_indexes, out=...) |
| 4704 | next_indexes = add(previous_indexes, 1, out=...) |
| 4705 | indexes_above_bounds = virtual_indexes >= valid_values_count - 1 |
| 4706 | # When indexes is above max index, take the max value of the array |
| 4707 | if indexes_above_bounds.any(): |
| 4708 | previous_indexes[indexes_above_bounds] = -1 |
| 4709 | next_indexes[indexes_above_bounds] = -1 |
| 4710 | # When indexes is below min index, take the min value of the array |
| 4711 | indexes_below_bounds = virtual_indexes < 0 |
| 4712 | if indexes_below_bounds.any(): |
| 4713 | previous_indexes[indexes_below_bounds] = 0 |
| 4714 | next_indexes[indexes_below_bounds] = 0 |
| 4715 | if np.issubdtype(arr.dtype, np.inexact): |
| 4716 | # After the sort, slices having NaNs will have for last element a NaN |
| 4717 | virtual_indexes_nans = np.isnan(virtual_indexes) |
| 4718 | if virtual_indexes_nans.any(): |
| 4719 | previous_indexes[virtual_indexes_nans] = -1 |
| 4720 | next_indexes[virtual_indexes_nans] = -1 |
| 4721 | previous_indexes = previous_indexes.astype(np.intp) |
| 4722 | next_indexes = next_indexes.astype(np.intp) |
| 4723 | return previous_indexes, next_indexes |
| 4724 | |
| 4725 | |
| 4726 | def _quantile( |