//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void twoPointsTest()
        public virtual void twoPointsTest()
        {
            double[] x = new double[] { 0.2, 0.5 };
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unused") com.opengamma.strata.collect.array.DoubleMatrix d1 = PenaltyMatrixGenerator.getDerivativeMatrix(x, 1, true);
            DoubleMatrix d1 = PenaltyMatrixGenerator.getDerivativeMatrix(x, 1, true);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "data") public void derivativeMatrix1DTest(double[] x, com.opengamma.strata.collect.array.DoubleArray y, com.opengamma.strata.collect.array.DoubleArray dydx, com.opengamma.strata.collect.array.DoubleArray d2ydx2)
        public virtual void derivativeMatrix1DTest(double[] x, DoubleArray y, DoubleArray dydx, DoubleArray d2ydx2)
        {
            int          n  = x.Length;
            DoubleMatrix d0 = PenaltyMatrixGenerator.getDerivativeMatrix(x, 0, true);

            AssertMatrix.assertEqualsMatrix(DoubleMatrix.identity(n), d0, 1e-14);

            DoubleMatrix d1  = PenaltyMatrixGenerator.getDerivativeMatrix(x, 1, true);
            DoubleMatrix d2  = PenaltyMatrixGenerator.getDerivativeMatrix(x, 2, true);
            DoubleArray  d1y = (DoubleArray)MA.multiply(d1, y);
            DoubleArray  d2y = (DoubleArray)MA.multiply(d2, y);

            AssertMatrix.assertEqualsVectors(dydx, d1y, 1e-13);
            AssertMatrix.assertEqualsVectors(d2ydx2, d2y, 1e-13);
        }
        /// <summary>
        /// create a quadratic function on a non-uniform 2D grid, then flatten this to a vector and check the first and
        /// second order differentiation matrices and penalty matrices work in both dimensions
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void penalty2DTest()
        public virtual void penalty2DTest()
        {
            double[] x  = new double[] { 0.0, 0.3, 0.7, 0.8, 1.2, 2.0 };
            double[] y  = new double[] { -20.0, -10.0, 0.0, 5.0, 15.0, 19.0, 20.0 };
            int      nx = x.Length;
            int      ny = y.Length;

            DoubleMatrix p0 = PenaltyMatrixGenerator.getPenaltyMatrix(new double[][] { x, y }, 0, 0);

            AssertMatrix.assertEqualsMatrix(DoubleMatrix.identity(nx * ny), p0, 1e-14);
            p0 = PenaltyMatrixGenerator.getPenaltyMatrix(new double[][] { x, y }, 0, 1);
            AssertMatrix.assertEqualsMatrix(DoubleMatrix.identity(nx * ny), p0, 1e-14);

            DoubleMatrix diffX1DFirstOrder = PenaltyMatrixGenerator.getDerivativeMatrix(x, 1, true);
            DoubleMatrix diffY1DFirstOrder = PenaltyMatrixGenerator.getDerivativeMatrix(y, 1, true);
            DoubleMatrix diffX1DSecOrder   = PenaltyMatrixGenerator.getDerivativeMatrix(x, 2, true);
            DoubleMatrix diffY1DSecOrder   = PenaltyMatrixGenerator.getDerivativeMatrix(y, 2, true);
            DoubleMatrix diffX2DFirstOrder = PenaltyMatrixGenerator.getMatrixForFlattened(new int[] { nx, ny }, diffX1DFirstOrder, 0);
            DoubleMatrix diffY2DFirstOrder = PenaltyMatrixGenerator.getMatrixForFlattened(new int[] { nx, ny }, diffY1DFirstOrder, 1);
            DoubleMatrix diffX2DSecOrder   = PenaltyMatrixGenerator.getMatrixForFlattened(new int[] { nx, ny }, diffX1DSecOrder, 0);
            DoubleMatrix diffY2DSecOrder   = PenaltyMatrixGenerator.getMatrixForFlattened(new int[] { nx, ny }, diffY1DSecOrder, 1);

            DoubleArray z         = DoubleArray.filled(nx * ny);
            DoubleArray dzdx      = DoubleArray.filled(nx * ny);
            DoubleArray d2zdx2    = DoubleArray.filled(nx * ny);
            DoubleArray dzdy      = DoubleArray.filled(nx * ny);
            DoubleArray d2zdy2    = DoubleArray.filled(nx * ny);
            double      dzdxSum   = 0;
            double      d2zdx2Sum = 0;
            double      dzdySum   = 0;
            double      d2zdy2Sum = 0;

            for (int i = 0; i < nx; i++)
            {
                double xi = x[i];
                for (int j = 0; j < ny; j++)
                {
                    double yj    = y[j];
                    int    index = i * ny + j;
                    z      = z.with(index, 0.3 + xi + 0.4 * xi * xi + 0.01 * yj - 1e-4 * yj * yj + 0.1 * xi * yj);
                    dzdx   = dzdx.with(index, 1.0 + 0.8 * xi + 0.1 * yj);
                    d2zdx2 = d2zdx2.with(index, 0.8);
                    dzdy   = dzdy.with(index, 0.01 - 2e-4 * yj + 0.1 * xi);
                    d2zdy2 = d2zdy2.with(index, -2e-4);

                    //The penalty matrix does not use end points, so don't include them here
                    if (i != 0 & i != (nx - 1))
                    {
                        dzdxSum   += FunctionUtils.square(dzdx.get(index));
                        d2zdx2Sum += FunctionUtils.square(d2zdx2.get(index));
                    }
                    if (j != 0 & j != (ny - 1))
                    {
                        dzdySum   += FunctionUtils.square(dzdy.get(index));
                        d2zdy2Sum += FunctionUtils.square(d2zdy2.get(index));
                    }
                }
            }

            AssertMatrix.assertEqualsVectors(dzdx, (DoubleArray)MA.multiply(diffX2DFirstOrder, z), 1e-12);
            AssertMatrix.assertEqualsVectors(dzdy, (DoubleArray)MA.multiply(diffY2DFirstOrder, z), 1e-12);
            AssertMatrix.assertEqualsVectors(d2zdx2, (DoubleArray)MA.multiply(diffX2DSecOrder, z), 1e-12);
            AssertMatrix.assertEqualsVectors(d2zdy2, (DoubleArray)MA.multiply(diffY2DSecOrder, z), 1e-12);

            DoubleMatrix p1x = PenaltyMatrixGenerator.getPenaltyMatrix(new double[][] { x, y }, 1, 0);
            DoubleMatrix p2x = PenaltyMatrixGenerator.getPenaltyMatrix(new double[][] { x, y }, 2, 0);
            DoubleMatrix p1y = PenaltyMatrixGenerator.getPenaltyMatrix(new double[][] { x, y }, 1, 1);
            DoubleMatrix p2y = PenaltyMatrixGenerator.getPenaltyMatrix(new double[][] { x, y }, 2, 1);
            double       r1x = MA.getInnerProduct(z, MA.multiply(p1x, z));
            double       r2x = MA.getInnerProduct(z, MA.multiply(p2x, z));
            double       r1y = MA.getInnerProduct(z, MA.multiply(p1y, z));
            double       r2y = MA.getInnerProduct(z, MA.multiply(p2y, z));

            double xRange = x[nx - 1] - x[0];
            double yRange = y[ny - 1] - y[0];

            assertEquals("first order x", Math.Pow(xRange, 2) * dzdxSum, r1x, 1e-10);
            assertEquals("second order x", Math.Pow(xRange, 4) * d2zdx2Sum, r2x, 1e-9);
            assertEquals("first order y", Math.Pow(yRange, 2) * dzdySum, r1y, 1e-10);
            assertEquals("second order y", Math.Pow(yRange, 4) * d2zdy2Sum, r2y, 1e-8);

            double lambdaX = 0.7;
            double lambdaY = Math.PI;
            //second order in x and first order in y
            DoubleMatrix p    = PenaltyMatrixGenerator.getPenaltyMatrix(new double[][] { x, y }, new int[] { 2, 1 }, new double[] { lambdaX, lambdaY });
            double       r    = MA.getInnerProduct(z, MA.multiply(p, z));
            double       expR = Math.Pow(xRange, 4) * d2zdx2Sum * lambdaX + Math.Pow(yRange, 2) * dzdySum * lambdaY;

            assertEquals(expR, r, 1e-9);
        }