Class ArrayMath

Object
ArrayMath

public class ArrayMath extends Object
Collection of convenience methods for mathematical operations, including array manipulations and statistics.
Author:
Christoph Hauert
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Ensure non-instantiability with private default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    abs(double[] a)
    Element-wise absolute value of double array a.
    static float[]
    abs(float[] a)
    Element-wise absolute value of float array a.
    static int[]
    abs(int[] a)
    Element-wise absolute value of int array a.
    static double[]
    add(double[] dst, double scalar)
    Add scalar value to each element of double array/vector dst.
    static double[]
    add(double[] dst, double[] add)
    Add double arrays dst and add.
    static double[]
    add(double[] a, double[] b, double[] dst)
    Non-destructive array addition.
    static float[]
    add(float[] dst, float scalar)
    Add scalar value to each element of float array/vector dst.
    static float[]
    add(float[] dst, float[] add)
    Add float arrays dst and add.
    static float[]
    add(float[] a, float[] b, float[] dst)
    Non-destructive array addition.
    static int[]
    add(int[] dst, int scalar)
    Add scalar value to each element of integer array/vector dst.
    static int[]
    add(int[] dst, int[] add)
    Add integer arrays dst and add.
    static int[]
    add(int[] a, int[] b, int[] dst)
    Non-destructive array addition.
    static long[]
    add(long[] dst, long scalar)
    Add scalar value to each element of long array/vector dst.
    static long[]
    add(long[] dst, long[] add)
    Add long arrays dst and add.
    static long[]
    add(long[] a, long[] b, long[] dst)
    Non-destructive array addition.
    static double[]
    addscale(double[] a, double[] b, double s, double[] dst)
    Non-destructive scalar multiplication and array addition.
    static boolean[]
    append(boolean[] array, boolean element)
    Append element to boolean array array.
    static double[]
    append(double[] array, double element)
    Append element to double array array.
    static int[]
    append(int[] array, int element)
    Append element to int array array.
    static <T> T[]
    append(T[] array, T element)
    Append element of type T to array array of the same type.
    static boolean[]
    clone(boolean[] orig)
    GWT has an aversion to clone()ing - provide alternatives.
    static double[]
    clone(double[] orig)
    GWT has an aversion to clone()ing - provide alternatives.
    static double[][]
    clone(double[][] orig)
    GWT has an aversion to clone()ing - provide alternatives.
    static int[]
    clone(int[] orig)
    GWT has an aversion to clone()ing - provide alternatives.
    static int
    compare(double[][] a1, double[][] a2)
    Compares the two specified double[][] arrays.
    static int
    compare(double[] a1, double[] a2)
    Compares the two specified double[] arrays.
    static int
    compare(int[][] a1, int[][] a2)
    Compares the two specified int[][] arrays.
    static int
    compare(int[] a1, int[] a2)
    Compares the two specified int[] arrays.
    static double[][]
    copy(double[][] src, double[][] dst)
    Copy the double 2D array/matrix src to dst.
    static double[]
    copy(double[] src, double[] dst)
    Copy the double 2D array/matrix src to dst.
    static int[][]
    copy(int[][] src, int[][] dst)
    Copy the integer 2D array/matrix src to dst.
    static double[]
    copy(int[] src, double[] dst)
    Element-wise copy of integer array/vector src to double array/vector dst.
    static int[]
    copy(int[] src, int[] dst)
    Copy the integer array/vector src to dst.
    static double
    dist(double[] a, double[] b)
    Distance of two double arrays a and b given by the square root of the sum over (a[i]-b[i])^2.
    static double
    dist(int[] a, int[] b)
    Distance of two integer arrays a and b given by the square root of the sum over (a[i]-b[i])^2.
    static double
    distSq(double[] a, double[] b)
    Squared distance of two double arrays a and b given by the sum over (a[i]-b[i])^2.
    static int
    distSq(int[] a, int[] b)
    Squared distance of two integer arrays a and b given by the sum over (a[i]-b[i])^2.
    static double
    dot(double[] a, double[] b)
    Dot product of two double arrays a and b given by the sum over a[i]*b[i].
    static float
    dot(float[] a, float[] b)
    Dot product of two float arrays a and b given by the sum over a[i]*b[i].
    static int
    dot(int[] a, int[] b)
    Dot product of two integer arrays a and b given by the sum over a[i]*b[i].
    static long
    dot(long[] a, long[] b)
    Dot product of two long arrays a and b given by the sum over a[i]*b[i].
    static boolean[]
    drop(boolean[] array, int index)
    Drop the element at index from the array array of type boolean[].
    static boolean[]
    drop(boolean[] array, int from, int to)
    Drop a range of elements starting with index from to index to from the boolean[] array array.
    static double[]
    drop(double[] array, int index)
    Drop the element at index from the array array of type double[].
    static double[]
    drop(double[] array, int from, int to)
    Drop a range of elements starting with index from to index to from the double[] array array.
    static int[]
    drop(int[] array, int index)
    Drop the element at index from the array array of type int[].
    static int[]
    drop(int[] array, int from, int to)
    Drop a range of elements starting with index from to index to from the int[] array array.
    static <T> T[]
    drop(T[] array, int index)
    Drop the element at index from the array array of type T.
    static <T> T[]
    drop(T[] array, int from, int to)
    Drop a range of elements starting with index from to index to from the array array of type T.
    static int
    first(double[] a, double b)
    Find the first occurence of the element b in the array double[] a.
    static int
    first(int[] a, int b)
    Find the first occurence of the element b in the array int[] a.
    static boolean[]
    insert(boolean[] array, boolean element, int index)
    Insert element element of type boolean into array array of the same type at index.
    static double[]
    insert(double[] array, double element, int index)
    Insert element element of type double into array array of the same type at index.
    static int[]
    insert(int[] array, int element, int index)
    Insert element element of type int into array array of the same type at index.
    static <T> T[]
    insert(T[] array, T element, int index)
    Insert element element of type T into array array of the same type at index.
    static int
    last(double[] a, int b)
    Find the last occurence of the element b in the array double[] a.
    static int
    last(int[] a, int b)
    Find the last occurence of the element b in the array int[] a.
    static double[]
    log10(double[] a)
    Element-wise logarithm of double array a (base 10).
    static float[]
    log10(float[] a)
    Element-wise logarithm of float array a (base 10).
    static boolean
    max(boolean[] a)
    Find maximum element in boolean array/vector a.
    static double
    max(double[] a)
    Find maximum element in double array/vector a.
    static double
    max(double[][] a)
    Find maximum element in double array/matrix a.
    static double
    max(double[] a, boolean[] active)
    Find maximum element in double array a among active elements.
    static double[]
    max(double[] a, double[] b)
    Find maximum element in two double arrays a and b.
    static float
    max(float[] a)
    Find maximum element in float array/vector a.
    static float
    max(float[][] a)
    Find maximum element in float array/matrix a.
    static float[]
    max(float[] a, float[] b)
    Find maximum element in two float arrays a and b.
    static int
    max(int[] a)
    Find maximum element in int array/vector a.
    static int
    max(int[][] a)
    Find maximum element in int array/matrix a.
    static long
    max(long[] a)
    Find maximum element in long array/vector a.
    static long
    max(long[][] a)
    Find maximum element in long array/matrix a.
    static int
    maxIndex(double[] a)
    Find index of maximum element in double array.
    static int
    maxIndex(float[] a)
    Find index of maximum element in float array.
    static int
    maxIndex(int[] a)
    Find index of maximum element in integer array.
    static int
    maxIndex(long[] a)
    Find index of maximum element in long array.
    static double[]
    merge(double[] head, double[] tail)
    Append double array tail to double array head.
    static <T> T[]
    merge(T[] head, T[] tail)
    Append array tail of type T[] to array head.
    static boolean
    min(boolean[] a)
    Find minimum element in boolean array/vector a.
    static double
    min(double[] a)
    Find minimum element in double array/vector a.
    static double
    min(double[][] a)
    Find minimum element in double array/matrix a.
    static double
    min(double[] a, boolean[] active)
    Find minimum element in double array a among active elements.
    static double[]
    min(double[] a, double[] b)
    Find minimum element in two double arrays a and b.
    static float
    min(float[] a)
    Find minimum element in float array/vector a.
    static float
    min(float[][] a)
    Find minimum element in float array/matrix a.
    static float[]
    min(float[] a, float[] b)
    Find minimum element in two float arrays a and b.
    static int
    min(int[] a)
    Find minimum element in integer array/vector a.
    static int
    min(int[][] a)
    Find minimum element in integer array/matrix a.
    static long
    min(long[] a)
    Find minimum element in long array/vector a.
    static long
    min(long[][] a)
    Find minimum element in long array/matrix a.
    static int
    minIndex(double[] a)
    Find index of minimum element in double array.
    static int
    minIndex(float[] a)
    Find index of minimum element in float array.
    static int
    minIndex(int[] a)
    Find index of minimum element in integer array.
    static int
    minIndex(long[] a)
    Find index of minimum element in long array.
    static double[]
    multiply(double[][] mat, double[] vec, double[] dst)
    Non-destructive double matrix multiplication.
    static double[]
    multiply(double[] dst, double scalar)
    Scalar multiplication of double array dst by scalar.
    static double[]
    multiply(double[] dst, double[] a)
    Element-wise multiplication of double array a and dst.
    static double[]
    multiply(double[] a, double[] b, double[] dst)
    Non-destructive, element-wise multiplication of double arrays a and b.
    static double[]
    multiply(double[] a, double scalar, double[] dst)
    Scalar multiplication of double array a by scalar with result in dst.
    static float[]
    multiply(float[][] mat, float[] vec, float[] dst)
    Non-destructive float matrix multiplication.
    static float[]
    multiply(float[] dst, float scalar)
    Scalar multiplication of float array dst by scalar.
    static float[]
    multiply(float[] dst, float[] a)
    Element-wise multiplication of float arrays a and dst.
    static float[]
    multiply(float[] a, float[] b, float[] dst)
    Non-destructive, element-wise multiplication of float arrays a and b.
    static float[]
    multiply(float[] a, float scalar, float[] dst)
    Scalar multiplication of float array a by scalar with result in dst.
    static int[]
    multiply(int[][] mat, int[] vec, int[] dst)
    Non-destructive integer matrix multiplication.
    static int[]
    multiply(int[] dst, int scalar)
    Scalar multiplication of integer array dst by scalar.
    static int[]
    multiply(int[] dst, int[] a)
    Element-wise multiplication of integer arrays a and dst.
    static int[]
    multiply(int[] a, int[] b, int[] dst)
    Non-destructive, element-wise multiplication of integer array a and b.
    static int[]
    multiply(int[] a, int scalar, int[] dst)
    Scalar multiplication of integer array a by scalar with result in dst.
    static long[]
    multiply(long[][] mat, long[] vec, long[] dst)
    Non-destructive long matrix multiplication.
    static long[]
    multiply(long[] dst, long scalar)
    Scalar multiplication of long array dst by scalar.
    static long[]
    multiply(long[] dst, long[] a)
    Element-wise multiplication of long arrays a and dst.
    static long[]
    multiply(long[] a, long[] b, long[] dst)
    Non-destructive, element-wise multiplication of long arrays a and b.
    static long[]
    multiply(long[] a, long scalar, long[] dst)
    Scalar multiplication of long array a by scalar with result in dst.
    static double
    norm(double[] a)
    Norm of double array a.
    static float
    norm(float[] a)
    Norm of float array a.
    static int
    norm(int[] a)
    Norm of integer array a.
    static long
    norm(long[] a)
    Norm of long array a.
    static double[]
    normalize(double[] a)
    Normalize double array a.
    static double[]
    normalize(double[] a, int from, int to)
    Normalize elements ranging from index from to index to in double array a.
    static float[]
    normalize(float[] a)
    Normalize float array a.
    static float[]
    normalize(float[] a, int from, int to)
    Normalize elements ranging from index from to index to in float array a.
    static double[]
    sqrt(double[] a)
    Element-wise square-root of double array a.
    static float[]
    sqrt(float[] a)
    Element-wise square-root of float array a.
    static double[]
    sub(double[] dst, double[] sub)
    Subtract double array sub from array dst.
    static double[]
    sub(double[] orig, double[] sub, double[] dst)
    Non-destructive array subtraction.
    static float[]
    sub(float[] dst, float[] sub)
    Subtract float array sub from array dst.
    static float[]
    sub(float[] orig, float[] sub, float[] dst)
    Non-destructive array subtraction.
    static int[]
    sub(int[] dst, int[] sub)
    Subtract integer array sub from array dst.
    static int[]
    sub(int[] orig, int[] sub, int[] dst)
    Non-destructive array subtraction.
    static long[]
    sub(long[] dst, long[] sub)
    Subtract long array sub from array dst.
    static long[]
    sub(long[] orig, long[] sub, long[] dst)
    Non-destructive array subtraction.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArrayMath

      private ArrayMath()
      Ensure non-instantiability with private default constructor
  • Method Details

    • append

      public static boolean[] append(boolean[] array, boolean element)
      Append element to boolean array array. The length of the returned array is array.length + 1. The array array remains unchanged.
      Parameters:
      array - the array
      element - the element to append
      Returns:
      the new (longer) array
    • append

      public static int[] append(int[] array, int element)
      Append element to int array array. The length of the returned array is array.length + 1. The array array remains unchanged.
      Parameters:
      array - the array
      element - the element to append
      Returns:
      the new (longer) array
    • append

      public static double[] append(double[] array, double element)
      Append element to double array array. The length of the returned array is array.length + 1. The array array remains unchanged.
      Parameters:
      array - the array
      element - the element to append
      Returns:
      the new (longer) array
    • append

      public static <T> T[] append(T[] array, T element)
      Append element of type T to array array of the same type. The length of the returned array is array.length + 1. The array array remains unchanged.
      Type Parameters:
      T - the type of the array
      Parameters:
      array - the array
      element - the element to append
      Returns:
      the new (longer) array
    • merge

      public static double[] merge(double[] head, double[] tail)
      Append double array tail to double array head. The length of the returned array is head.length + tail.length. The arrays head and tail remain unchanged.
      Parameters:
      head - the base array
      tail - the array to append
      Returns:
      the new (longer) array
    • merge

      public static <T> T[] merge(T[] head, T[] tail)
      Append array tail of type T[] to array head. The length of the returned array is head.length + tail.length. The arrays head and tail remain unchanged.
      Type Parameters:
      T - the type of the array
      Parameters:
      head - the base array
      tail - the array to append
      Returns:
      the new (longer) array
    • drop

      public static boolean[] drop(boolean[] array, int index)
      Drop the element at index from the array array of type boolean[]. The length of the returned array is array.length - 1.
      Parameters:
      array - the array
      index - the index of the element to remove
      Returns:
      the new (shorter) array
    • drop

      public static boolean[] drop(boolean[] array, int from, int to)
      Drop a range of elements starting with index from to index to from the boolean[] array array. The length of the returned array is array.length - (to - from).
      Parameters:
      array - the array
      from - the first index to drop
      to - the last index to drop
      Returns:
      the new (shorter) array
    • drop

      public static int[] drop(int[] array, int index)
      Drop the element at index from the array array of type int[]. The length of the returned array is array.length - 1.
      Parameters:
      array - the array
      index - the index of the element to remove
      Returns:
      the new (shorter) array
    • drop

      public static int[] drop(int[] array, int from, int to)
      Drop a range of elements starting with index from to index to from the int[] array array. The length of the returned array is array.length - (to - from).
      Parameters:
      array - the array
      from - the first index to drop
      to - the last index to drop
      Returns:
      the new (shorter) array
    • drop

      public static double[] drop(double[] array, int index)
      Drop the element at index from the array array of type double[]. The length of the returned array is array.length - 1.
      Parameters:
      array - the array
      index - the index of the element to remove
      Returns:
      the new (shorter) array
    • drop

      public static double[] drop(double[] array, int from, int to)
      Drop a range of elements starting with index from to index to from the double[] array array. The length of the returned array is array.length - (to - from).
      Parameters:
      array - the array
      from - the first index to drop
      to - the last index to drop
      Returns:
      the new (shorter) array
    • drop

      public static <T> T[] drop(T[] array, int index)
      Drop the element at index from the array array of type T. The length of the returned array is array.length - 1.
      Type Parameters:
      T - the type of the array
      Parameters:
      array - the array
      index - the index of the element to remove
      Returns:
      the new (shorter) array
    • drop

      public static <T> T[] drop(T[] array, int from, int to)
      Drop a range of elements starting with index from to index to from the array array of type T. The length of the returned array is array.length - (to - from).
      Type Parameters:
      T - the type of the array
      Parameters:
      array - the array
      from - the first index to drop
      to - the last index to drop
      Returns:
      the new (shorter) array
    • insert

      public static boolean[] insert(boolean[] array, boolean element, int index)
      Insert element element of type boolean into array array of the same type at index. The length of the returned array is array.length + 1.
      Parameters:
      array - the array
      element - the element to insert
      index - the insertion point
      Returns:
      the new (longer) array
    • insert

      public static int[] insert(int[] array, int element, int index)
      Insert element element of type int into array array of the same type at index. The length of the returned array is array.length + 1.
      Parameters:
      array - the array
      element - the element to insert
      index - the insertion point
      Returns:
      the new (longer) array
    • insert

      public static double[] insert(double[] array, double element, int index)
      Insert element element of type double into array array of the same type at index. The length of the returned array is array.length + 1.
      Parameters:
      array - the array
      element - the element to insert
      index - the insertion point
      Returns:
      the new (longer) array
    • insert

      public static <T> T[] insert(T[] array, T element, int index)
      Insert element element of type T into array array of the same type at index. The length of the returned array is array.length + 1.
      Type Parameters:
      T - the type of the element and the array
      Parameters:
      array - the array
      element - the element to insert
      index - the insertion point
      Returns:
      the new (longer) array
    • compare

      public static int compare(int[] a1, int[] a2)
      Compares the two specified int[] arrays. Returns zero if the arrays are identical and 1 otherwise. In contrast to Integer.compare(int, int) there is no obvious ranking of the two arrays.
      Parameters:
      a1 - the first int[] array to compare
      a2 - the second int[] array to compare
      Returns:
      the value 0 if a1 is numerically equal to a2 and 1 otherwise
      See Also:
    • compare

      public static int compare(int[][] a1, int[][] a2)
      Compares the two specified int[][] arrays. Returns zero if the arrays are identical and 1 otherwise. In contrast to Integer.compare(int, int) there is no obvious ranking of the two arrays.
      Parameters:
      a1 - the first int[][] array to compare
      a2 - the second int[][] array to compare
      Returns:
      the value 0 if a1 is numerically equal to a2 and 1 otherwise
      See Also:
    • compare

      public static int compare(double[] a1, double[] a2)
      Compares the two specified double[] arrays. Returns zero if the arrays are identical and 1 otherwise. In contrast to Double.compare(double, double) there is no obvious ranking of the two arrays.
      Parameters:
      a1 - the first double[] array to compare
      a2 - the second double[] array to compare
      Returns:
      the value 0 if d1 is numerically equal to d2 and 1 otherwise
      See Also:
    • compare

      public static int compare(double[][] a1, double[][] a2)
      Compares the two specified double[][] arrays. Returns zero if the arrays are identical and 1 otherwise. In contrast to Double.compare(double, double) there is no obvious ranking of the two arrays.
      Parameters:
      a1 - the first double[][] array to compare
      a2 - the second double[][] array to compare
      Returns:
      the value 0 if d1 is numerically equal to d2 and 1 otherwise
      See Also:
    • first

      public static int first(int[] a, int b)
      Find the first occurence of the element b in the array int[] a.
      Parameters:
      a - the array
      b - the element to look for
      Returns:
      the index of the first occurrence of b or -1 if a does not contain any element b
    • first

      public static int first(double[] a, double b)
      Find the first occurence of the element b in the array double[] a.
      Parameters:
      a - the array
      b - the element to look for
      Returns:
      the index of the first occurrence of b or -1 if a does not contain any element b
    • last

      public static int last(int[] a, int b)
      Find the last occurence of the element b in the array int[] a.
      Parameters:
      a - the array
      b - the element to look for
      Returns:
      the index of the first occurrence of b or -1 if a does not contain any element b
    • last

      public static int last(double[] a, int b)
      Find the last occurence of the element b in the array double[] a.
      Parameters:
      a - the array
      b - the element to look for
      Returns:
      the index of the first occurrence of b or -1 if a does not contain any element b
    • min

      public static boolean min(boolean[] a)
      Find minimum element in boolean array/vector a.
      Parameters:
      a - the boolean[] array
      Returns:
      true if all elements are true and false if at least one element is false
    • min

      public static int min(int[] a)
      Find minimum element in integer array/vector a.
      Parameters:
      a - the array int[]
      Returns:
      the minimum element
    • min

      public static long min(long[] a)
      Find minimum element in long array/vector a.
      Parameters:
      a - the array long[]
      Returns:
      the minimum element
    • min

      public static float min(float[] a)
      Find minimum element in float array/vector a.
      Parameters:
      a - the array float[]
      Returns:
      the minimum element
    • min

      public static double min(double[] a)
      Find minimum element in double array/vector a.
      Parameters:
      a - the array double[]
      Returns:
      the minimum element
    • min

      public static int min(int[][] a)
      Find minimum element in integer array/matrix a.
      Parameters:
      a - the array int[][]
      Returns:
      the minimum element
    • min

      public static long min(long[][] a)
      Find minimum element in long array/matrix a.
      Parameters:
      a - the array long[][]
      Returns:
      the minimum element
    • min

      public static float min(float[][] a)
      Find minimum element in float array/matrix a.
      Parameters:
      a - the array float[][]
      Returns:
      the minimum element
    • min

      public static double min(double[][] a)
      Find minimum element in double array/matrix a.
      Parameters:
      a - the array double[][]
      Returns:
      the minimum element
    • minIndex

      public static int minIndex(int[] a)
      Find index of minimum element in integer array.
      Parameters:
      a - the array int[]
      Returns:
      the index of the minimum element
    • minIndex

      public static int minIndex(long[] a)
      Find index of minimum element in long array.
      Parameters:
      a - the array long[]
      Returns:
      the index of the minimum element
    • minIndex

      public static int minIndex(float[] a)
      Find index of minimum element in float array.
      Parameters:
      a - the array float[]
      Returns:
      the index of the minimum element
    • minIndex

      public static int minIndex(double[] a)
      Find index of minimum element in double array.
      Parameters:
      a - the array double[]
      Returns:
      the index of the minimum element
    • min

      public static float[] min(float[] a, float[] b)
      Find minimum element in two float arrays a and b.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the minimum element in a and b
    • min

      public static double[] min(double[] a, double[] b)
      Find minimum element in two double arrays a and b.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the minimum element in a and b
    • min

      public static double min(double[] a, boolean[] active)
      Find minimum element in double array a among active elements. More precisely, disregard elements a[i] with active[i]==false.
      Parameters:
      a - the array double[]
      active - the array boolean[] indicating whether element should be skipped (false) or considered (true).
      Returns:
      the minimum active element
    • max

      public static boolean max(boolean[] a)
      Find maximum element in boolean array/vector a.
      Parameters:
      a - the boolean[] array
      Returns:
      false if all elements are false and true if at least one element is true
    • max

      public static int max(int[] a)
      Find maximum element in int array/vector a.
      Parameters:
      a - the array int[]
      Returns:
      the maximum element
    • max

      public static long max(long[] a)
      Find maximum element in long array/vector a.
      Parameters:
      a - the array long[]
      Returns:
      the maximum element
    • max

      public static float max(float[] a)
      Find maximum element in float array/vector a.
      Parameters:
      a - the array float[]
      Returns:
      the maximum element
    • max

      public static double max(double[] a)
      Find maximum element in double array/vector a.
      Parameters:
      a - the array double[]
      Returns:
      the maximum element
    • max

      public static int max(int[][] a)
      Find maximum element in int array/matrix a.
      Parameters:
      a - the array int[][]
      Returns:
      the maximum element
    • max

      public static long max(long[][] a)
      Find maximum element in long array/matrix a.
      Parameters:
      a - the array long[][]
      Returns:
      the maximum element
    • max

      public static float max(float[][] a)
      Find maximum element in float array/matrix a.
      Parameters:
      a - the array float[][]
      Returns:
      the maximum element
    • max

      public static double max(double[][] a)
      Find maximum element in double array/matrix a.
      Parameters:
      a - the array double[][]
      Returns:
      the maximum element
    • maxIndex

      public static int maxIndex(int[] a)
      Find index of maximum element in integer array.
      Parameters:
      a - the array int[]
      Returns:
      the index of maximum element
    • maxIndex

      public static int maxIndex(long[] a)
      Find index of maximum element in long array.
      Parameters:
      a - the array long[]
      Returns:
      the index of maximum element
    • maxIndex

      public static int maxIndex(float[] a)
      Find index of maximum element in float array.
      Parameters:
      a - the array float[]
      Returns:
      the index of maximum element
    • maxIndex

      public static int maxIndex(double[] a)
      Find index of maximum element in double array.
      Parameters:
      a - the array double[]
      Returns:
      the index of maximum element
    • max

      public static float[] max(float[] a, float[] b)
      Find maximum element in two float arrays a and b.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the maximum element in a and b
    • max

      public static double[] max(double[] a, double[] b)
      Find maximum element in two double arrays a and b.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the maximum element in a and b
    • max

      public static double max(double[] a, boolean[] active)
      Find maximum element in double array a among active elements. More precisely, disregard elements a[i] with active[i]==false.
      Parameters:
      a - the array double[]
      active - the array boolean[] indicating whether element should be skipped (false) or considered (true).
      Returns:
      the maximum active element
    • norm

      public static int norm(int[] a)
      Norm of integer array a.
      Parameters:
      a - the array int[]
      Returns:
      the sum of all elements a[i]
    • norm

      public static long norm(long[] a)
      Norm of long array a.
      Parameters:
      a - the rray long[]
      Returns:
      the sum of all elements a[i]
    • norm

      public static float norm(float[] a)
      Norm of float array a.
      Parameters:
      a - the array float[]
      Returns:
      the sum of all elements a[i]
    • norm

      public static double norm(double[] a)
      Norm of double array a.
      Parameters:
      a - the array double[]
      Returns:
      the sum of all elements a[i]
    • normalize

      public static float[] normalize(float[] a)
      Normalize float array a. Scales elements such that the sum over all elements a[i] adds up to 1. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements of a are overwritten with new values.
      Parameters:
      a - the array float[]
      Returns:
      the normalized array a
    • normalize

      public static float[] normalize(float[] a, int from, int to)
      Normalize elements ranging from index from to index to in float array a. Scales elements such that the sum over elements a[i] with i=from,...,to add up to 1. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements of a are overwritten with new values.
      Parameters:
      a - the float[] array to normalize
      from - the start index of the section to normalize
      to - the end index of the section to normalize
      Returns:
      the array a with normalized section
      See Also:
    • normalize

      public static double[] normalize(double[] a)
      Normalize double array a. Scales elements such that the sum over all elements a[i] adds up to 1. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements of a are overwritten with new values.
      Parameters:
      a - the double[] array to normalize
      Returns:
      the normalized array a
      See Also:
    • normalize

      public static double[] normalize(double[] a, int from, int to)
      Normalize elements ranging from index from to index to in double array a. Scales elements such that the sum over elements a[i] with i=from,...,to add up to 1. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements of a are overwritten with new values.
      Parameters:
      a - the double[] array to normalize
      from - the start index of the section to normalize
      to - the end index of the section to normalize
      Returns:
      the array a with normalized section
      See Also:
    • copy

      public static double[] copy(int[] src, double[] dst)
      Element-wise copy of integer array/vector src to double array/vector dst.
      Parameters:
      src - the int[] source array
      dst - the double[] destination array
      Returns:
      the array dst
    • copy

      public static int[] copy(int[] src, int[] dst)
      Copy the integer array/vector src to dst.
      Parameters:
      src - the int[] source vector
      dst - the int[] destination vector
      Returns:
      the matrix dst
    • copy

      public static double[] copy(double[] src, double[] dst)
      Copy the double 2D array/matrix src to dst.
      Parameters:
      src - the double[] source matrix
      dst - the double[] destination matrix
      Returns:
      the matrix dst
    • copy

      public static int[][] copy(int[][] src, int[][] dst)
      Copy the integer 2D array/matrix src to dst.
      Parameters:
      src - the int[][] source matrix
      dst - the int[][] destination matrix
      Returns:
      the matrix dst
    • copy

      public static double[][] copy(double[][] src, double[][] dst)
      Copy the double 2D array/matrix src to dst.
      Parameters:
      src - the double[][] source matrix
      dst - the double[][] destination matrix
      Returns:
      the matrix dst
    • add

      public static int[] add(int[] dst, int scalar)
      Add scalar value to each element of integer array/vector dst. Elements of dst are overwritten with new values.
      Parameters:
      dst - the array int[]
      scalar - the value to add to each element of dst
      Returns:
      the modified array dst
    • add

      public static long[] add(long[] dst, long scalar)
      Add scalar value to each element of long array/vector dst. Elements of dst are overwritten with new values.
      Parameters:
      dst - the array long[]
      scalar - the value to add to each element of dst
      Returns:
      the modified array dst
    • add

      public static float[] add(float[] dst, float scalar)
      Add scalar value to each element of float array/vector dst. Elements of dst are overwritten with new values.
      Parameters:
      dst - the array float[]
      scalar - the value to add to each element of dst
      Returns:
      the modified array dst
    • add

      public static double[] add(double[] dst, double scalar)
      Add scalar value to each element of double array/vector dst. Elements of dst are overwritten with new values.
      Parameters:
      dst - the array double[]
      scalar - the value to add to each element of dst
      Returns:
      the modified array dst
    • add

      public static int[] add(int[] dst, int[] add)
      Add integer arrays dst and add. Place result in dst (array add remains unchanged). Arrays dst and add can be of different lengths as long as dst.length<add.length. If add is longer, additional elements are ignored.
      Parameters:
      dst - the destination array
      add - the array to add to dst
      Returns:
      the modified array dst
      Throws:
      ArrayIndexOutOfBoundsException - if add.length<dst.length
    • add

      public static long[] add(long[] dst, long[] add)
      Add long arrays dst and add. Place result in dst (array add remains unchanged). Arrays dst and add can be of different lengths as long as dst.length<add.length. If add is longer, additional elements are ignored.
      Parameters:
      dst - the destination array
      add - the array to add to dst
      Returns:
      the modified array dst
      Throws:
      ArrayIndexOutOfBoundsException - if add.length<dst.length
    • add

      public static float[] add(float[] dst, float[] add)
      Add float arrays dst and add. Place result in dst (array add remains unchanged). Arrays dst and add can be of different lengths as long as dst.length<add.length. If add is longer, additional elements are ignored.
      Parameters:
      dst - the destination array
      add - the array to add to dst
      Returns:
      the modified array dst
      Throws:
      ArrayIndexOutOfBoundsException - if add.length<dst.length
    • add

      public static double[] add(double[] dst, double[] add)
      Add double arrays dst and add. Place result in dst (array add remains unchanged). Arrays dst and add can be of different lengths as long as dst.length<add.length. If add is longer, additional elements are ignored.
      Parameters:
      dst - the destination array
      add - the array to add to dst
      Returns:
      the modified array dst
      Throws:
      ArrayIndexOutOfBoundsException - if add.length<dst.length
    • add

      public static int[] add(int[] a, int[] b, int[] dst)
      Non-destructive array addition. Add int arrays a and b and place result in dst (arrays a and b remain unchanged). Arrays a, b and dst can be of different lengths as long as a.length≤b.length≤dst.length. If b or dst is longer than a, additional elements are ignored.
      Parameters:
      a - the first array
      b - the second array
      dst - the result array
      Returns:
      the modified array dst=a+b
      Throws:
      ArrayIndexOutOfBoundsException - if dst.length<a.length or b.length<a.length
    • add

      public static long[] add(long[] a, long[] b, long[] dst)
      Non-destructive array addition. Add long arrays a and b and place result in dst (arrays a and b remain unchanged). Arrays a, b and dst can be of different lengths as long as a.length≤b.length≤dst.length. If b or dst is longer than a, additional elements are ignored.
      Parameters:
      a - the first array
      b - the second array
      dst - the result array
      Returns:
      the modified array dst=a+b
      Throws:
      ArrayIndexOutOfBoundsException - if dst.length<a.length or b.length<a.length
    • add

      public static float[] add(float[] a, float[] b, float[] dst)
      Non-destructive array addition. Add float arrays a and b and place result in dst (arrays a and b remain unchanged). Arrays a, b and dst can be of different lengths as long as a.length≤b.length≤dst.length. If b or dst is longer than a, additional elements are ignored.
      Parameters:
      a - the first array
      b - the second array
      dst - the result array
      Returns:
      the modified array dst=a+b
      Throws:
      ArrayIndexOutOfBoundsException - if dst.length<a.length or b.length<a.length
    • add

      public static double[] add(double[] a, double[] b, double[] dst)
      Non-destructive array addition. Add double arrays a and b and place result in dst (arrays a and b remain unchanged). Arrays a, b and dst can be of different lengths as long as a.length≤b.length≤dst.length. If b or dst is longer than a, additional elements are ignored.
      Parameters:
      a - the first array
      b - the second array
      dst - the result array
      Returns:
      the modified array dst=a+b
      Throws:
      ArrayIndexOutOfBoundsException - if dst.length<a.length or b.length<a.length
    • addscale

      public static double[] addscale(double[] a, double[] b, double s, double[] dst)
      Non-destructive scalar multiplication and array addition. Multiply double array b by scalar value s, add the result to array a and store result in array dst (arrays a and b remain unchanged). Arrays a, b and dst can be of different lengths as long as a.length≤b.length≤dst.length. If b or dst are longer than a, additional elements are ignored.
      Parameters:
      a - the first array
      b - the second array
      s - the scalar multiplier
      dst - the result array
      Returns:
      the modified array dst=a+s*b
      Throws:
      ArrayIndexOutOfBoundsException - if a.length<dst.length or b.length<dst.length
    • sub

      public static int[] sub(int[] dst, int[] sub)
      Subtract integer array sub from array dst. Place result in dst (array sub remains unchanged). Arrays dst and sub can be of different lengths as long as dst.length<sub.length. If sub is longer, additional elements are ignored.
      Parameters:
      dst - the destination array
      sub - the array to subtract from dst
      Returns:
      the modified array dst
      Throws:
      ArrayIndexOutOfBoundsException - if sub.length<dst.length
    • sub

      public static long[] sub(long[] dst, long[] sub)
      Subtract long array sub from array dst. Place result in dst (array sub remains unchanged). Arrays dst and sub can be of different lengths as long as dst.length<sub.length. If sub is longer, additional elements are ignored.
      Parameters:
      dst - the destination array
      sub - the array to subtract from dst
      Returns:
      the modified array dst
      Throws:
      ArrayIndexOutOfBoundsException - if sub.length<dst.length
    • sub

      public static float[] sub(float[] dst, float[] sub)
      Subtract float array sub from array dst. Place result in dst (array sub remains unchanged). Arrays dst and sub can be of different lengths as long as dst.length<sub.length. If sub is longer, additional elements are ignored.
      Parameters:
      dst - the destination array
      sub - the array to subtract from dst
      Returns:
      the modified array dst
      Throws:
      ArrayIndexOutOfBoundsException - if sub.length<dst.length
    • sub

      public static double[] sub(double[] dst, double[] sub)
      Subtract double array sub from array dst. Place result in dst (array sub remains unchanged). Arrays dst and sub can be of different lengths as long as dst.length<sub.length. If sub is longer, additional elements are ignored.
      Parameters:
      dst - the destination array
      sub - the array to subtract from dst
      Returns:
      the modified array dst
      Throws:
      ArrayIndexOutOfBoundsException - if sub.length<dst.length
    • sub

      public static int[] sub(int[] orig, int[] sub, int[] dst)
      Non-destructive array subtraction. Subtract integer array sub from array orig and place result in dst (arrays orig and sub remain unchanged). Arrays orig, sub and dst can be of different lengths as long as orig.length≤sub.length≤dst.length. If dst or sub are longer, additional elements are ignored.
      Parameters:
      orig - the first array
      sub - the second array to subtract from orig
      dst - the result array
      Returns:
      the modified array dst=orig-sub
      Throws:
      ArrayIndexOutOfBoundsException - if dst.length<orig.length or sub.length<orig.length
    • sub

      public static long[] sub(long[] orig, long[] sub, long[] dst)
      Non-destructive array subtraction. Subtract long array sub from array orig and place result in dst (arrays orig and sub remain unchanged). Arrays orig, sub and dst can be of different lengths as long as orig.length≤sub.length≤dst.length. If dst or sub are longer, additional elements are ignored.
      Parameters:
      orig - the first array
      sub - the second array to subtract from orig
      dst - the result array
      Returns:
      the modified array dst=orig-sub
      Throws:
      ArrayIndexOutOfBoundsException - if dst.length<orig.length or sub.length<orig.length
    • sub

      public static float[] sub(float[] orig, float[] sub, float[] dst)
      Non-destructive array subtraction. Subtract float array sub from array orig and place result in dst (arrays orig and sub remain unchanged). Arrays orig, sub and dst can be of different lengths as long as orig.length≤sub.length≤dst.length. If dst or sub are longer, additional elements are ignored.
      Parameters:
      orig - the first array
      sub - the second array to subtract from orig
      dst - the result array
      Returns:
      the modified array dst=orig-sub
      Throws:
      ArrayIndexOutOfBoundsException - if dst.length<orig.length or sub.length<orig.length
    • sub

      public static double[] sub(double[] orig, double[] sub, double[] dst)
      Non-destructive array subtraction. Subtract double array sub from array orig and place result in dst (arrays orig and sub remain unchanged). Arrays orig, sub and dst can be of different lengths as long as orig.length≤sub.length≤dst.length. If dst or sub are longer, additional elements are ignored.
      Parameters:
      orig - the first array
      sub - the second array to subtract from orig
      dst - the result array
      Returns:
      the modified array dst=orig-sub
      Throws:
      ArrayIndexOutOfBoundsException - if dst.length<orig.length or sub.length<orig.length
    • distSq

      public static int distSq(int[] a, int[] b)
      Squared distance of two integer arrays a and b given by the sum over (a[i]-b[i])^2. Arrays a and b are preserved.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the distance between a and b squared
    • distSq

      public static double distSq(double[] a, double[] b)
      Squared distance of two double arrays a and b given by the sum over (a[i]-b[i])^2. Arrays a and b are preserved.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the distance between a and b squared
    • dist

      public static double dist(int[] a, int[] b)
      Distance of two integer arrays a and b given by the square root of the sum over (a[i]-b[i])^2. Arrays a and b are preserved.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the distance between a and b
    • dist

      public static double dist(double[] a, double[] b)
      Distance of two double arrays a and b given by the square root of the sum over (a[i]-b[i])^2. Arrays a and b are preserved.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the distance between a and b
    • dot

      public static int dot(int[] a, int[] b)
      Dot product of two integer arrays a and b given by the sum over a[i]*b[i]. Arrays a and b are preserved.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the dot product a.b
    • dot

      public static long dot(long[] a, long[] b)
      Dot product of two long arrays a and b given by the sum over a[i]*b[i]. Arrays a and b are preserved.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the dot product a.b
    • dot

      public static float dot(float[] a, float[] b)
      Dot product of two float arrays a and b given by the sum over a[i]*b[i]. Arrays a and b are preserved.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the dot product a.b
    • dot

      public static double dot(double[] a, double[] b)
      Dot product of two double arrays a and b given by the sum over a[i]*b[i]. Arrays a and b are preserved.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      the dot product a.b
    • multiply

      public static int[] multiply(int[] dst, int scalar)
      Scalar multiplication of integer array dst by scalar.
      Parameters:
      dst - the array
      scalar - the multiplier
      Returns:
      the modified array dst
    • multiply

      public static long[] multiply(long[] dst, long scalar)
      Scalar multiplication of long array dst by scalar.
      Parameters:
      dst - the array
      scalar - the multiplier
      Returns:
      the modified array dst
    • multiply

      public static float[] multiply(float[] dst, float scalar)
      Scalar multiplication of float array dst by scalar.
      Parameters:
      dst - the array
      scalar - the multiplier
      Returns:
      the modified array dst
    • multiply

      public static double[] multiply(double[] dst, double scalar)
      Scalar multiplication of double array dst by scalar.
      Parameters:
      dst - the array
      scalar - the multiplier
      Returns:
      the modified array dst
    • multiply

      public static int[] multiply(int[] a, int scalar, int[] dst)
      Scalar multiplication of integer array a by scalar with result in dst.
      Parameters:
      a - the array of int's
      scalar - the multiplier
      dst - the destination array
      Returns:
      the modified array dst
    • multiply

      public static long[] multiply(long[] a, long scalar, long[] dst)
      Scalar multiplication of long array a by scalar with result in dst.
      Parameters:
      a - the array of long's
      scalar - the multiplier
      dst - the destination array
      Returns:
      the modified array dst
    • multiply

      public static float[] multiply(float[] a, float scalar, float[] dst)
      Scalar multiplication of float array a by scalar with result in dst.
      Parameters:
      a - the array of float's
      scalar - the multiplier
      dst - the destination array
      Returns:
      the modified array dst
    • multiply

      public static double[] multiply(double[] a, double scalar, double[] dst)
      Scalar multiplication of double array a by scalar with result in dst.
      Parameters:
      a - the array of double's
      scalar - the multiplier
      dst - the destination array
      Returns:
      the modified array dst
    • multiply

      public static int[] multiply(int[] dst, int[] a)
      Element-wise multiplication of integer arrays a and dst. The result is placed in dst (array a is preserved).
      Parameters:
      dst - the first array
      a - the second array
      Returns:
      the modified array dst
    • multiply

      public static long[] multiply(long[] dst, long[] a)
      Element-wise multiplication of long arrays a and dst. The result is placed in dst (array a is preserved).
      Parameters:
      dst - the first array
      a - the second array
      Returns:
      the modified array dst
    • multiply

      public static float[] multiply(float[] dst, float[] a)
      Element-wise multiplication of float arrays a and dst. The result is placed in dst (array a is preserved).
      Parameters:
      dst - the first array
      a - the second array
      Returns:
      the modified array dst
    • multiply

      public static double[] multiply(double[] dst, double[] a)
      Element-wise multiplication of double array a and dst. The result is placed in dst (array a is preserved).
      Parameters:
      dst - the first array
      a - the second array
      Returns:
      the modified array dst
    • multiply

      public static int[] multiply(int[] a, int[] b, int[] dst)
      Non-destructive, element-wise multiplication of integer array a and b. The result is placed in dst (array a and b are preserved).
      Parameters:
      a - the first array
      b - the second array
      dst - the result array
      Returns:
      the modified array dst[i]=a[i]*b[i]
    • multiply

      public static long[] multiply(long[] a, long[] b, long[] dst)
      Non-destructive, element-wise multiplication of long arrays a and b. The result is placed in dst (arrays a and b are preserved).
      Parameters:
      a - the first array
      b - the second array
      dst - the result array
      Returns:
      the modified array dst[i]=a[i]*b[i]
    • multiply

      public static float[] multiply(float[] a, float[] b, float[] dst)
      Non-destructive, element-wise multiplication of float arrays a and b. The result is placed in dst (arrays a and b are preserved).
      Parameters:
      a - the first array
      b - the second array
      dst - the result array
      Returns:
      the modified array dst[i]=a[i]*b[i]
    • multiply

      public static double[] multiply(double[] a, double[] b, double[] dst)
      Non-destructive, element-wise multiplication of double arrays a and b. The result is placed in dst (arrays a and b are preserved).
      Parameters:
      a - the first array
      b - the second array
      dst - the result array
      Returns:
      the modified array dst[i]=a[i]*b[i]
    • multiply

      public static int[] multiply(int[][] mat, int[] vec, int[] dst)
      Non-destructive integer matrix multiplication. Matrix mat multiplied by array vec and the result stored in dst (right multiplication). Matrix mat and array vec preserved.
      Parameters:
      mat - the matrix
      vec - the array
      dst - the result array
      Returns:
      the modified array dst=mat * vec
    • multiply

      public static long[] multiply(long[][] mat, long[] vec, long[] dst)
      Non-destructive long matrix multiplication. Matrix mat multiplied by array vec and the result stored in dst (right multiplication). Matrix mat and array vec preserved.
      Parameters:
      mat - the matrix
      vec - the array
      dst - the result array
      Returns:
      the modified array dst=mat * vec
    • multiply

      public static float[] multiply(float[][] mat, float[] vec, float[] dst)
      Non-destructive float matrix multiplication. Matrix mat multiplied by array vec and the result stored in dst (right multiplication). Matrix mat and array vec preserved.
      Parameters:
      mat - the matrix
      vec - the array
      dst - the result array
      Returns:
      the modified array dst=mat * vec
    • multiply

      public static double[] multiply(double[][] mat, double[] vec, double[] dst)
      Non-destructive double matrix multiplication. Matrix mat multiplied by array vec and the result stored in dst (right multiplication). Matrix mat and array vec preserved.
      Parameters:
      mat - the matrix
      vec - the array
      dst - the result array
      Returns:
      the modified array dst=mat * vec
    • abs

      public static int[] abs(int[] a)
      Element-wise absolute value of int array a.
      Parameters:
      a - the array to apply absolute value to
      Returns:
      the modified array a
    • abs

      public static float[] abs(float[] a)
      Element-wise absolute value of float array a.
      Parameters:
      a - the array to apply absolute value to
      Returns:
      the modified array a
    • abs

      public static double[] abs(double[] a)
      Element-wise absolute value of double array a.
      Parameters:
      a - the array to apply absolute value to
      Returns:
      the modified array a
    • log10

      public static float[] log10(float[] a)
      Element-wise logarithm of float array a (base 10).
      Parameters:
      a - the array to apply logarithm to
      Returns:
      the modified array a
    • log10

      public static double[] log10(double[] a)
      Element-wise logarithm of double array a (base 10).
      Parameters:
      a - the array to apply logarithm to
      Returns:
      the modified array a
    • sqrt

      public static float[] sqrt(float[] a)
      Element-wise square-root of float array a.
      Parameters:
      a - the array to apply logarithm to
      Returns:
      the modified array a
    • sqrt

      public static double[] sqrt(double[] a)
      Element-wise square-root of double array a.
      Parameters:
      a - the array to apply logarithm to
      Returns:
      the modified array a
    • clone

      public static boolean[] clone(boolean[] orig)
      GWT has an aversion to clone()ing - provide alternatives.
      Parameters:
      orig - the boolean array to clone.
      Returns:
      the clone of boolean array orig.
    • clone

      public static int[] clone(int[] orig)
      GWT has an aversion to clone()ing - provide alternatives.
      Parameters:
      orig - the int array to clone.
      Returns:
      the clone of int array orig.
    • clone

      public static double[] clone(double[] orig)
      GWT has an aversion to clone()ing - provide alternatives.
      Parameters:
      orig - the double array to clone.
      Returns:
      the clone of double array orig.
    • clone

      public static double[][] clone(double[][] orig)
      GWT has an aversion to clone()ing - provide alternatives.
      Parameters:
      orig - the two dimensional array (matrix) to clone.
      Returns:
      the clone of matrix orig.