InterpolatedCurveVectorFunction extends VectorFunction { @Override public DoubleMatrix1D evaluate(final DoubleMatrix1D x) { final Interpolator1DDataBundle db = _interpolator.getDataBundleFromSortedArrays(_knots, x.getData()); final int n = _samplePoints.length; final DoubleMatrix1D res = new DoubleMatrix1D(n); final double[] data = res.getData(); for (int i = 0; i < n; i++) { data[i] = _interpolator.interpolate(db, _samplePoints[i]); } return res; } InterpolatedCurveVectorFunction(final double[] samplePoints, final Interpolator1D interpolator, final double[] knots); @Override DoubleMatrix2D calculateJacobian(final DoubleMatrix1D x); @Override DoubleMatrix1D evaluate(final DoubleMatrix1D x); @Override int getLengthOfDomain(); @Override int getLengthOfRange();  }
@Test public void providerTest() { final double[] knots = new double[] {-1, 0, 0.5, 1.5, 3.0 }; final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.DOUBLE_QUADRATIC, Interpolator1DFactory.LINEAR_EXTRAPOLATOR); final InterpolatedVectorFunctionProvider pro = new InterpolatedVectorFunctionProvider(interpolator, knots); final double[] samplePoints = new double[] {-3, -0.5, 0.5, 1.3, 2.7 }; final VectorFunction vf1 = pro.from(samplePoints); final VectorFunction vf2 = new InterpolatedCurveVectorFunction(samplePoints, interpolator, knots); final DoubleMatrix1D knotValues = new DoubleMatrix1D(-1.0, 1.0, -1.0, 1.0, -1.0); final DoubleMatrix1D y1 = vf1.evaluate(knotValues); final DoubleMatrix1D y2 = vf2.evaluate(knotValues); AssertMatrix.assertEqualsVectors(y1, y2, 1e-13); assertEquals(interpolator, pro.getInterpolator()); final double[] knots2 = pro.getKnots(); final int n = knots.length; for (int i = 0; i < n; i++) { assertEquals(knots[i], knots2[i], 1e-14); } }