CommonsMathWrapper { public static MultivariateRealFunction wrap(final FunctionND<Double, Double> f) { Validate.notNull(f); return new MultivariateRealFunction() { @Override public double value(final double[] point) throws FunctionEvaluationException, IllegalArgumentException { final int n = point.length; final Double[] coordinate = new Double[n]; for (int i = 0; i < n; i++) { coordinate[i] = point[i]; } return f.evaluate(coordinate); } }; } 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 testNull1DMatrix() { CommonsMathWrapper.wrap((DoubleMatrix1D) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullNDFunction() { CommonsMathWrapper.wrap((FunctionND<Double, Double>) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullMatrix() { CommonsMathWrapper.wrap((DoubleMatrix2D) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullComplexNumber() { CommonsMathWrapper.wrap((ComplexNumber) null); }
@Test public void testNDFunction() throws FunctionEvaluationException { final Double[] x1 = new Double[4]; final double[] x2 = new double[4]; final MultivariateRealFunction commons = CommonsMathWrapper.wrap(OG_FUNCTION_ND); for (int i = 0; i < 100; i++) { for (int j = 0; j < 4; j++) { x1[j] = (double) i; x2[j] = x1[j]; } assertEquals(OG_FUNCTION_ND.evaluate(x1), commons.value(x2), 1e-15); } }
@Test public void testComplexNumber() { final Complex commons = CommonsMathWrapper.wrap(OG_COMPLEX); assertEquals(commons.getReal(), OG_COMPLEX.getReal(), 0); assertEquals(commons.getImaginary(), OG_COMPLEX.getImaginary(), 0); }