Documentation of 'kcl.waterloo.math.ArrayMath' Java class
ArrayMath
kcl.waterloo.math

Class ArrayMath



  • public final class ArrayMath
    extends java.lang.Object
    Provides convenience static library for math operations across vectors. Most methods are defined for double[] only.

    Methods appended with "i" perform operations in-place and so over-write the input data by reference.

    • Constructor Summary

      Constructors 
      Constructor and Description
      ArrayMath() 
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      static double[] abs(double[] in)
      Returns the absolute values for a double[]
      static double[] absi(double[] in)
      Returns the absolute values for a double[] (in-place)
      static double[] add(double[] in1, double factor)
      Returns in1 + factor element-wise
      static double[] add(double[] in1, double[] in2)
      Returns in1+in2 element-wise where in1 and in2 are double[]s
      static double[] addi(double[] in1, double factor)
      Returns in1 + factor element-wise (in-place)
      static double[] addi(double[] in1, double[] in2)
      Returns in1+in2 element-wise where in1 and in2 are double[]s
      static boolean any(boolean[] in)
      Returns true where any element in the input is true
      static double[] cusum(double[] in)
      Returns the cumulative sum of the elements of the input.
      static double[] cusumi(double[] in)
      Returns the cumulative y of the elements of the input (in-place).
      static double[] diff(double[] in)
      Returns the first derivative for a double[]
      static double[] diffi(double[] in)
      Returns the first derivative for a double[] (in-place).
      static double[] diffpad(double[] in) 
      static double[] div(double[] in1, double factor)
      Returns in1/factor element-wise where in1 is a double[] and factor is scalar
      static double[] div(double[] in1, double[] in2)
      Returns in1/in2 element-wise where in1 and in2 are double[]s
      static double[] divi(double[] in1, double factor)
      Returns in1/factor element-wise where in1 is a double[] and factor is scalar (in-place)
      static double[] divi(double[] in1, double[] in2)
      Returns in1/in2 element-wise where in1 and in2 are double[]s (in-place)
      static double dot(double[] in1, double[] in2)
      Returns scalar dot product of in1 & in2
      static double[] fill(int len, int start, int inc)
      Fills a double[] of length len, with values beginning with start and incrementing by inc.
      static boolean[] filli(boolean[] in, boolean constant)
      Fills the input with the specified value (in-place)
      static double[] filli(double[] in, double constant)
      Fills the input with the specified value (in-place)
      static boolean[] isEqual(double[] in, double x)
      Returns true for in==x element-wise.
      static boolean[] isGE(double[] in, double x)
      Returns true where in is greater than or equal to x, element-wise.
      static boolean[] isGT(double[] in, double x)
      Returns true where in is greater than x, element-wise.
      static boolean[] isInfinite(double[] in)
      Returns true where in equals +infinity or -infinity, element-wise.
      static boolean[] isLE(double[] in, double x)
      Returns true where in has magnitude less than or equal to x, element-wise.
      static boolean[] isLT(double[] in, double x)
      Returns true where in has magnitude less than x, element-wise.
      static boolean[] isNaN(double[] in)
      Returns true where in is Not-a-Number element-wise.
      static boolean[] isZero(double[] in)
      Returns true for in==0 (or -0) element-wise
      static double[] linspace(double start, double stop, int n) 
      static double[] log10(double[] in)
      Returns the Math.log10() for a double[]
      static double[] log10i(double[] in)
      Returns the Math.log10() for a double[] (in-place)
      static double max(double[] in)
      Returns maximum value ignoring NaNs.
      static double[] max(double[] in, double factor)
      Returns a vector containing the maximum for each element from the input and the factor supplied.
      static double[] max(double[] in1, double[] in2)
      Returns a vector containing the maximum for each element from the inputs.
      static double[] maxi(double[] in1, double factor)
      Returns a vector containing the maximum for each element from the input and factor.
      static double[] maxi(double[] in1, double[] in2)
      Returns a vector containing the maximum for each element from the inputs.
      static double min(double[] in)
      Returns minimum value ignoring NaNs.
      static double[] min(double[] in, double factor)
      Returns a vector containing the minimum for each element from the input and the factor supplied.
      static double[] min(double[] in1, double[] in2)
      Returns a vector containing the minimum for each element from the inputs.
      static double[] mini(double[] in1, double factor)
      Returns a vector containing the minimum for each element from the inputs.
      static double[] mini(double[] in1, double[] in2)
      Returns a vector containing the minimum for each element from the inputs.
      static double[] minmax(double[] in)
      Returns double[2] array containing the minimum and maximum values ignoring NaNs.
      static int[] minmax(int[] in)
      Returns int[2] array containing the minimum and maximum values ignoring NaNs.
      static double[] mul(double[] in1, double factor)
      Returns in1*factor element-wise where in1 is a double[] and factor is scalar
      static double[] mul(double[] in1, double[] in2)
      Returns in1*in2 element-wise where in1 and in2 are double[]s
      static double[] muli(double[] in1, double factor)
      Returns in1*factor element-wise where in1 is a double[] and factor is scalar (in-place)
      static double[] muli(double[] in1, double[] in2)
      Returns in1*in2 element-wise where in1 and in2 are double[]s (in-place)
      static double[] neg(double[] in)
      Returns the negated input
      static double[] negi(double[] in)
      Returns the negated input (in-place)
      static double[] pow(double[] in, double exponent)
      Returns the Math.pow() for a double[]
      static double[] powi(double[] in, double exponent)
      Returns the Math.pow() for a double[] (in-place)
      double[] repVeci(double[] in, double[] vec)
      Repetitively fills the vector in with the values from vec
      static double[] sqrt(double[] in)
      Returns the square roots for a double[]
      static double[] sqrti(double[] in)
      Returns the square roots for a double[] (in-place)
      static double[] sub(double[] in, double factor)
      Returns in-factor element-wise
      static double[] sub(double[] in1, double[] in2)
      Returns in1-in2 element-wise where in1 and in2 are double[]s
      static double[] subi(double[] in, double factor)
      Returns in-factor element-wise (in-place)
      static double[] subi(double[] in1, double[] in2)
      Returns in1-in2 element-wise where in1 and in2 are double[]s
      static double[] subi(double factor, double[] in1)
      Returns factor - in1 element-wise where in1 is a double[] and factor is scalar (in-place)
      static double sum(double[] in)
      Returns the sum of the elements of the input.
      static double sum(double[] in, int idx0, int idx1) 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArrayMath

        public ArrayMath()
    • Method Detail

      • sum

        public static double sum(double[] in)
        Returns the sum of the elements of the input. Compensates for IEEE precision loss.
        Parameters:
        in - the input array
        Returns:
        a double
      • sum

        public static double sum(double[] in,
                                 int idx0,
                                 int idx1)
      • cusum

        public static double[] cusum(double[] in)
        Returns the cumulative sum of the elements of the input.
        Parameters:
        in - the input array
        Returns:
        a double[]
      • cusumi

        public static double[] cusumi(double[] in)
        Returns the cumulative y of the elements of the input (in-place).
        Parameters:
        in - the input array
        Returns:
        a double[]
      • abs

        public static double[] abs(double[] in)
        Returns the absolute values for a double[]
        Parameters:
        in - the input array
        Returns:
        a double[]
      • absi

        public static double[] absi(double[] in)
        Returns the absolute values for a double[] (in-place)
        Parameters:
        in - the input array
        Returns:
        a double[]
      • sqrt

        public static double[] sqrt(double[] in)
        Returns the square roots for a double[]
        Parameters:
        in - the input array
        Returns:
        a double[]
      • sqrti

        public static double[] sqrti(double[] in)
        Returns the square roots for a double[] (in-place)
        Parameters:
        in - the input array
        Returns:
        double[]
      • neg

        public static double[] neg(double[] in)
        Returns the negated input
        Parameters:
        in - the input array
        Returns:
        a double[]
      • negi

        public static double[] negi(double[] in)
        Returns the negated input (in-place)
        Parameters:
        in - the input array
        Returns:
        a double[]
      • log10

        public static double[] log10(double[] in)
        Returns the Math.log10() for a double[]
        Parameters:
        in - the input array
        Returns:
        a double[]
      • log10i

        public static double[] log10i(double[] in)
        Returns the Math.log10() for a double[] (in-place)
        Parameters:
        in - the input array
        Returns:
        a double[]
      • pow

        public static double[] pow(double[] in,
                                   double exponent)
        Returns the Math.pow() for a double[]
        Parameters:
        in - the input array
        exponent - the exponent
        Returns:
        a double[]
      • powi

        public static double[] powi(double[] in,
                                    double exponent)
        Returns the Math.pow() for a double[] (in-place)
        Parameters:
        in - the input array
        exponent - the exponent
        Returns:
        a double[]
      • diff

        public static double[] diff(double[] in)
        Returns the first derivative for a double[]
        Parameters:
        in - the input array
        Returns:
        a double[]
      • diffpad

        public static double[] diffpad(double[] in)
      • diffi

        public static double[] diffi(double[] in)
        Returns the first derivative for a double[] (in-place). The final element will be set to NaN.
        Parameters:
        in - the input array
        Returns:
        a double[]
      • fill

        public static double[] fill(int len,
                                    int start,
                                    int inc)
        Fills a double[] of length len, with values beginning with start and incrementing by inc. start and inc must be integers Output is reliable only for values with a magnitude less than or equal to 2^53
        Parameters:
        len - the length of the array to create
        start - the starting value
        inc - the increment between elements
        Returns:
        a double[]
      • filli

        public static double[] filli(double[] in,
                                     double constant)
        Fills the input with the specified value (in-place)
        Parameters:
        in - the input array
        constant - the constant value to fill the array with
        Returns:
        a double[]
      • filli

        public static boolean[] filli(boolean[] in,
                                      boolean constant)
        Fills the input with the specified value (in-place)
        Parameters:
        in - the input array
        constant - the constant value to fill the array with
        Returns:
        a boolean[]
      • div

        public static double[] div(double[] in1,
                                   double[] in2)
        Returns in1/in2 element-wise where in1 and in2 are double[]s
        Parameters:
        in1 - the numerator array
        in2 - the divisor array
        Returns:
        a double[] the returned array
      • divi

        public static double[] divi(double[] in1,
                                    double[] in2)
        Returns in1/in2 element-wise where in1 and in2 are double[]s (in-place)
        Parameters:
        in1 - the numerator array
        in2 - the divisor array
        Returns:
        a double[] the returned array (i.e. the numerator array)
      • div

        public static double[] div(double[] in1,
                                   double factor)
        Returns in1/factor element-wise where in1 is a double[] and factor is scalar
        Parameters:
        in1 - the numerator array
        factor - the scalar divisor
        Returns:
        a double[] the returned array
      • divi

        public static double[] divi(double[] in1,
                                    double factor)
        Returns in1/factor element-wise where in1 is a double[] and factor is scalar (in-place)
        Parameters:
        in1 - the input array
        factor - the divisor
        Returns:
        a double[] the output array (i.e. in1)
      • subi

        public static double[] subi(double factor,
                                    double[] in1)
        Returns factor - in1 element-wise where in1 is a double[] and factor is scalar (in-place)
        Parameters:
        in1 - the input array
        factor - the scalar to subtract
        Returns:
        a double[] the output array (i.e. in1)
      • mul

        public static double[] mul(double[] in1,
                                   double[] in2)
        Returns in1*in2 element-wise where in1 and in2 are double[]s
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        a double[] the element-wise product
      • muli

        public static double[] muli(double[] in1,
                                    double[] in2)
        Returns in1*in2 element-wise where in1 and in2 are double[]s (in-place)
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        a double[], the element-wise product (i.e. in1)
      • mul

        public static double[] mul(double[] in1,
                                   double factor)
        Returns in1*factor element-wise where in1 is a double[] and factor is scalar
        Parameters:
        in1 - the input array
        factor - a scalar factor
        Returns:
        a double[] the product
      • muli

        public static double[] muli(double[] in1,
                                    double factor)
        Returns in1*factor element-wise where in1 is a double[] and factor is scalar (in-place)
        Parameters:
        in1 - the input array
        factor - a scalar factor
        Returns:
        a double[] the product (i.e. in1)
      • add

        public static double[] add(double[] in1,
                                   double[] in2)
        Returns in1+in2 element-wise where in1 and in2 are double[]s
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        a double[] the sum
      • addi

        public static double[] addi(double[] in1,
                                    double[] in2)
        Returns in1+in2 element-wise where in1 and in2 are double[]s
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        a double[] the sum (i.e. in1)
      • add

        public static double[] add(double[] in1,
                                   double factor)
        Returns in1 + factor element-wise
        Parameters:
        in1 - the input array
        factor - the factor to add
        Returns:
        a double[] the sum
      • addi

        public static double[] addi(double[] in1,
                                    double factor)
        Returns in1 + factor element-wise (in-place)
        Parameters:
        in1 - the input array
        factor - the factor to add
        Returns:
        a double[] the sum (i.e. in1)
      • sub

        public static double[] sub(double[] in1,
                                   double[] in2)
        Returns in1-in2 element-wise where in1 and in2 are double[]s
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        double[] the difference
      • subi

        public static double[] subi(double[] in1,
                                    double[] in2)
        Returns in1-in2 element-wise where in1 and in2 are double[]s
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        double[] the difference (i.e. in1)
      • sub

        public static double[] sub(double[] in,
                                   double factor)
        Returns in-factor element-wise
        Parameters:
        in - input array
        factor - the value to subtract
        Returns:
        double[] the difference (i.e. in1)
      • subi

        public static double[] subi(double[] in,
                                    double factor)
        Returns in-factor element-wise (in-place)
        Parameters:
        in - input array
        factor - the value to subtract
        Returns:
        double[] the difference (i.e. in1)
      • dot

        public static double dot(double[] in1,
                                 double[] in2)
        Returns scalar dot product of in1 & in2
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        a double, the dot product of the inputs
      • isZero

        public static boolean[] isZero(double[] in)
        Returns true for in==0 (or -0) element-wise
        Parameters:
        in - the input array
        Returns:
        a boolean[]
      • isEqual

        public static boolean[] isEqual(double[] in,
                                        double x)
        Returns true for in==x element-wise.
        Parameters:
        in - the input array
        x - the value to compare to
        Returns:
        a boolean[]
      • isLT

        public static boolean[] isLT(double[] in,
                                     double x)
        Returns true where in has magnitude less than x, element-wise.
        Parameters:
        in - the input array
        x - the value to compare to
        Returns:
        a boolean[]
      • isLE

        public static boolean[] isLE(double[] in,
                                     double x)
        Returns true where in has magnitude less than or equal to x, element-wise.
        Parameters:
        in - the input array
        x - the value to compare to
        Returns:
        a boolean[]
      • isGT

        public static boolean[] isGT(double[] in,
                                     double x)
        Returns true where in is greater than x, element-wise.
        Parameters:
        in - the input array
        x - the value to compare to
        Returns:
        a boolean[]
      • isGE

        public static boolean[] isGE(double[] in,
                                     double x)
        Returns true where in is greater than or equal to x, element-wise.
        Parameters:
        in - the input array
        x - the value to compare to
        Returns:
        a boolean[]
      • isNaN

        public static boolean[] isNaN(double[] in)
        Returns true where in is Not-a-Number element-wise.
        Parameters:
        in - the input array
        Returns:
        a boolean[]
      • isInfinite

        public static boolean[] isInfinite(double[] in)
        Returns true where in equals +infinity or -infinity, element-wise.
        Parameters:
        in - the input array
        Returns:
        a boolean[]
      • any

        public static boolean any(boolean[] in)
        Returns true where any element in the input is true
        Parameters:
        in - the input array
        Returns:
        a boolean
      • min

        public static double min(double[] in)
        Returns minimum value ignoring NaNs.
        Parameters:
        in - a double[]
        Returns:
        the minimum value from the input
      • max

        public static double max(double[] in)
        Returns maximum value ignoring NaNs.
        Parameters:
        in - a double[]
        Returns:
        the maximum value from the input
      • min

        public static double[] min(double[] in1,
                                   double[] in2)
        Returns a vector containing the minimum for each element from the inputs. NaNs will always be judged greater than any other value.
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        the minimum values from the inputs
      • mini

        public static double[] mini(double[] in1,
                                    double[] in2)
        Returns a vector containing the minimum for each element from the inputs. NaNs will always be judged greater than any other value. In-place operation: the output will be put into the first input vector. (in-place)
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        the minimum values from the inputs (in in1)
      • min

        public static double[] min(double[] in,
                                   double factor)
        Returns a vector containing the minimum for each element from the input and the factor supplied.
        Parameters:
        in - input array
        factor - to comapre the input to
        Returns:
        the minimum values from the input and factor (in in1)
      • max

        public static double[] max(double[] in,
                                   double factor)
        Returns a vector containing the maximum for each element from the input and the factor supplied.
        Parameters:
        in - input array
        factor - to compare to
        Returns:
        the maximum values from the input and factor
      • max

        public static double[] max(double[] in1,
                                   double[] in2)
        Returns a vector containing the maximum for each element from the inputs. DOES NOT ignore NaNs which will be judged larger than any other value.
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        the maximum values from the inputs
      • maxi

        public static double[] maxi(double[] in1,
                                    double[] in2)
        Returns a vector containing the maximum for each element from the inputs. DOES NOT ignore NaNs which will be judged larger than any other value. (in-place)
        Parameters:
        in1 - input array 1
        in2 - input array 2
        Returns:
        the maximum values from the inputs (in in1)
      • maxi

        public static double[] maxi(double[] in1,
                                    double factor)
        Returns a vector containing the maximum for each element from the input and factor. DOES NOT ignore NaNs which will be judged larger than any other value (in-place).
        Parameters:
        in1 - input array 1
        factor -
        Returns:
        the maximum values from the input and factor (in in1)
      • mini

        public static double[] mini(double[] in1,
                                    double factor)
        Returns a vector containing the minimum for each element from the inputs. DOES NOT ignore NaNs which will be judged larger than any other value.
        Parameters:
        in1 - input array 1
        factor - a scalar value
        Returns:
        the minimum values
      • minmax

        public static double[] minmax(double[] in)
        Returns double[2] array containing the minimum and maximum values ignoring NaNs.
        Parameters:
        in - a double[]
        Returns:
        the minimum & maximum value from the input
      • minmax

        public static int[] minmax(int[] in)
        Returns int[2] array containing the minimum and maximum values ignoring NaNs.
        Parameters:
        in - a int[]
        Returns:
        the minimum & maximum value from the input
      • repVeci

        public double[] repVeci(double[] in,
                                double[] vec)
        Repetitively fills the vector in with the values from vec
        Parameters:
        in - the array to fill
        vec - the source values
        Returns:
        the returned repeated vector
      • linspace

        public static double[] linspace(double start,
                                        double stop,
                                        int n)

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.