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
ConstructorsModifierConstructorDescriptionprivate
Ensure 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) Addscalar
value to each element of double array/vectordst
.static double[]
add
(double[] dst, double[] add) Add double arraysdst
andadd
.static double[]
add
(double[] a, double[] b, double[] dst) Non-destructive array addition.static float[]
add
(float[] dst, float scalar) Addscalar
value to each element of float array/vectordst
.static float[]
add
(float[] dst, float[] add) Add float arraysdst
andadd
.static float[]
add
(float[] a, float[] b, float[] dst) Non-destructive array addition.static int[]
add
(int[] dst, int scalar) Addscalar
value to each element of integer array/vectordst
.static int[]
add
(int[] dst, int[] add) Add integer arraysdst
andadd
.static int[]
add
(int[] a, int[] b, int[] dst) Non-destructive array addition.static long[]
add
(long[] dst, long scalar) Addscalar
value to each element of long array/vectordst
.static long[]
add
(long[] dst, long[] add) Add long arraysdst
andadd
.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) Appendelement
toboolean
arrayarray
.static double[]
append
(double[] array, double element) Appendelement
todouble
arrayarray
.static int[]
append
(int[] array, int element) Appendelement
toint
arrayarray
.static <T> T[]
append
(T[] array, T element) Appendelement
of typeT
to arrayarray
of the same type.static boolean[]
clone
(boolean[] orig) GWT has an aversion to clone()ing - provide alternatives.static double[]
clone
(double[] orig) GWT has an aversion to clone()ing - provide alternatives.static double[][]
clone
(double[][] orig) GWT has an aversion to clone()ing - provide alternatives.static int[]
clone
(int[] orig) GWT has an aversion to clone()ing - provide alternatives.static int
compare
(double[][] a1, double[][] a2) Compares the two specifieddouble[][]
arrays.static int
compare
(double[] a1, double[] a2) Compares the two specifieddouble[]
arrays.static int
compare
(int[][] a1, int[][] a2) Compares the two specifiedint[][]
arrays.static int
compare
(int[] a1, int[] a2) Compares the two specifiedint[]
arrays.static double[][]
copy
(double[][] src, double[][] dst) Copy the double 2D array/matrixsrc
todst
.static double[]
copy
(double[] src, double[] dst) Copy the double 2D array/matrixsrc
todst
.static int[][]
copy
(int[][] src, int[][] dst) Copy the integer 2D array/matrixsrc
todst
.static double[]
copy
(int[] src, double[] dst) Element-wise copy of integer array/vectorsrc
to double array/vectordst
.static int[]
copy
(int[] src, int[] dst) Copy the integer array/vectorsrc
todst
.static double
dist
(double[] a, double[] b) Distance of two double arraysa
andb
given by the square root of the sum over(a[i]-b[i])^2
.static double
dist
(int[] a, int[] b) Distance of two integer arraysa
andb
given by the square root of the sum over(a[i]-b[i])^2
.static double
distSq
(double[] a, double[] b) Squared distance of two double arraysa
andb
given by the sum over(a[i]-b[i])^2
.static int
distSq
(int[] a, int[] b) Squared distance of two integer arraysa
andb
given by the sum over(a[i]-b[i])^2
.static double
dot
(double[] a, double[] b) Dot product of two double arraysa
andb
given by the sum overa[i]*b[i]
.static float
dot
(float[] a, float[] b) Dot product of two float arraysa
andb
given by the sum overa[i]*b[i]
.static int
dot
(int[] a, int[] b) Dot product of two integer arraysa
andb
given by the sum overa[i]*b[i]
.static long
dot
(long[] a, long[] b) Dot product of two long arraysa
andb
given by the sum overa[i]*b[i]
.static boolean[]
drop
(boolean[] array, int index) Drop the element atindex
from the arrayarray
of typeboolean[]
.static boolean[]
drop
(boolean[] array, int from, int to) Drop a range of elements starting with indexfrom
to indexto
from theboolean[]
arrayarray
.static double[]
drop
(double[] array, int index) Drop the element atindex
from the arrayarray
of typedouble[]
.static double[]
drop
(double[] array, int from, int to) Drop a range of elements starting with indexfrom
to indexto
from thedouble[]
arrayarray
.static int[]
drop
(int[] array, int index) Drop the element atindex
from the arrayarray
of typeint[]
.static int[]
drop
(int[] array, int from, int to) Drop a range of elements starting with indexfrom
to indexto
from theint[]
arrayarray
.static <T> T[]
drop
(T[] array, int index) Drop the element atindex
from the arrayarray
of typeT
.static <T> T[]
drop
(T[] array, int from, int to) Drop a range of elements starting with indexfrom
to indexto
from the arrayarray
of typeT
.static int
first
(double[] a, double b) Find the first occurence of the elementb
in the arraydouble[] a
.static int
first
(int[] a, int b) Find the first occurence of the elementb
in the arrayint[] a
.static boolean[]
insert
(boolean[] array, boolean element, int index) Insert elementelement
of typeboolean
into arrayarray
of the same type atindex
.static double[]
insert
(double[] array, double element, int index) Insert elementelement
of typedouble
into arrayarray
of the same type atindex
.static int[]
insert
(int[] array, int element, int index) Insert elementelement
of typeint
into arrayarray
of the same type atindex
.static <T> T[]
insert
(T[] array, T element, int index) Insert elementelement
of typeT
into arrayarray
of the same type atindex
.static int
last
(double[] a, int b) Find the last occurence of the elementb
in the arraydouble[] a
.static int
last
(int[] a, int b) Find the last occurence of the elementb
in 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 boolean
max
(boolean[] a) Find maximum element in boolean array/vectora
.static double
max
(double[] a) Find maximum element in double array/vectora
.static double
max
(double[][] a) Find maximum element in double array/matrixa
.static double
max
(double[] a, boolean[] active) Find maximum element in double arraya
amongactive
elements.static double[]
max
(double[] a, double[] b) Find maximum element in two double arraysa
andb
.static float
max
(float[] a) Find maximum element in float array/vectora
.static float
max
(float[][] a) Find maximum element in float array/matrixa
.static float[]
max
(float[] a, float[] b) Find maximum element in two float arraysa
andb
.static int
max
(int[] a) Find maximum element in int array/vectora
.static int
max
(int[][] a) Find maximum element in int array/matrixa
.static long
max
(long[] a) Find maximum element in long array/vectora
.static long
max
(long[][] a) Find maximum element in long array/matrixa
.static int
maxIndex
(double[] a) Find index of maximum element in double array.static int
maxIndex
(float[] a) Find index of maximum element in float array.static int
maxIndex
(int[] a) Find index of maximum element in integer array.static int
maxIndex
(long[] a) Find index of maximum element in long array.static double[]
merge
(double[] head, double[] tail) Appenddouble
arraytail
todouble
arrayhead
.static <T> T[]
merge
(T[] head, T[] tail) Append arraytail
of typeT[]
to arrayhead
.static boolean
min
(boolean[] a) Find minimum element in boolean array/vectora
.static double
min
(double[] a) Find minimum element in double array/vectora
.static double
min
(double[][] a) Find minimum element in double array/matrixa
.static double
min
(double[] a, boolean[] active) Find minimum element in double arraya
amongactive
elements.static double[]
min
(double[] a, double[] b) Find minimum element in two double arraysa
andb
.static float
min
(float[] a) Find minimum element in float array/vectora
.static float
min
(float[][] a) Find minimum element in float array/matrixa
.static float[]
min
(float[] a, float[] b) Find minimum element in two float arraysa
andb
.static int
min
(int[] a) Find minimum element in integer array/vectora
.static int
min
(int[][] a) Find minimum element in integer array/matrixa
.static long
min
(long[] a) Find minimum element in long array/vectora
.static long
min
(long[][] a) Find minimum element in long array/matrixa
.static int
minIndex
(double[] a) Find index of minimum element in double array.static int
minIndex
(float[] a) Find index of minimum element in float array.static int
minIndex
(int[] a) Find index of minimum element in integer array.static int
minIndex
(long[] a) Find index of minimum element in long array.static double[]
multiply
(double[][] mat, double[] vec, double[] dst) Non-destructive double matrix multiplication.static double[]
multiply
(double[] dst, double scalar) Scalar multiplication of double arraydst
byscalar
.static double[]
multiply
(double[] dst, double[] a) Element-wise multiplication of double arraya
anddst
.static double[]
multiply
(double[] a, double[] b, double[] dst) Non-destructive, element-wise multiplication of double arraysa
andb
.static double[]
multiply
(double[] a, double scalar, double[] dst) Scalar multiplication of double arraya
byscalar
with 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 arraydst
byscalar
.static float[]
multiply
(float[] dst, float[] a) Element-wise multiplication of float arraysa
anddst
.static float[]
multiply
(float[] a, float[] b, float[] dst) Non-destructive, element-wise multiplication of float arraysa
andb
.static float[]
multiply
(float[] a, float scalar, float[] dst) Scalar multiplication of float arraya
byscalar
with 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 arraydst
byscalar
.static int[]
multiply
(int[] dst, int[] a) Element-wise multiplication of integer arraysa
anddst
.static int[]
multiply
(int[] a, int[] b, int[] dst) Non-destructive, element-wise multiplication of integer arraya
andb
.static int[]
multiply
(int[] a, int scalar, int[] dst) Scalar multiplication of integer arraya
byscalar
with 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 arraydst
byscalar
.static long[]
multiply
(long[] dst, long[] a) Element-wise multiplication of long arraysa
anddst
.static long[]
multiply
(long[] a, long[] b, long[] dst) Non-destructive, element-wise multiplication of long arraysa
andb
.static long[]
multiply
(long[] a, long scalar, long[] dst) Scalar multiplication of long arraya
byscalar
with result indst
.static double
norm
(double[] a) Norm of double arraya
.static float
norm
(float[] a) Norm of float arraya
.static int
norm
(int[] a) Norm of integer arraya
.static long
norm
(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 indexfrom
to indexto
in double arraya
.static float[]
normalize
(float[] a) Normalize float arraya
.static float[]
normalize
(float[] a, int from, int to) Normalize elements ranging from indexfrom
to indexto
in 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 arraysub
from arraydst
.static double[]
sub
(double[] orig, double[] sub, double[] dst) Non-destructive array subtraction.static float[]
sub
(float[] dst, float[] sub) Subtract float arraysub
from arraydst
.static float[]
sub
(float[] orig, float[] sub, float[] dst) Non-destructive array subtraction.static int[]
sub
(int[] dst, int[] sub) Subtract integer arraysub
from arraydst
.static int[]
sub
(int[] orig, int[] sub, int[] dst) Non-destructive array subtraction.static long[]
sub
(long[] dst, long[] sub) Subtract long arraysub
from 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) Appendelement
toboolean
arrayarray
. The length of the returned array isarray.length + 1
. The arrayarray
remains unchanged.- Parameters:
array
- the arrayelement
- the element to append- Returns:
- the new (longer) array
-
append
public static int[] append(int[] array, int element) Appendelement
toint
arrayarray
. The length of the returned array isarray.length + 1
. The arrayarray
remains unchanged.- Parameters:
array
- the arrayelement
- the element to append- Returns:
- the new (longer) array
-
append
public static double[] append(double[] array, double element) Appendelement
todouble
arrayarray
. The length of the returned array isarray.length + 1
. The arrayarray
remains unchanged.- Parameters:
array
- the arrayelement
- the element to append- Returns:
- the new (longer) array
-
append
public static <T> T[] append(T[] array, T element) Appendelement
of typeT
to arrayarray
of the same type. The length of the returned array isarray.length + 1
. The arrayarray
remains 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) Appenddouble
arraytail
todouble
arrayhead
. The length of the returned array ishead.length + tail.length
. The arrayshead
andtail
remain 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 arraytail
of typeT[]
to arrayhead
. The length of the returned array ishead.length + tail.length
. The arrayshead
andtail
remain 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 atindex
from the arrayarray
of 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 indexfrom
to indexto
from 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 atindex
from the arrayarray
of 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 indexfrom
to indexto
from 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 atindex
from the arrayarray
of 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 indexfrom
to indexto
from 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 atindex
from the arrayarray
of 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 indexfrom
to indexto
from the arrayarray
of 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 elementelement
of typeboolean
into arrayarray
of 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 elementelement
of typeint
into arrayarray
of 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 elementelement
of typedouble
into arrayarray
of 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 elementelement
of typeT
into arrayarray
of 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 and1
otherwise. 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
0
ifa1
is numerically equal toa2
and1
otherwise - See Also:
-
compare
public static int compare(int[][] a1, int[][] a2) Compares the two specifiedint[][]
arrays. Returns zero if the arrays are identical and1
otherwise. 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
0
ifa1
is numerically equal toa2
and1
otherwise - See Also:
-
compare
public static int compare(double[] a1, double[] a2) Compares the two specifieddouble[]
arrays. Returns zero if the arrays are identical and1
otherwise. 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
0
ifd1
is numerically equal tod2
and1
otherwise - See Also:
-
compare
public static int compare(double[][] a1, double[][] a2) Compares the two specifieddouble[][]
arrays. Returns zero if the arrays are identical and1
otherwise. 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
0
ifd1
is numerically equal tod2
and1
otherwise - See Also:
-
first
public static int first(int[] a, int b) Find the first occurence of the elementb
in the arrayint[] a
.- Parameters:
a
- the arrayb
- the element to look for- Returns:
- the index of the first occurrence of
b
or-1
ifa
does not contain any elementb
-
first
public static int first(double[] a, double b) Find the first occurence of the elementb
in the arraydouble[] a
.- Parameters:
a
- the arrayb
- the element to look for- Returns:
- the index of the first occurrence of
b
or-1
ifa
does not contain any elementb
-
last
public static int last(int[] a, int b) Find the last occurence of the elementb
in the arrayint[] a
.- Parameters:
a
- the arrayb
- the element to look for- Returns:
- the index of the first occurrence of
b
or-1
ifa
does not contain any elementb
-
last
public static int last(double[] a, int b) Find the last occurence of the elementb
in the arraydouble[] a
.- Parameters:
a
- the arrayb
- the element to look for- Returns:
- the index of the first occurrence of
b
or-1
ifa
does not contain any elementb
-
min
public static boolean min(boolean[] a) Find minimum element in boolean array/vectora
.- Parameters:
a
- theboolean[]
array- Returns:
true
if all elements aretrue
andfalse
if 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 arraysa
andb
.- Parameters:
a
- the first arrayb
- the second array- Returns:
- the minimum element in
a
andb
-
min
public static double[] min(double[] a, double[] b) Find minimum element in two double arraysa
andb
.- Parameters:
a
- the first arrayb
- the second array- Returns:
- the minimum element in
a
andb
-
min
public static double min(double[] a, boolean[] active) Find minimum element in double arraya
amongactive
elements. 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:
false
if all elements arefalse
andtrue
if 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 arraysa
andb
.- Parameters:
a
- the first arrayb
- the second array- Returns:
- the maximum element in
a
andb
-
max
public static double[] max(double[] a, double[] b) Find maximum element in two double arraysa
andb
.- Parameters:
a
- the first arrayb
- the second array- Returns:
- the maximum element in
a
andb
-
max
public static double max(double[] a, boolean[] active) Find maximum element in double arraya
amongactive
elements. 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 ofa
are 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 indexfrom
to indexto
in float arraya
. Scales elements such that the sum over elementsa[i]
withi=from,...,to
add up to1
. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements ofa
are 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
a
with 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 ofa
are 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 indexfrom
to indexto
in double arraya
. Scales elements such that the sum over elementsa[i]
withi=from,...,to
add up to1
. Normalization usually only makes sense if the sign of all elements is the same but this is not checked. Elements ofa
are 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
a
with normalized section - See Also:
-
copy
public static double[] copy(int[] src, double[] dst) Element-wise copy of integer array/vectorsrc
to 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/vectorsrc
todst
.- 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/matrixsrc
todst
.- 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/matrixsrc
todst
.- 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/matrixsrc
todst
.- Parameters:
src
- thedouble[][]
source matrixdst
- thedouble[][]
destination matrix- Returns:
- the matrix
dst
-
add
public static int[] add(int[] dst, int scalar) Addscalar
value to each element of integer array/vectordst
. Elements ofdst
are 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) Addscalar
value to each element of long array/vectordst
. Elements ofdst
are 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) Addscalar
value to each element of float array/vectordst
. Elements ofdst
are 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) Addscalar
value to each element of double array/vectordst
. Elements ofdst
are 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 arraysdst
andadd
. Place result indst
(arrayadd
remains unchanged). Arraysdst
andadd
can be of different lengths as long asdst.length<add.length
. Ifadd
is 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 arraysdst
andadd
. Place result indst
(arrayadd
remains unchanged). Arraysdst
andadd
can be of different lengths as long asdst.length<add.length
. Ifadd
is 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 arraysdst
andadd
. Place result indst
(arrayadd
remains unchanged). Arraysdst
andadd
can be of different lengths as long asdst.length<add.length
. Ifadd
is 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 arraysdst
andadd
. Place result indst
(arrayadd
remains unchanged). Arraysdst
andadd
can be of different lengths as long asdst.length<add.length
. Ifadd
is 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 arraysa
andb
and place result indst
(arraysa
andb
remain unchanged). Arraysa
,b
anddst
can be of different lengths as long asa.length≤b.length≤dst.length
. Ifb
ordst
is 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.length
orb.length<a.length
-
add
public static long[] add(long[] a, long[] b, long[] dst) Non-destructive array addition. Add long arraysa
andb
and place result indst
(arraysa
andb
remain unchanged). Arraysa
,b
anddst
can be of different lengths as long asa.length≤b.length≤dst.length
. Ifb
ordst
is 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.length
orb.length<a.length
-
add
public static float[] add(float[] a, float[] b, float[] dst) Non-destructive array addition. Add float arraysa
andb
and place result indst
(arraysa
andb
remain unchanged). Arraysa
,b
anddst
can be of different lengths as long asa.length≤b.length≤dst.length
. Ifb
ordst
is 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.length
orb.length<a.length
-
add
public static double[] add(double[] a, double[] b, double[] dst) Non-destructive array addition. Add double arraysa
andb
and place result indst
(arraysa
andb
remain unchanged). Arraysa
,b
anddst
can be of different lengths as long asa.length≤b.length≤dst.length
. Ifb
ordst
is 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.length
orb.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 arrayb
by scalar values
, add the result to arraya
and store result in arraydst
(arraysa
andb
remain unchanged). Arraysa
,b
anddst
can be of different lengths as long asa.length≤b.length≤dst.length
. Ifb
ordst
are 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.length
orb.length<dst.length
-
sub
public static int[] sub(int[] dst, int[] sub) Subtract integer arraysub
from arraydst
. Place result indst
(arraysub
remains unchanged). Arraysdst
andsub
can be of different lengths as long asdst.length<sub.length
. Ifsub
is 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 arraysub
from arraydst
. Place result indst
(arraysub
remains unchanged). Arraysdst
andsub
can be of different lengths as long asdst.length<sub.length
. Ifsub
is 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 arraysub
from arraydst
. Place result indst
(arraysub
remains unchanged). Arraysdst
andsub
can be of different lengths as long asdst.length<sub.length
. Ifsub
is 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 arraysub
from arraydst
. Place result indst
(arraysub
remains unchanged). Arraysdst
andsub
can be of different lengths as long asdst.length<sub.length
. Ifsub
is 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 arraysub
from arrayorig
and place result indst
(arraysorig
andsub
remain unchanged). Arraysorig
,sub
anddst
can be of different lengths as long asorig.length≤sub.length≤dst.length
. Ifdst
orsub
are longer, additional elements are ignored.- Parameters:
orig
- the first arraysub
- the second array to subtract fromorig
dst
- the result array- Returns:
- the modified array
dst=orig-sub
- Throws:
ArrayIndexOutOfBoundsException
- ifdst.length<orig.length
orsub.length<orig.length
-
sub
public static long[] sub(long[] orig, long[] sub, long[] dst) Non-destructive array subtraction. Subtract long arraysub
from arrayorig
and place result indst
(arraysorig
andsub
remain unchanged). Arraysorig
,sub
anddst
can be of different lengths as long asorig.length≤sub.length≤dst.length
. Ifdst
orsub
are longer, additional elements are ignored.- Parameters:
orig
- the first arraysub
- the second array to subtract fromorig
dst
- the result array- Returns:
- the modified array
dst=orig-sub
- Throws:
ArrayIndexOutOfBoundsException
- ifdst.length<orig.length
orsub.length<orig.length
-
sub
public static float[] sub(float[] orig, float[] sub, float[] dst) Non-destructive array subtraction. Subtract float arraysub
from arrayorig
and place result indst
(arraysorig
andsub
remain unchanged). Arraysorig
,sub
anddst
can be of different lengths as long asorig.length≤sub.length≤dst.length
. Ifdst
orsub
are longer, additional elements are ignored.- Parameters:
orig
- the first arraysub
- the second array to subtract fromorig
dst
- the result array- Returns:
- the modified array
dst=orig-sub
- Throws:
ArrayIndexOutOfBoundsException
- ifdst.length<orig.length
orsub.length<orig.length
-
sub
public static double[] sub(double[] orig, double[] sub, double[] dst) Non-destructive array subtraction. Subtract double arraysub
from arrayorig
and place result indst
(arraysorig
andsub
remain unchanged). Arraysorig
,sub
anddst
can be of different lengths as long asorig.length≤sub.length≤dst.length
. Ifdst
orsub
are longer, additional elements are ignored.- Parameters:
orig
- the first arraysub
- the second array to subtract fromorig
dst
- the result array- Returns:
- the modified array
dst=orig-sub
- Throws:
ArrayIndexOutOfBoundsException
- ifdst.length<orig.length
orsub.length<orig.length
-
distSq
public static int distSq(int[] a, int[] b) Squared distance of two integer arraysa
andb
given by the sum over(a[i]-b[i])^2
. Arraysa
andb
are preserved.- Parameters:
a
- the first arrayb
- the second array- Returns:
- the distance between
a
andb
squared
-
distSq
public static double distSq(double[] a, double[] b) Squared distance of two double arraysa
andb
given by the sum over(a[i]-b[i])^2
. Arraysa
andb
are preserved.- Parameters:
a
- the first arrayb
- the second array- Returns:
- the distance between
a
andb
squared
-
dist
public static double dist(int[] a, int[] b) Distance of two integer arraysa
andb
given by the square root of the sum over(a[i]-b[i])^2
. Arraysa
andb
are preserved.- Parameters:
a
- the first arrayb
- the second array- Returns:
- the distance between
a
andb
-
dist
public static double dist(double[] a, double[] b) Distance of two double arraysa
andb
given by the square root of the sum over(a[i]-b[i])^2
. Arraysa
andb
are preserved.- Parameters:
a
- the first arrayb
- the second array- Returns:
- the distance between
a
andb
-
dot
public static int dot(int[] a, int[] b) Dot product of two integer arraysa
andb
given by the sum overa[i]*b[i]
. Arraysa
andb
are 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 arraysa
andb
given by the sum overa[i]*b[i]
. Arraysa
andb
are 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 arraysa
andb
given by the sum overa[i]*b[i]
. Arraysa
andb
are 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 arraysa
andb
given by the sum overa[i]*b[i]
. Arraysa
andb
are 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 arraydst
byscalar
.- Parameters:
dst
- the arrayscalar
- the multiplier- Returns:
- the modified array
dst
-
multiply
public static long[] multiply(long[] dst, long scalar) Scalar multiplication of long arraydst
byscalar
.- Parameters:
dst
- the arrayscalar
- the multiplier- Returns:
- the modified array
dst
-
multiply
public static float[] multiply(float[] dst, float scalar) Scalar multiplication of float arraydst
byscalar
.- Parameters:
dst
- the arrayscalar
- the multiplier- Returns:
- the modified array
dst
-
multiply
public static double[] multiply(double[] dst, double scalar) Scalar multiplication of double arraydst
byscalar
.- 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 arraya
byscalar
with 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 arraya
byscalar
with 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 arraya
byscalar
with 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 arraya
byscalar
with 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 arraysa
anddst
. The result is placed indst
(arraya
is 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 arraysa
anddst
. The result is placed indst
(arraya
is 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 arraysa
anddst
. The result is placed indst
(arraya
is 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 arraya
anddst
. The result is placed indst
(arraya
is 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 arraya
andb
. The result is placed indst
(arraya
andb
are 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 arraysa
andb
. The result is placed indst
(arraysa
andb
are 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 arraysa
andb
. The result is placed indst
(arraysa
andb
are 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 arraysa
andb
. The result is placed indst
(arraysa
andb
are 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. Matrixmat
multiplied by arrayvec
and the result stored indst
(right multiplication). Matrixmat
and arrayvec
preserved.- 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. Matrixmat
multiplied by arrayvec
and the result stored indst
(right multiplication). Matrixmat
and arrayvec
preserved.- 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. Matrixmat
multiplied by arrayvec
and the result stored indst
(right multiplication). Matrixmat
and arrayvec
preserved.- 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. Matrixmat
multiplied by arrayvec
and the result stored indst
(right multiplication). Matrixmat
and arrayvec
preserved.- 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
.
-