`np.searchsorted` with equivalent implementation for torch. Args: a: numpy array or tensor, containing monotonically increasing sequence on the innermost dimension. v: containing the search values. right: if False, return the first suitable location that is found, i
(a: NdarrayTensor, v: NdarrayOrTensor, right=False, sorter=None, **kwargs)
| 343 | |
| 344 | |
| 345 | def searchsorted(a: NdarrayTensor, v: NdarrayOrTensor, right=False, sorter=None, **kwargs) -> NdarrayTensor: |
| 346 | """ |
| 347 | `np.searchsorted` with equivalent implementation for torch. |
| 348 | |
| 349 | Args: |
| 350 | a: numpy array or tensor, containing monotonically increasing sequence on the innermost dimension. |
| 351 | v: containing the search values. |
| 352 | right: if False, return the first suitable location that is found, if True, return the last such index. |
| 353 | sorter: if `a` is numpy array, optional array of integer indices that sort array `a` into ascending order. |
| 354 | kwargs: if `a` is PyTorch Tensor, additional args for `torch.searchsorted`, more details: |
| 355 | https://pytorch.org/docs/stable/generated/torch.searchsorted.html. |
| 356 | |
| 357 | """ |
| 358 | side = "right" if right else "left" |
| 359 | if isinstance(a, np.ndarray): |
| 360 | return np.searchsorted(a, v, side, sorter) # type: ignore |
| 361 | return torch.searchsorted(a, v, right=right, **kwargs) # type: ignore |
| 362 | |
| 363 | |
| 364 | def repeat(a: NdarrayOrTensor, repeats: int, axis: int | None = None, **kwargs) -> NdarrayOrTensor: |
no outgoing calls
no test coverage detected
searching dependent graphs…