(self, x: NdarrayOrTensor, xp: NdarrayOrTensor, fp: NdarrayOrTensor)
| 1869 | self.floating_control_points: NdarrayOrTensor |
| 1870 | |
| 1871 | def interp(self, x: NdarrayOrTensor, xp: NdarrayOrTensor, fp: NdarrayOrTensor) -> NdarrayOrTensor: |
| 1872 | ns = torch if isinstance(x, torch.Tensor) else np |
| 1873 | if isinstance(x, np.ndarray): |
| 1874 | # approx 2x faster than code below for ndarray |
| 1875 | return cast(np.ndarray, np.interp(x, xp, fp)) |
| 1876 | |
| 1877 | m = (fp[1:] - fp[:-1]) / (xp[1:] - xp[:-1]) |
| 1878 | b = fp[:-1] - (m * xp[:-1]) |
| 1879 | |
| 1880 | indices = ns.searchsorted(xp.reshape(-1), x.reshape(-1)) - 1 |
| 1881 | indices = ns.clip(indices, 0, len(m) - 1) |
| 1882 | |
| 1883 | f: NdarrayOrTensor = (m[indices] * x.reshape(-1) + b[indices]).reshape(x.shape) |
| 1884 | f[x < xp[0]] = fp[0] |
| 1885 | f[x > xp[-1]] = fp[-1] |
| 1886 | return f |
| 1887 | |
| 1888 | def randomize(self, data: Any | None = None) -> None: |
| 1889 | super().randomize(None) |
no outgoing calls