MathArrays { public static int[] copyOf(int[] source) { return copyOf(source, source.length); } 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 testCopyOfInt() { final int[] source = { Integer.MIN_VALUE, -1, 0, 1, 3, 113, 4769, Integer.MAX_VALUE }; final int[] dest = MathArrays.copyOf(source); Assert.assertEquals(dest.length, source.length); for (int i = 0; i < source.length; i++) { Assert.assertEquals(source[i], dest[i]); } }
@Test public void testCopyOfInt2() { final int[] source = { Integer.MIN_VALUE, -1, 0, 1, 3, 113, 4769, Integer.MAX_VALUE }; final int offset = 3; final int[] dest = MathArrays.copyOf(source, source.length - offset); Assert.assertEquals(dest.length, source.length - offset); for (int i = 0; i < source.length - offset; i++) { Assert.assertEquals(source[i], dest[i]); } }
@Test public void testCopyOfInt3() { final int[] source = { Integer.MIN_VALUE, -1, 0, 1, 3, 113, 4769, Integer.MAX_VALUE }; final int offset = 3; final int[] dest = MathArrays.copyOf(source, source.length + offset); Assert.assertEquals(dest.length, source.length + offset); for (int i = 0; i < source.length; i++) { Assert.assertEquals(source[i], dest[i]); } for (int i = source.length; i < source.length + offset; i++) { Assert.assertEquals(0, dest[i], 0); } }
@Test public void testCopyOfDouble() { final double[] source = { Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -1, 0, Double.MIN_VALUE, FastMath.ulp(1d), 1, 3, 113, 4769, Double.MAX_VALUE, Double.POSITIVE_INFINITY }; final double[] dest = MathArrays.copyOf(source); Assert.assertEquals(dest.length, source.length); for (int i = 0; i < source.length; i++) { Assert.assertEquals(source[i], dest[i], 0); } }
@Test public void testCopyOfDouble2() { final double[] source = { Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -1, 0, Double.MIN_VALUE, FastMath.ulp(1d), 1, 3, 113, 4769, Double.MAX_VALUE, Double.POSITIVE_INFINITY }; final int offset = 3; final double[] dest = MathArrays.copyOf(source, source.length - offset); Assert.assertEquals(dest.length, source.length - offset); for (int i = 0; i < source.length - offset; i++) { Assert.assertEquals(source[i], dest[i], 0); } }
@Test public void testCopyOfDouble3() { final double[] source = { Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -1, 0, Double.MIN_VALUE, FastMath.ulp(1d), 1, 3, 113, 4769, Double.MAX_VALUE, Double.POSITIVE_INFINITY }; final int offset = 3; final double[] dest = MathArrays.copyOf(source, source.length + offset); Assert.assertEquals(dest.length, source.length + offset); for (int i = 0; i < source.length; i++) { Assert.assertEquals(source[i], dest[i], 0); } for (int i = source.length; i < source.length + offset; i++) { Assert.assertEquals(0, dest[i], 0); } }