Package org.evoludo.math
Class ArrayMath
Object
ArrayMath
Collection of convenience methods for mathematical operations, including
array manipulations and statistics.
- Author:
- Christoph Hauert
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateEnsure non-instantiability with private default constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]abs(double[] a) Element-wise absolute value of double arraya.static float[]abs(float[] a) Element-wise absolute value of float arraya.static int[]abs(int[] a) Element-wise absolute value of int arraya.static double[]add(double[] dst, double scalar) Addscalarvalue to each element of double array/vectordst.static double[]add(double[] dst, double[] add) Add double arraysdstandadd.static double[]add(double[] a, double[] b, double[] dst) Non-destructive array addition.static float[]add(float[] dst, float scalar) Addscalarvalue to each element of float array/vectordst.static float[]add(float[] dst, float[] add) Add float arraysdstandadd.static float[]add(float[] a, float[] b, float[] dst) Non-destructive array addition.static int[]add(int[] dst, int scalar) Addscalarvalue to each element of integer array/vectordst.static int[]add(int[] dst, int[] add) Add integer arraysdstandadd.static int[]add(int[] a, int[] b, int[] dst) Non-destructive array addition.static long[]add(long[] dst, long scalar) Addscalarvalue to each element of long array/vectordst.static long[]add(long[] dst, long[] add) Add long arraysdstandadd.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) Appendelementtobooleanarrayarray.static double[]append(double[] array, double element) Appendelementtodoublearrayarray.static int[]append(int[] array, int element) Appendelementtointarrayarray.static <T> T[]append(T[] array, T element) Appendelementof typeTto arrayarrayof 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 intcompare(double[][] a1, double[][] a2) Compares the two specifieddouble[][]arrays.static intcompare(double[] a1, double[] a2) Compares the two specifieddouble[]arrays.static intcompare(int[][] a1, int[][] a2) Compares the two specifiedint[][]arrays.static intcompare(int[] a1, int[] a2) Compares the two specifiedint[]arrays.static double[][]copy(double[][] src, double[][] dst) Copy the double 2D array/matrixsrctodst.static double[]copy(double[] src, double[] dst) Copy the double 2D array/matrixsrctodst.static int[][]copy(int[][] src, int[][] dst) Copy the integer 2D array/matrixsrctodst.static double[]copy(int[] src, double[] dst) Element-wise copy of integer array/vectorsrcto double array/vectordst.static int[]copy(int[] src, int[] dst) Copy the integer array/vectorsrctodst.static doubledist(double[] a, double[] b) Distance of two double arraysaandbgiven by the square root of the sum over(a[i]-b[i])^2.static doubledist(int[] a, int[] b) Distance of two integer arraysaandbgiven by the square root of the sum over(a[i]-b[i])^2.static doubledistSq(double[] a, double[] b) Squared distance of two double arraysaandbgiven by the sum over(a[i]-b[i])^2.static intdistSq(int[] a, int[] b) Squared distance of two integer arraysaandbgiven by the sum over(a[i]-b[i])^2.static doubledot(double[] a, double[] b) Dot product of two double arraysaandbgiven by the sum overa[i]*b[i].static floatdot(float[] a, float[] b) Dot product of two float arraysaandbgiven by the sum overa[i]*b[i].static intdot(int[] a, int[] b) Dot product of two integer arraysaandbgiven by the sum overa[i]*b[i].static longdot(long[] a, long[] b) Dot product of two long arraysaandbgiven by the sum overa[i]*b[i].static boolean[]drop(boolean[] array, int index) Drop the element atindexfrom the arrayarrayof typeboolean[].static boolean[]drop(boolean[] array, int from, int to) Drop a range of elements starting with indexfromto indextofrom theboolean[]arrayarray.static double[]drop(double[] array, int index) Drop the element atindexfrom the arrayarrayof typedouble[].static double[]drop(double[] array, int from, int to) Drop a range of elements starting with indexfromto indextofrom thedouble[]arrayarray.static int[]drop(int[] array, int index) Drop the element atindexfrom the arrayarrayof typeint[].static int[]drop(int[] array, int from, int to) Drop a range of elements starting with indexfromto indextofrom theint[]arrayarray.static <T> T[]drop(T[] array, int index) Drop the element atindexfrom the arrayarrayof typeT.static <T> T[]drop(T[] array, int from, int to) Drop a range of elements starting with indexfromto indextofrom the arrayarrayof typeT.static intfirst(double[] a, double b) Find the first occurence of the elementbin the arraydouble[] a.static intfirst(int[] a, int b) Find the first occurence of the elementbin the arrayint[] a.static boolean[]insert(boolean[] array, boolean element, int index) Insert elementelementof typebooleaninto arrayarrayof the same type atindex.static double[]insert(double[] array, double element, int index) Insert elementelementof typedoubleinto arrayarrayof the same type atindex.static int[]insert(int[] array, int element, int index) Insert elementelementof typeintinto arrayarrayof the same type atindex.static <T> T[]insert(T[] array, T element, int index) Insert elementelementof typeTinto arrayarrayof the same type atindex.static intlast(double[] a, int b) Find the last occurence of the elementbin the arraydouble[] a.static intlast(int[] a, int b) Find the last occurence of the elementbin the arrayint[] a.static double[]log10(double[] a) Element-wise logarithm of double arraya(base 10).static float[]log10(float[] a) Element-wise logarithm of float arraya(base 10).static booleanmax(boolean[] a) Find maximum element in boolean array/vectora.static doublemax(double[] a) Find maximum element in double array/vectora.static doublemax(double[][] a) Find maximum element in double array/matrixa.static doublemax(double[] a, boolean[] active) Find maximum element in double arrayaamongactiveelements.static double[]max(double[] a, double[] b) Find maximum element in two double arraysaandb.static floatmax(float[] a) Find maximum element in float array/vectora.static floatmax(float[][] a) Find maximum element in float array/matrixa.static float[]max(float[] a, float[] b) Find maximum element in two float arraysaandb.static intmax(int[] a) Find maximum element in int array/vectora.static intmax(int[][] a) Find maximum element in int array/matrixa.static longmax(long[] a) Find maximum element in long array/vectora.static longmax(long[][] a) Find maximum element in long array/matrixa.static intmaxIndex(double[] a) Find index of maximum element in double array.static intmaxIndex(float[] a) Find index of maximum element in float array.static intmaxIndex(int[] a) Find index of maximum element in integer array.static intmaxIndex(long[] a) Find index of maximum element in long array.static double[]merge(double[] head, double[] tail) Appenddoublearraytailtodoublearrayhead.static <T> T[]merge(T[] head, T[] tail) Append arraytailof typeT[]to arrayhead.static booleanmin(boolean[] a) Find minimum element in boolean array/vectora.static doublemin(double[] a) Find minimum element in double array/vectora.static doublemin(double[][] a) Find minimum element in double array/matrixa.static doublemin(double[] a, boolean[] active) Find minimum element in double arrayaamongactiveelements.static double[]min(double[] a, double[] b) Find minimum element in two double arraysaandb.static floatmin(float[] a) Find minimum element in float array/vectora.static floatmin(float[][] a) Find minimum element in float array/matrixa.static float[]min(float[] a, float[] b) Find minimum element in two float arraysaandb.static intmin(int[] a) Find minimum element in integer array/vectora.static intmin(int[][] a) Find minimum element in integer array/matrixa.static longmin(long[] a) Find minimum element in long array/vectora.static longmin(long[][] a) Find minimum element in long array/matrixa.static intminIndex(double[] a) Find index of minimum element in double array.static intminIndex(float[] a) Find index of minimum element in float array.static intminIndex(int[] a) Find index of minimum element in integer array.static intminIndex(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 arraydstbyscalar.static double[]multiply(double[] dst, double[] a) Element-wise multiplication of double arrayaanddst.static double[]multiply(double[] a, double[] b, double[] dst) Non-destructive, element-wise multiplication of double arraysaandb.static double[]multiply(double[] a, double scalar, double[] dst) Scalar multiplication of double arrayabyscalarwith result indst.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 arraydstbyscalar.static float[]multiply(float[] dst, float[] a) Element-wise multiplication of float arraysaanddst.static float[]multiply(float[] a, float[] b, float[] dst) Non-destructive, element-wise multiplication of float arraysaandb.static float[]multiply(float[] a, float scalar, float[] dst) Scalar multiplication of float arrayabyscalarwith result indst.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 arraydstbyscalar.static int[]multiply(int[] dst, int[] a) Element-wise multiplication of integer arraysaanddst.static int[]multiply(int[] a, int[] b, int[] dst) Non-destructive, element-wise multiplication of integer arrayaandb.static int[]multiply(int[] a, int scalar, int[] dst) Scalar multiplication of integer arrayabyscalarwith result indst.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 arraydstbyscalar.static long[]multiply(long[] dst, long[] a) Element-wise multiplication of long arraysaanddst.static long[]multiply(long[] a, long[] b, long[] dst) Non-destructive, element-wise multiplication of long arraysaandb.static long[]multiply(long[] a, long scalar, long[] dst) Scalar multiplication of long arrayabyscalarwith result indst.static doublenorm(double[] a) Norm of double arraya.static floatnorm(float[] a) Norm of float arraya.static intnorm(int[] a) Norm of integer arraya.static longnorm(long[] a) Norm of long arraya.static double[]normalize(double[] a) Normalize double arraya.static double[]normalize(double[] a, int from, int to) Normalize elements ranging from indexfromto indextoin double arraya.static float[]normalize(float[] a) Normalize float arraya.static float[]normalize(float[] a, int from, int to) Normalize elements ranging from indexfromto indextoin float arraya.static double[]sqrt(double[] a) Element-wise square-root of double arraya.static float[]sqrt(float[] a) Element-wise square-root of float arraya.static double[]sub(double[] dst, double[] sub) Subtract double arraysubfrom arraydst.static double[]sub(double[] orig, double[] sub, double[] dst) Non-destructive array subtraction.static float[]sub(float[] dst, float[] sub) Subtract float arraysubfrom arraydst.static float[]sub(float[] orig, float[] sub, float[] dst) Non-destructive array subtraction.static int[]sub(int[] dst, int[] sub) Subtract integer arraysubfrom arraydst.static int[]sub(int[] orig, int[] sub, int[] dst) Non-destructive array subtraction.static long[]sub(long[] dst, long[] sub) Subtract long arraysubfrom arraydst.static long[]sub(long[] orig, long[] sub, long[] dst) Non-destructive array subtraction.
-
Constructor Details
-
ArrayMath
private ArrayMath()Ensure non-instantiability with private default constructor
-
-
Method Details
-
append
public static boolean[] append(boolean[] array, boolean element) Appendelementtobooleanarrayarray. The length of the returned array isarray.length + 1. The arrayarrayremains unchanged.- Parameters:
array- the arrayelement- the element to append- Returns:
- the new (longer) array
-
append
public static int[] append(int[] array, int element) Appendelementtointarrayarray. The length of the returned array isarray.length + 1. The arrayarrayremains unchanged.- Parameters:
array- the arrayelement- the element to append- Returns:
- the new (longer) array
-
append
public static double[] append(double[] array, double element) Appendelementtodoublearrayarray. The length of the returned array isarray.length + 1. The arrayarrayremains unchanged.- Parameters:
array- the arrayelement- the element to append- Returns:
- the new (longer) array
-
append
public static <T> T[] append(T[] array, T element) Appendelementof typeTto arrayarrayof the same type. The length of the returned array isarray.length + 1. The arrayarrayremains unchanged.- Type Parameters:
T- the type of the array- Parameters:
array- the arrayelement- the element to append- Returns:
- the new (longer) array
-
merge
public static double[] merge(double[] head, double[] tail) Appenddoublearraytailtodoublearrayhead. The length of the returned array ishead.length + tail.length. The arraysheadandtailremain unchanged.- Parameters:
head- the base arraytail- the array to append- Returns:
- the new (longer) array
-
merge
public static <T> T[] merge(T[] head, T[] tail) Append arraytailof typeT[]to arrayhead. The length of the returned array ishead.length + tail.length. The arraysheadandtailremain unchanged.- Type Parameters:
T- the type of the array- Parameters:
head- the base arraytail- the array to append- Returns:
- the new (longer) array
-
drop
public static boolean[] drop(boolean[] array, int index) Drop the element atindexfrom the arrayarrayof typeboolean[]. The length of the returned array isarray.length - 1.- Parameters:
array- the arrayindex- 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 indexfromto indextofrom theboolean[]arrayarray. The length of the returned array isarray.length - (to - from).- Parameters:
array- the arrayfrom- the first index to dropto- the last index to drop- Returns:
- the new (shorter) array
-
drop
public static int[] drop(int[] array, int index) Drop the element atindexfrom the arrayarrayof typeint[]. The length of the returned array isarray.length - 1.- Parameters:
array- the arrayindex- 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 indexfromto indextofrom theint[]arrayarray. The length of the returned array isarray.length - (to - from).- Parameters:
array- the arrayfrom- the first index to dropto- the last index to drop- Returns:
- the new (shorter) array
-
drop
public static double[] drop(double[] array, int index) Drop the element atindexfrom the arrayarrayof typedouble[]. The length of the returned array isarray.length - 1.- Parameters:
array- the arrayindex- 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 indexfromto indextofrom thedouble[]arrayarray. The length of the returned array isarray.length - (to - from).- Parameters:
array- the arrayfrom- the first index to dropto- the last index to drop- Returns:
- the new (shorter) array
-
drop
public static <T> T[] drop(T[] array, int index) Drop the element atindexfrom the arrayarrayof typeT. The length of the returned array isarray.length - 1.- Type Parameters:
T- the type of the array- Parameters:
array- the arrayindex- 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 indexfromto indextofrom the arrayarrayof typeT. The length of the returned array isarray.length - (to - from).- Type Parameters:
T- the type of the array- Parameters:
array- the arrayfrom- the first index to dropto- the last index to drop- Returns:
- the new (shorter) array
-
insert
public static boolean[] insert(boolean[] array, boolean element, int index) Insert elementelementof typebooleaninto arrayarrayof the same type atindex. The length of the returned array isarray.length + 1.- Parameters:
array- the arrayelement- the element to insertindex- the insertion point- Returns:
- the new (longer) array
-
insert
public static int[] insert(int[] array, int element, int index) Insert elementelementof typeintinto arrayarrayof the same type atindex. The length of the returned array isarray.length + 1.- Parameters:
array- the arrayelement- the element to insertindex- the insertion point- Returns:
- the new (longer) array
-
insert
public static double[] insert(double[] array, double element, int index) Insert elementelementof typedoubleinto arrayarrayof the same type atindex. The length of the returned array isarray.length + 1.- Parameters:
array- the arrayelement- the element to insertindex- the insertion point- Returns:
- the new (longer) array
-
insert
public static <T> T[] insert(T[] array, T element, int index) Insert elementelementof typeTinto arrayarrayof the same type atindex. The length of the returned array isarray.length + 1.- Type Parameters:
T- the type of the element and the array- Parameters:
array- the arrayelement- the element to insertindex- the insertion point- Returns:
- the new (longer) array
-
compare
public static int compare(int[] a1, int[] a2) Compares the two specifiedint[]arrays. Returns zero if the arrays are identical and1otherwise. In contrast toInteger.compare(int, int)there is no obvious ranking of the two arrays.- Parameters:
a1- the firstint[]array to comparea2- the secondint[]array to compare- Returns:
- the value
0ifa1is numerically equal toa2and1otherwise - See Also:
-
compare
public static int compare(int[][] a1, int[][] a2) Compares the two specifiedint[][]arrays. Returns zero if the arrays are identical and1otherwise. In contrast toInteger.compare(int, int)there is no obvious ranking of the two arrays.- Parameters:
a1- the firstint[][]array to comparea2- the secondint[][]array to compare- Returns:
- the value
0ifa1is numerically equal toa2and1otherwise - See Also:
-
compare
public static int compare(double[] a1, double[] a2) Compares the two specifieddouble[]arrays. Returns zero if the arrays are identical and1otherwise. In contrast toDouble.compare(double, double)there is no obvious ranking of the two arrays.- Parameters:
a1- the firstdouble[]array to comparea2- the seconddouble[]array to compare- Returns:
- the value
0ifd1is numerically equal tod2and1otherwise - See Also:
-
compare
public static int compare(double[][] a1, double[][] a2) Compares the two specifieddouble[][]arrays. Returns zero if the arrays are identical and1otherwise. In contrast toDouble.compare(double, double)there is no obvious ranking of the two arrays.- Parameters:
a1- the firstdouble[][]array to comparea2- the seconddouble[][]array to compare- Returns:
- the value
0ifd1is numerically equal tod2and1otherwise - See Also:
-
first
public static int first(int[] a, int b) Find the first occurence of the elementbin the arrayint[] a.- Parameters:
a- the arrayb- the element to look for- Returns:
- the index of the first occurrence of
bor-1ifadoes not contain any elementb
-
first
public static int first(double[] a, double b) Find the first occurence of the elementbin the arraydouble[] a.- Parameters:
a- the arrayb- the element to look for- Returns:
- the index of the first occurrence of
bor-1ifadoes not contain any elementb
-
last
public static int last(int[] a, int b) Find the last occurence of the elementbin the arrayint[] a.- Parameters:
a- the arrayb- the element to look for- Returns:
- the index of the first occurrence of
bor-1ifadoes not contain any elementb
-
last
public static int last(double[] a, int b) Find the last occurence of the elementbin the arraydouble[] a.- Parameters:
a- the arrayb- the element to look for- Returns:
- the index of the first occurrence of
bor-1ifadoes not contain any elementb
-
min
public static boolean min(boolean[] a) Find minimum element in boolean array/vectora.- Parameters:
a- theboolean[]array- Returns:
trueif all elements aretrueandfalseif at least one element isfalse
-
min
public static int min(int[] a) Find minimum element in integer array/vectora.- Parameters:
a- the arrayint[]- Returns:
- the minimum element
-
min
public static long min(long[] a) Find minimum element in long array/vectora.- Parameters:
a- the arraylong[]- Returns:
- the minimum element
-
min
public static float min(float[] a) Find minimum element in float array/vectora.- Parameters:
a- the arrayfloat[]- Returns:
- the minimum element
-
min
public static double min(double[] a) Find minimum element in double array/vectora.- Parameters:
a- the arraydouble[]- Returns:
- the minimum element
-
min
public static int min(int[][] a) Find minimum element in integer array/matrixa.- Parameters:
a- the arrayint[][]- Returns:
- the minimum element
-
min
public static long min(long[][] a) Find minimum element in long array/matrixa.- Parameters:
a- the arraylong[][]- Returns:
- the minimum element
-
min
public static float min(float[][] a) Find minimum element in float array/matrixa.- Parameters:
a- the arrayfloat[][]- Returns:
- the minimum element
-
min
public static double min(double[][] a) Find minimum element in double array/matrixa.- Parameters:
a- the arraydouble[][]- Returns:
- the minimum element
-
minIndex
public static int minIndex(int[] a) Find index of minimum element in integer array.- Parameters:
a- the arrayint[]- 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 arraylong[]- 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 arrayfloat[]- 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 arraydouble[]- Returns:
- the index of the minimum element
-
min
public static float[] min(float[] a, float[] b) Find minimum element in two float arraysaandb.- Parameters:
a- the first arrayb- the second array- Returns:
- the minimum element in
aandb
-
min
public static double[] min(double[] a, double[] b) Find minimum element in two double arraysaandb.- Parameters:
a- the first arrayb- the second array- Returns:
- the minimum element in
aandb
-
min
public static double min(double[] a, boolean[] active) Find minimum element in double arrayaamongactiveelements. More precisely, disregard elementsa[i]withactive[i]==false.- Parameters:
a- the arraydouble[]active- the arrayboolean[]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/vectora.- Parameters:
a- theboolean[]array- Returns:
falseif all elements arefalseandtrueif at least one element istrue
-
max
public static int max(int[] a) Find maximum element in int array/vectora.- Parameters:
a- the arrayint[]- Returns:
- the maximum element
-
max
public static long max(long[] a) Find maximum element in long array/vectora.- Parameters:
a- the arraylong[]- Returns:
- the maximum element
-
max
public static float max(float[] a) Find maximum element in float array/vectora.- Parameters:
a- the arrayfloat[]- Returns:
- the maximum element
-
max
public static double max(double[] a) Find maximum element in double array/vectora.- Parameters:
a- the arraydouble[]- Returns:
- the maximum element
-
max
public static int max(int[][] a) Find maximum element in int array/matrixa.- Parameters:
a- the arrayint[][]- Returns:
- the maximum element
-
max
public static long max(long[][] a) Find maximum element in long array/matrixa.- Parameters:
a- the arraylong[][]- Returns:
- the maximum element
-
max
public static float max(float[][] a) Find maximum element in float array/matrixa.- Parameters:
a- the arrayfloat[][]- Returns:
- the maximum element
-
max
public static double max(double[][] a) Find maximum element in double array/matrixa.- Parameters:
a- the arraydouble[][]- Returns:
- the maximum element
-
maxIndex
public static int maxIndex(int[] a) Find index of maximum element in integer array.- Parameters:
a- the arrayint[]- Returns:
- the index of maximum element
-
maxIndex
public static int maxIndex(long[] a) Find index of maximum element in long array.- Parameters:
a- the arraylong[]- Returns:
- the index of maximum element
-
maxIndex
public static int maxIndex(float[] a) Find index of maximum element in float array.- Parameters:
a- the arrayfloat[]- Returns:
- the index of maximum element
-
maxIndex
public static int maxIndex(double[] a) Find index of maximum element in double array.- Parameters:
a- the arraydouble[]- Returns:
- the index of maximum element
-
max
public static float[] max(float[] a, float[] b) Find maximum element in two float arraysaandb.- Parameters:
a- the first arrayb- the second array- Returns:
- the maximum element in
aandb
-
max
public static double[] max(double[] a, double[] b) Find maximum element in two double arraysaandb.- Parameters:
a- the first arrayb- the second array- Returns:
- the maximum element in
aandb
-
max
public static double max(double[] a, boolean[] active) Find maximum element in double arrayaamongactiveelements. More precisely, disregard elementsa[i]withactive[i]==false.- Parameters:
a- the arraydouble[]active- the arrayboolean[]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 arraya.- Parameters:
a- the arrayint[]- Returns:
- the sum of all elements
a[i]
-
norm
public static long norm(long[] a) Norm of long arraya.- Parameters:
a- the rraylong[]- Returns:
- the sum of all elements
a[i]
-
norm
public static float norm(float[] a) Norm of float arraya.- Parameters:
a- the arrayfloat[]- Returns:
- the sum of all elements
a[i]
-
norm
public static double norm(double[] a) Norm of double arraya.- Parameters:
a- the arraydouble[]- Returns:
- the sum of all elements
a[i]
-
normalize
public static float[] normalize(float[] a) Normalize float arraya. Scales elements such that the sum over all elementsa[i]adds up to1. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements ofaare overwritten with new values.- Parameters:
a- the arrayfloat[]- Returns:
- the normalized array
a
-
normalize
public static float[] normalize(float[] a, int from, int to) Normalize elements ranging from indexfromto indextoin float arraya. Scales elements such that the sum over elementsa[i]withi=from,...,toadd up to1. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements ofaare overwritten with new values.- Parameters:
a- thefloat[]array to normalizefrom- the start index of the section to normalizeto- the end index of the section to normalize- Returns:
- the array
awith normalized section - See Also:
-
normalize
public static double[] normalize(double[] a) Normalize double arraya. Scales elements such that the sum over all elementsa[i]adds up to1. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements ofaare overwritten with new values.- Parameters:
a- thedouble[]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 indexfromto indextoin double arraya. Scales elements such that the sum over elementsa[i]withi=from,...,toadd up to1. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements ofaare overwritten with new values.- Parameters:
a- thedouble[]array to normalizefrom- the start index of the section to normalizeto- the end index of the section to normalize- Returns:
- the array
awith normalized section - See Also:
-
copy
public static double[] copy(int[] src, double[] dst) Element-wise copy of integer array/vectorsrcto double array/vectordst.- Parameters:
src- theint[]source arraydst- thedouble[]destination array- Returns:
- the array
dst
-
copy
public static int[] copy(int[] src, int[] dst) Copy the integer array/vectorsrctodst.- Parameters:
src- theint[]source vectordst- theint[]destination vector- Returns:
- the matrix
dst
-
copy
public static double[] copy(double[] src, double[] dst) Copy the double 2D array/matrixsrctodst.- Parameters:
src- thedouble[]source matrixdst- thedouble[]destination matrix- Returns:
- the matrix
dst
-
copy
public static int[][] copy(int[][] src, int[][] dst) Copy the integer 2D array/matrixsrctodst.- Parameters:
src- theint[][]source matrixdst- theint[][]destination matrix- Returns:
- the matrix
dst
-
copy
public static double[][] copy(double[][] src, double[][] dst) Copy the double 2D array/matrixsrctodst.- Parameters:
src- thedouble[][]source matrixdst- thedouble[][]destination matrix- Returns:
- the matrix
dst
-
add
public static int[] add(int[] dst, int scalar) Addscalarvalue to each element of integer array/vectordst. Elements ofdstare overwritten with new values.- Parameters:
dst- the arrayint[]scalar- the value to add to each element ofdst- Returns:
- the modified array
dst
-
add
public static long[] add(long[] dst, long scalar) Addscalarvalue to each element of long array/vectordst. Elements ofdstare overwritten with new values.- Parameters:
dst- the arraylong[]scalar- the value to add to each element ofdst- Returns:
- the modified array
dst
-
add
public static float[] add(float[] dst, float scalar) Addscalarvalue to each element of float array/vectordst. Elements ofdstare overwritten with new values.- Parameters:
dst- the arrayfloat[]scalar- the value to add to each element ofdst- Returns:
- the modified array
dst
-
add
public static double[] add(double[] dst, double scalar) Addscalarvalue to each element of double array/vectordst. Elements ofdstare overwritten with new values.- Parameters:
dst- the arraydouble[]scalar- the value to add to each element ofdst- Returns:
- the modified array
dst
-
add
public static int[] add(int[] dst, int[] add) Add integer arraysdstandadd. Place result indst(arrayaddremains unchanged). Arraysdstandaddcan be of different lengths as long asdst.length<add.length. Ifaddis longer, additional elements are ignored.- Parameters:
dst- the destination arrayadd- the array to add todst- Returns:
- the modified array
dst - Throws:
ArrayIndexOutOfBoundsException- ifadd.length<dst.length
-
add
public static long[] add(long[] dst, long[] add) Add long arraysdstandadd. Place result indst(arrayaddremains unchanged). Arraysdstandaddcan be of different lengths as long asdst.length<add.length. Ifaddis longer, additional elements are ignored.- Parameters:
dst- the destination arrayadd- the array to add todst- Returns:
- the modified array
dst - Throws:
ArrayIndexOutOfBoundsException- ifadd.length<dst.length
-
add
public static float[] add(float[] dst, float[] add) Add float arraysdstandadd. Place result indst(arrayaddremains unchanged). Arraysdstandaddcan be of different lengths as long asdst.length<add.length. Ifaddis longer, additional elements are ignored.- Parameters:
dst- the destination arrayadd- the array to add todst- Returns:
- the modified array
dst - Throws:
ArrayIndexOutOfBoundsException- ifadd.length<dst.length
-
add
public static double[] add(double[] dst, double[] add) Add double arraysdstandadd. Place result indst(arrayaddremains unchanged). Arraysdstandaddcan be of different lengths as long asdst.length<add.length. Ifaddis longer, additional elements are ignored.- Parameters:
dst- the destination arrayadd- the array to add todst- Returns:
- the modified array
dst - Throws:
ArrayIndexOutOfBoundsException- ifadd.length<dst.length
-
add
public static int[] add(int[] a, int[] b, int[] dst) Non-destructive array addition. Add int arraysaandband place result indst(arraysaandbremain unchanged). Arraysa,banddstcan be of different lengths as long asa.length≤b.length≤dst.length. Ifbordstis longer thana, additional elements are ignored.- Parameters:
a- the first arrayb- the second arraydst- the result array- Returns:
- the modified array
dst=a+b - Throws:
ArrayIndexOutOfBoundsException- ifdst.length<a.lengthorb.length<a.length
-
add
public static long[] add(long[] a, long[] b, long[] dst) Non-destructive array addition. Add long arraysaandband place result indst(arraysaandbremain unchanged). Arraysa,banddstcan be of different lengths as long asa.length≤b.length≤dst.length. Ifbordstis longer thana, additional elements are ignored.- Parameters:
a- the first arrayb- the second arraydst- the result array- Returns:
- the modified array
dst=a+b - Throws:
ArrayIndexOutOfBoundsException- ifdst.length<a.lengthorb.length<a.length
-
add
public static float[] add(float[] a, float[] b, float[] dst) Non-destructive array addition. Add float arraysaandband place result indst(arraysaandbremain unchanged). Arraysa,banddstcan be of different lengths as long asa.length≤b.length≤dst.length. Ifbordstis longer thana, additional elements are ignored.- Parameters:
a- the first arrayb- the second arraydst- the result array- Returns:
- the modified array
dst=a+b - Throws:
ArrayIndexOutOfBoundsException- ifdst.length<a.lengthorb.length<a.length
-
add
public static double[] add(double[] a, double[] b, double[] dst) Non-destructive array addition. Add double arraysaandband place result indst(arraysaandbremain unchanged). Arraysa,banddstcan be of different lengths as long asa.length≤b.length≤dst.length. Ifbordstis longer thana, additional elements are ignored.- Parameters:
a- the first arrayb- the second arraydst- the result array- Returns:
- the modified array
dst=a+b - Throws:
ArrayIndexOutOfBoundsException- ifdst.length<a.lengthorb.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 arraybby scalar values, add the result to arrayaand store result in arraydst(arraysaandbremain unchanged). Arraysa,banddstcan be of different lengths as long asa.length≤b.length≤dst.length. Ifbordstare longer thana, additional elements are ignored.- Parameters:
a- the first arrayb- the second arrays- the scalar multiplierdst- the result array- Returns:
- the modified array
dst=a+s*b - Throws:
ArrayIndexOutOfBoundsException- ifa.length<dst.lengthorb.length<dst.length
-
sub
public static int[] sub(int[] dst, int[] sub) Subtract integer arraysubfrom arraydst. Place result indst(arraysubremains unchanged). Arraysdstandsubcan be of different lengths as long asdst.length<sub.length. Ifsubis longer, additional elements are ignored.- Parameters:
dst- the destination arraysub- the array to subtract fromdst- Returns:
- the modified array
dst - Throws:
ArrayIndexOutOfBoundsException- ifsub.length<dst.length
-
sub
public static long[] sub(long[] dst, long[] sub) Subtract long arraysubfrom arraydst. Place result indst(arraysubremains unchanged). Arraysdstandsubcan be of different lengths as long asdst.length<sub.length. Ifsubis longer, additional elements are ignored.- Parameters:
dst- the destination arraysub- the array to subtract fromdst- Returns:
- the modified array
dst - Throws:
ArrayIndexOutOfBoundsException- ifsub.length<dst.length
-
sub
public static float[] sub(float[] dst, float[] sub) Subtract float arraysubfrom arraydst. Place result indst(arraysubremains unchanged). Arraysdstandsubcan be of different lengths as long asdst.length<sub.length. Ifsubis longer, additional elements are ignored.- Parameters:
dst- the destination arraysub- the array to subtract fromdst- Returns:
- the modified array
dst - Throws:
ArrayIndexOutOfBoundsException- ifsub.length<dst.length
-
sub
public static double[] sub(double[] dst, double[] sub) Subtract double arraysubfrom arraydst. Place result indst(arraysubremains unchanged). Arraysdstandsubcan be of different lengths as long asdst.length<sub.length. Ifsubis longer, additional elements are ignored.- Parameters:
dst- the destination arraysub- the array to subtract fromdst- Returns:
- the modified array
dst - Throws:
ArrayIndexOutOfBoundsException- ifsub.length<dst.length
-
sub
public static int[] sub(int[] orig, int[] sub, int[] dst) Non-destructive array subtraction. Subtract integer arraysubfrom arrayorigand place result indst(arraysorigandsubremain unchanged). Arraysorig,subanddstcan be of different lengths as long asorig.length≤sub.length≤dst.length. Ifdstorsubare longer, additional elements are ignored.- Parameters:
orig- the first arraysub- the second array to subtract fromorigdst- the result array- Returns:
- the modified array
dst=orig-sub - Throws:
ArrayIndexOutOfBoundsException- ifdst.length<orig.lengthorsub.length<orig.length
-
sub
public static long[] sub(long[] orig, long[] sub, long[] dst) Non-destructive array subtraction. Subtract long arraysubfrom arrayorigand place result indst(arraysorigandsubremain unchanged). Arraysorig,subanddstcan be of different lengths as long asorig.length≤sub.length≤dst.length. Ifdstorsubare longer, additional elements are ignored.- Parameters:
orig- the first arraysub- the second array to subtract fromorigdst- the result array- Returns:
- the modified array
dst=orig-sub - Throws:
ArrayIndexOutOfBoundsException- ifdst.length<orig.lengthorsub.length<orig.length
-
sub
public static float[] sub(float[] orig, float[] sub, float[] dst) Non-destructive array subtraction. Subtract float arraysubfrom arrayorigand place result indst(arraysorigandsubremain unchanged). Arraysorig,subanddstcan be of different lengths as long asorig.length≤sub.length≤dst.length. Ifdstorsubare longer, additional elements are ignored.- Parameters:
orig- the first arraysub- the second array to subtract fromorigdst- the result array- Returns:
- the modified array
dst=orig-sub - Throws:
ArrayIndexOutOfBoundsException- ifdst.length<orig.lengthorsub.length<orig.length
-
sub
public static double[] sub(double[] orig, double[] sub, double[] dst) Non-destructive array subtraction. Subtract double arraysubfrom arrayorigand place result indst(arraysorigandsubremain unchanged). Arraysorig,subanddstcan be of different lengths as long asorig.length≤sub.length≤dst.length. Ifdstorsubare longer, additional elements are ignored.- Parameters:
orig- the first arraysub- the second array to subtract fromorigdst- the result array- Returns:
- the modified array
dst=orig-sub - Throws:
ArrayIndexOutOfBoundsException- ifdst.length<orig.lengthorsub.length<orig.length
-
distSq
public static int distSq(int[] a, int[] b) Squared distance of two integer arraysaandbgiven by the sum over(a[i]-b[i])^2. Arraysaandbare preserved.- Parameters:
a- the first arrayb- the second array- Returns:
- the distance between
aandbsquared
-
distSq
public static double distSq(double[] a, double[] b) Squared distance of two double arraysaandbgiven by the sum over(a[i]-b[i])^2. Arraysaandbare preserved.- Parameters:
a- the first arrayb- the second array- Returns:
- the distance between
aandbsquared
-
dist
public static double dist(int[] a, int[] b) Distance of two integer arraysaandbgiven by the square root of the sum over(a[i]-b[i])^2. Arraysaandbare preserved.- Parameters:
a- the first arrayb- the second array- Returns:
- the distance between
aandb
-
dist
public static double dist(double[] a, double[] b) Distance of two double arraysaandbgiven by the square root of the sum over(a[i]-b[i])^2. Arraysaandbare preserved.- Parameters:
a- the first arrayb- the second array- Returns:
- the distance between
aandb
-
dot
public static int dot(int[] a, int[] b) Dot product of two integer arraysaandbgiven by the sum overa[i]*b[i]. Arraysaandbare preserved.- Parameters:
a- the first arrayb- the second array- Returns:
- the dot product
a.b
-
dot
public static long dot(long[] a, long[] b) Dot product of two long arraysaandbgiven by the sum overa[i]*b[i]. Arraysaandbare preserved.- Parameters:
a- the first arrayb- the second array- Returns:
- the dot product
a.b
-
dot
public static float dot(float[] a, float[] b) Dot product of two float arraysaandbgiven by the sum overa[i]*b[i]. Arraysaandbare preserved.- Parameters:
a- the first arrayb- the second array- Returns:
- the dot product
a.b
-
dot
public static double dot(double[] a, double[] b) Dot product of two double arraysaandbgiven by the sum overa[i]*b[i]. Arraysaandbare preserved.- Parameters:
a- the first arrayb- the second array- Returns:
- the dot product
a.b
-
multiply
public static int[] multiply(int[] dst, int scalar) Scalar multiplication of integer arraydstbyscalar.- Parameters:
dst- the arrayscalar- the multiplier- Returns:
- the modified array
dst
-
multiply
public static long[] multiply(long[] dst, long scalar) Scalar multiplication of long arraydstbyscalar.- Parameters:
dst- the arrayscalar- the multiplier- Returns:
- the modified array
dst
-
multiply
public static float[] multiply(float[] dst, float scalar) Scalar multiplication of float arraydstbyscalar.- Parameters:
dst- the arrayscalar- the multiplier- Returns:
- the modified array
dst
-
multiply
public static double[] multiply(double[] dst, double scalar) Scalar multiplication of double arraydstbyscalar.- Parameters:
dst- the arrayscalar- the multiplier- Returns:
- the modified array
dst
-
multiply
public static int[] multiply(int[] a, int scalar, int[] dst) Scalar multiplication of integer arrayabyscalarwith result indst.- Parameters:
a- the array ofint'sscalar- the multiplierdst- the destination array- Returns:
- the modified array
dst
-
multiply
public static long[] multiply(long[] a, long scalar, long[] dst) Scalar multiplication of long arrayabyscalarwith result indst.- Parameters:
a- the array oflong'sscalar- the multiplierdst- the destination array- Returns:
- the modified array
dst
-
multiply
public static float[] multiply(float[] a, float scalar, float[] dst) Scalar multiplication of float arrayabyscalarwith result indst.- Parameters:
a- the array offloat'sscalar- the multiplierdst- the destination array- Returns:
- the modified array
dst
-
multiply
public static double[] multiply(double[] a, double scalar, double[] dst) Scalar multiplication of double arrayabyscalarwith result indst.- Parameters:
a- the array ofdouble'sscalar- the multiplierdst- the destination array- Returns:
- the modified array
dst
-
multiply
public static int[] multiply(int[] dst, int[] a) Element-wise multiplication of integer arraysaanddst. The result is placed indst(arrayais preserved).- Parameters:
dst- the first arraya- the second array- Returns:
- the modified array
dst
-
multiply
public static long[] multiply(long[] dst, long[] a) Element-wise multiplication of long arraysaanddst. The result is placed indst(arrayais preserved).- Parameters:
dst- the first arraya- the second array- Returns:
- the modified array
dst
-
multiply
public static float[] multiply(float[] dst, float[] a) Element-wise multiplication of float arraysaanddst. The result is placed indst(arrayais preserved).- Parameters:
dst- the first arraya- the second array- Returns:
- the modified array
dst
-
multiply
public static double[] multiply(double[] dst, double[] a) Element-wise multiplication of double arrayaanddst. The result is placed indst(arrayais preserved).- Parameters:
dst- the first arraya- 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 arrayaandb. The result is placed indst(arrayaandbare preserved).- Parameters:
a- the first arrayb- the second arraydst- 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 arraysaandb. The result is placed indst(arraysaandbare preserved).- Parameters:
a- the first arrayb- the second arraydst- 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 arraysaandb. The result is placed indst(arraysaandbare preserved).- Parameters:
a- the first arrayb- the second arraydst- 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 arraysaandb. The result is placed indst(arraysaandbare preserved).- Parameters:
a- the first arrayb- the second arraydst- 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. Matrixmatmultiplied by arrayvecand the result stored indst(right multiplication). Matrixmatand arrayvecpreserved.- Parameters:
mat- the matrixvec- the arraydst- 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. Matrixmatmultiplied by arrayvecand the result stored indst(right multiplication). Matrixmatand arrayvecpreserved.- Parameters:
mat- the matrixvec- the arraydst- 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. Matrixmatmultiplied by arrayvecand the result stored indst(right multiplication). Matrixmatand arrayvecpreserved.- Parameters:
mat- the matrixvec- the arraydst- 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. Matrixmatmultiplied by arrayvecand the result stored indst(right multiplication). Matrixmatand arrayvecpreserved.- Parameters:
mat- the matrixvec- the arraydst- the result array- Returns:
- the modified array
dst=mat * vec
-
abs
public static int[] abs(int[] a) Element-wise absolute value of int arraya.- 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 arraya.- 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 arraya.- 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 arraya(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 arraya(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 arraya.- 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 arraya.- 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.
-