kcl.waterloo.math
Class ArrayMath
- java.lang.Object
-
- kcl.waterloo.math.ArrayMath
-
public final class ArrayMath extends java.lang.ObjectProvides 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-wisestatic double[]add(double[] in1, double[] in2)Returns in1+in2 element-wise where in1 and in2 are double[]sstatic 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[]sstatic booleanany(boolean[] in)Returns true where any element in the input is truestatic 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 scalarstatic double[]div(double[] in1, double[] in2)Returns in1/in2 element-wise where in1 and in2 are double[]sstatic 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 doubledot(double[] in1, double[] in2)Returns scalar dot product of in1 & in2static 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-wisestatic 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 doublemax(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 doublemin(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 scalarstatic double[]mul(double[] in1, double[] in2)Returns in1*in2 element-wise where in1 and in2 are double[]sstatic 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 inputstatic 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 vecstatic 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-wisestatic double[]sub(double[] in1, double[] in2)Returns in1-in2 element-wise where in1 and in2 are double[]sstatic 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[]sstatic double[]subi(double factor, double[] in1)Returns factor - in1 element-wise where in1 is a double[] and factor is scalar (in-place)static doublesum(double[] in)Returns the sum of the elements of the input.static doublesum(double[] in, int idx0, int idx1)
-
-
-
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 arrayexponent- 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 arrayexponent- 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 createstart- the starting valueinc- 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 arrayconstant- 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 arrayconstant- 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 arrayin2- 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 arrayin2- 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 arrayfactor- 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 arrayfactor- 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 arrayfactor- 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 1in2- 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 1in2- 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 arrayfactor- 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 arrayfactor- 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 1in2- 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 1in2- 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 arrayfactor- 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 arrayfactor- 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 1in2- 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 1in2- 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 arrayfactor- 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 arrayfactor- 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 1in2- 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 arrayx- 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 arrayx- 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 arrayx- 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 arrayx- 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 arrayx- 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 1in2- 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 1in2- 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 arrayfactor- 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 arrayfactor- 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 1in2- 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 1in2- 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 1factor-- 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 1factor- 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 fillvec- 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