Interp1D¶
-
class
xitorch.interpolate.Interp1D(x: torch.Tensor, y: Optional[torch.Tensor] = None, method: Optional[Union[str, Callable]] = None, **fwd_options)[source]¶ 1D interpolation class. When initializing the class, the x must be specified and y can be specified during initialization or later.
- Parameters
x (torch.Tensor) – The position of known values in tensor with shape
(nr,)y (torch.Tensor or None) – The values at the given position with shape
(*BY, nr). IfNone, it must be supplied during__call__method (str or callable or None) – Interpolation method. If None, it will choose
"cspline".**fwd_options – Method-specific options (see method section below)
-
method="cspline" Interp1D(..., method="cspline", *, y=None, bc_type=None, extrap=None)
Perform 1D cubic spline interpolation for non-uniform
x1 2.- Keyword Arguments
bc_type (str or None) –
Boundary condition:
"not-a-knot": The first and second segments are the same polynomial"natural": 2nd grad at the boundaries are 0"clamped": 1st grad at the boundaries are 0"periodic": periodic boundary condition (new in version 0.2)
If
None, it will choose"not-a-knot"extrap (int, float, 1-element torch.Tensor, str, or None) –
Extrapolation option:
int,float, or 1-elementtorch.Tensor: it will pad the extrapolated values with the specified values"mirror": the extrapolation values are mirrored"periodic": periodic boundary condition.y[...,0] == y[...,-1]must be fulfilled for this condition."bound": fill in the extrapolated values with the left or right bound values."nan": fill the extrapolated values with nancallable: apply this extrapolation function with the extrapolated positions and use the output as the values
None: choose the extrapolation based on thebc_type. These are the pairs:"clamped":"mirror"other:
"nan"
Default:
None
References
- 1
SplineInterpolation on Wikipedia, https://en.wikipedia.org/wiki/Spline_interpolation#Algorithm_to_find_the_interpolating_cubic_spline)
- 2
Carl de Boor, “A Practical Guide to Splines”, Springer-Verlag, 1978.
-
method="linear" Interp1D(..., method="linear", *, y=None, extrap=None)
Perform 1D linear interpolation for non-uniform
x.- Keyword Arguments
extrap (int, float, 1-element torch.Tensor, str, or None) –
Extrapolation option:
int,float, or 1-elementtorch.Tensor: it will pad the extrapolated values with the specified values"mirror": the extrapolation values are mirrored"periodic": periodic boundary condition.y[...,0] == y[...,-1]must be fulfilled for this condition."bound": fill in the extrapolated values with the left or right bound values."nan": fill the extrapolated values with nancallable: apply this extrapolation function with the extrapolated positions and use the output as the values
None: choose the extrapolation based on thebc_type. These are the pairs:"clamped":"mirror"other:
"nan"
Default:
None
-
__call__(xq: torch.Tensor, y: Optional[torch.Tensor] = None) → torch.Tensor[source]¶ - Parameters
xq (torch.Tensor) – The position of query points with shape
(nrq,).y (torch.Tensor or None) – The values at the given position with shape
(*BY, nr). Ifyhas been specified during__init__and also specified here, the value ofygiven here will be ignored. If noyever specified, then it will raise an error.
- Returns
The interpolated values with shape
(*BY, nrq).- Return type
torch.Tensor