MathArrays { public static void sortInPlace(double[] x, double[] ... yList) throws DimensionMismatchException, NullArgumentException { sortInPlace(x, OrderDirection.INCREASING, yList); } private  MathArrays(); static double[] scale(double val, final double[] arr); static void scaleInPlace(double val, final double[] arr); static double[] ebeAdd(double[] a, double[] b); static double[] ebeSubtract(double[] a, double[] b); static double[] ebeMultiply(double[] a, double[] b); static double[] ebeDivide(double[] a, double[] b); static double distance1(double[] p1, double[] p2); static int distance1(int[] p1, int[] p2); static double distance(double[] p1, double[] p2); static double distance(int[] p1, int[] p2); static double distanceInf(double[] p1, double[] p2); static int distanceInf(int[] p1, int[] p2); static boolean isMonotonic(T[] val,
                                      OrderDirection dir,
                                      boolean strict); static boolean isMonotonic(double[] val, OrderDirection dir, boolean strict); static boolean checkOrder(double[] val, OrderDirection dir,
                                     boolean strict, boolean abort); static void checkOrder(double[] val, OrderDirection dir,
                                  boolean strict); static void checkOrder(double[] val); static void checkRectangular(final long[][] in); static void checkPositive(final double[] in); static void checkNotNaN(final double[] in); static void checkNonNegative(final long[] in); static void checkNonNegative(final long[][] in); static double safeNorm(double[] v); static void sortInPlace(double[] x, double[] ... yList); static void sortInPlace(double[] x,
                                   final OrderDirection dir,
                                   double[] ... yList); static int[] copyOf(int[] source); static double[] copyOf(double[] source); static int[] copyOf(int[] source, int len); static double[] copyOf(double[] source, int len); static double[] copyOfRange(double[] source, int from, int to); static double linearCombination(final double[] a, final double[] b); static double linearCombination(final double a1, final double b1,
                                           final double a2, final double b2); static double linearCombination(final double a1, final double b1,
                                           final double a2, final double b2,
                                           final double a3, final double b3); static double linearCombination(final double a1, final double b1,
                                           final double a2, final double b2,
                                           final double a3, final double b3,
                                           final double a4, final double b4); static boolean equals(float[] x, float[] y); static boolean equalsIncludingNaN(float[] x, float[] y); static boolean equals(double[] x, double[] y); static boolean equalsIncludingNaN(double[] x, double[] y); static double[] normalizeArray(double[] values, double normalizedSum); static T[] buildArray(final Field<T> field, final int length); @SuppressWarnings("unchecked") static T[][] buildArray(final Field<T> field, final int rows, final int columns); static double[] convolve(double[] x, double[] h); static void shuffle(int[] list,
                               int start,
                               Position pos); static void shuffle(int[] list,
                               int start,
                               Position pos,
                               RandomGenerator rng); static void shuffle(int[] list,
                               RandomGenerator rng); static void shuffle(int[] list); static int[] natural(int n); static int[] sequence(int size,
                                 int start,
                                 int stride); static boolean verifyValues(final double[] values, final int begin, final int length); static boolean verifyValues(final double[] values, final int begin,
            final int length, final boolean allowEmpty); static boolean verifyValues(
        final double[] values,
        final double[] weights,
        final int begin,
        final int length); static boolean verifyValues(final double[] values, final double[] weights,
            final int begin, final int length, final boolean allowEmpty);  }
@Test public void testSortInPlace() { final double[] x1 = {2, 5, -3, 1, 4}; final double[] x2 = {4, 25, 9, 1, 16}; final double[] x3 = {8, 125, -27, 1, 64}; MathArrays.sortInPlace(x1, x2, x3); Assert.assertEquals(-3, x1[0], FastMath.ulp(1d)); Assert.assertEquals(9, x2[0], FastMath.ulp(1d)); Assert.assertEquals(-27, x3[0], FastMath.ulp(1d)); Assert.assertEquals(1, x1[1], FastMath.ulp(1d)); Assert.assertEquals(1, x2[1], FastMath.ulp(1d)); Assert.assertEquals(1, x3[1], FastMath.ulp(1d)); Assert.assertEquals(2, x1[2], FastMath.ulp(1d)); Assert.assertEquals(4, x2[2], FastMath.ulp(1d)); Assert.assertEquals(8, x3[2], FastMath.ulp(1d)); Assert.assertEquals(4, x1[3], FastMath.ulp(1d)); Assert.assertEquals(16, x2[3], FastMath.ulp(1d)); Assert.assertEquals(64, x3[3], FastMath.ulp(1d)); Assert.assertEquals(5, x1[4], FastMath.ulp(1d)); Assert.assertEquals(25, x2[4], FastMath.ulp(1d)); Assert.assertEquals(125, x3[4], FastMath.ulp(1d)); }
@Test public void testSortInPlaceDecresasingOrder() { final double[] x1 = {2, 5, -3, 1, 4}; final double[] x2 = {4, 25, 9, 1, 16}; final double[] x3 = {8, 125, -27, 1, 64}; MathArrays.sortInPlace(x1, MathArrays.OrderDirection.DECREASING, x2, x3); Assert.assertEquals(-3, x1[4], FastMath.ulp(1d)); Assert.assertEquals(9, x2[4], FastMath.ulp(1d)); Assert.assertEquals(-27, x3[4], FastMath.ulp(1d)); Assert.assertEquals(1, x1[3], FastMath.ulp(1d)); Assert.assertEquals(1, x2[3], FastMath.ulp(1d)); Assert.assertEquals(1, x3[3], FastMath.ulp(1d)); Assert.assertEquals(2, x1[2], FastMath.ulp(1d)); Assert.assertEquals(4, x2[2], FastMath.ulp(1d)); Assert.assertEquals(8, x3[2], FastMath.ulp(1d)); Assert.assertEquals(4, x1[1], FastMath.ulp(1d)); Assert.assertEquals(16, x2[1], FastMath.ulp(1d)); Assert.assertEquals(64, x3[1], FastMath.ulp(1d)); Assert.assertEquals(5, x1[0], FastMath.ulp(1d)); Assert.assertEquals(25, x2[0], FastMath.ulp(1d)); Assert.assertEquals(125, x3[0], FastMath.ulp(1d)); }
@Test public void testSortInPlaceFailures() { final double[] nullArray = null; final double[] one = {1}; final double[] two = {1, 2}; final double[] onep = {2}; try { MathArrays.sortInPlace(one, two); Assert.fail("Expecting DimensionMismatchException"); } catch (DimensionMismatchException ex) { } try { MathArrays.sortInPlace(one, nullArray); Assert.fail("Expecting NullArgumentException"); } catch (NullArgumentException ex) { } try { MathArrays.sortInPlace(one, onep, nullArray); Assert.fail("Expecting NullArgumentException"); } catch (NullArgumentException ex) { } }