CommonsMathWrapper { public static DoubleMatrix2D unwrap(final RealMatrix x) { Validate.notNull(x); return new DoubleMatrix2D(x.getData()); } private  CommonsMathWrapper(); static UnivariateRealFunction wrapUnivariate(final Function1D<Double, Double> f); static MultivariateRealFunction wrapMultivariate(final Function1D<DoubleMatrix1D, Double> f); static MultivariateRealFunction wrap(final FunctionND<Double, Double> f); static RealMatrix wrap(final DoubleMatrix2D x); static RealMatrix wrapAsMatrix(final DoubleMatrix1D x); static DoubleMatrix2D unwrap(final RealMatrix x); static RealVector wrap(final DoubleMatrix1D x); static DoubleMatrix1D unwrap(final RealVector x); static Complex wrap(final ComplexNumber z); static Function1D<Double, Double> unwrap(final PolynomialFunctionLagrangeForm lagrange); static double[] unwrap(final RealPointValuePair x); static DifferentiableUnivariateRealFunction wrapDifferentiable(final DoubleFunction1D f);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullVector() { CommonsMathWrapper.unwrap((RealVector) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullRealMatrix() { CommonsMathWrapper.unwrap((RealMatrix) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullLagrange() { CommonsMathWrapper.unwrap((PolynomialFunctionLagrangeForm) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullRealPointVectorPair() { CommonsMathWrapper.unwrap((RealPointValuePair) null); }
@Test public void testLagrange() { final int n = OG_POLYNOMIAL.getCoefficients().length; final double[] x = new double[n]; final double[] y = new double[n]; for (int i = 0; i < n; i++) { x[i] = i; y[i] = OG_POLYNOMIAL.evaluate(x[i]); } final Function1D<Double, Double> unwrapped = CommonsMathWrapper.unwrap(new PolynomialFunctionLagrangeForm(x, y)); for (int i = 0; i < 100; i++) { assertEquals(unwrapped.evaluate(i + 0.5), OG_POLYNOMIAL.evaluate(i + 0.5), 1e-9); } }
@Test public void testRealPointValuePair() { final double[] x = new double[] {1, 2, 3}; final double[] y = CommonsMathWrapper.unwrap(new RealPointValuePair(x, 0)); assertArrayEquals(x, y, 0); }