interp1#
Piecewise interpolation with various methods (linear, nearest, next, previous, spline).
-
template<typename OpX, typename OpV, typename OpXQ>
auto matx::interp1(const OpX &x, const OpV &v, const OpXQ &xq, InterpMethod method = InterpMethod::LINEAR)# 1D interpolation of samples at query points.
Interpolation is performed along the last dimension. All other dimensions must be of compatible size.
- Template Parameters:
OpX – Type of sample points
OpV – Type of sample values
OpXQ – Type of query points
- Parameters:
x – Sample points. Last dimension must be sorted in ascending order.
v – Sample values. Must have compatible dimensions with x.
xq – Query points where to interpolate. All dimensions except the last must be of compatible size with x and v (e.g. x and v can be vectors, and xq can be a matrix).
method – Interpolation method (LINEAR, NEAREST, NEXT, PREV, SPLINE)
- Returns:
Operator that interpolates values at query points, with the same dimensions as xq.
-
template<typename OpX, typename OpV, typename OpXQ>
auto matx::interp1(const OpX &x, const OpV &v, const OpXQ &xq, const int (&axis)[1], InterpMethod method = InterpMethod::LINEAR)# 1D interpolation of samples at query points.
Interpolation is performed along the specified dimension. All other dimensions must be of compatible size.
- Template Parameters:
OpX – Type of sample points
OpV – Type of sample values
OpXQ – Type of query points
- Parameters:
x – Sample points. Last dimension must be sorted in ascending order.
v – Sample values. Must have compatible dimensions with x.
xq – Query points where to interpolate. All dimensions except the specified dimension must be of compatible size with x and v (e.g. x and v can be vectors, and xq can be a matrix).
axis – Dimension (of xq) along which to interpolate.
method – Interpolation method (LINEAR, NEAREST, NEXT, PREV, SPLINE)
- Returns:
Operator that interpolates values at query points, with the same dimensions as xq.
Interpolation Methods#
-
enum class matx::InterpMethod#
Interpolation method enumeration.
Specifies the algorithm to use when performing interpolation between sample points.
Values:
-
enumerator LINEAR#
Linear interpolation between adjacent points.
-
enumerator NEAREST#
Uses the value at the nearest sample point.
-
enumerator NEXT#
Uses the value at the next sample point.
-
enumerator PREV#
Uses the value at the previous sample point.
-
enumerator SPLINE#
Cubic spline interpolation, using not-a-knot boundary conditions.
-
enumerator LINEAR#
Examples#
Linear Interpolation (default):
auto x = make_tensor<TestType>({5});
x.SetVals({0.0, 1.0, 3.0, 3.5, 4.0});
auto v = make_tensor<TestType>(x.Shape());
v.SetVals({0.0, 2.0, 1.0, 3.0, 4.0});
auto xq = make_tensor<TestType>({6});
xq.SetVals({-1.0, 0.0, 0.25, 1.0, 1.5, 5.0});
auto vq_linear = make_tensor<TestType>({xq.Size(0)});
vq_linear.SetVals({0.0, 0.0, 0.5, 2.0, 1.75, 4.0});
auto vq_nearest = make_tensor<TestType>({xq.Size(0)});
vq_nearest.SetVals({0.0, 0.0, 0.0, 2.0, 2.0, 4.0});
auto vq_next = make_tensor<TestType>({xq.Size(0)});
vq_next.SetVals({0.0, 0.0, 2.0, 2.0, 1.0, 4.0});
auto vq_prev = make_tensor<TestType>({xq.Size(0)});
vq_prev.SetVals({0.0, 0.0, 0.0, 2.0, 2.0, 4.0});
auto vq_spline = make_tensor<TestType>({xq.Size(0)});
vq_spline.SetVals({-10.7391, 0.0, 1.1121, 2.0, 1.3804, -8.1739});
auto out_linear = make_tensor<TestType>({xq.Size(0)});
(out_linear = interp1(x, v, xq, InterpMethod::LINEAR)).run(exec);
Nearest Neighbor Interpolation:
auto out_nearest = make_tensor<TestType>({xq.Size(0)});
(out_nearest = interp1(x, v, xq, InterpMethod::NEAREST)).run(exec);