public class MathArrays extends Object
Modifier and Type | Class and Description |
---|---|
static class |
MathArrays.OrderDirection
Specification of ordering direction.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkOrder(double[] val)
Check that the given array is sorted in strictly increasing order.
|
static void |
checkOrder(double[] val,
MathArrays.OrderDirection dir,
boolean strict)
Check that the given array is sorted.
|
static boolean |
checkOrder(double[] val,
MathArrays.OrderDirection dir,
boolean strict,
boolean abort)
Check that the given array is sorted.
|
static double[] |
copyOf(double[] source)
Creates a copy of the
source array. |
static double[] |
copyOf(double[] source,
int len)
Creates a copy of the
source array. |
static int[] |
copyOf(int[] source)
Creates a copy of the
source array. |
static int[] |
copyOf(int[] source,
int len)
Creates a copy of the
source array. |
static double |
distance(double[] p1,
double[] p2)
Calculates the L2 (Euclidean) distance between two points.
|
static double |
distance(int[] p1,
int[] p2)
Calculates the L2 (Euclidean) distance between two points.
|
static double |
distance1(double[] p1,
double[] p2)
Calculates the L1 (sum of abs) distance between two points.
|
static int |
distance1(int[] p1,
int[] p2)
Calculates the L1 (sum of abs) distance between two points.
|
static double |
distanceInf(double[] p1,
double[] p2)
Calculates the L∞ (max of abs) distance between two points.
|
static int |
distanceInf(int[] p1,
int[] p2)
Calculates the L∞ (max of abs) distance between two points.
|
static boolean |
equals(double[] x,
double[] y)
Returns
true iff both arguments are null or have same
dimensions and all their elements are equal as defined by
Precision.equals(double,double) . |
static boolean |
equals(float[] x,
float[] y)
Returns true iff both arguments are null or have same dimensions and all
their elements are equal as defined by
Precision.equals(float,float) . |
static boolean |
equalsIncludingNaN(double[] x,
double[] y)
Returns
true iff both arguments are null or have same
dimensions and all their elements are equal as defined by
this method . |
static boolean |
equalsIncludingNaN(float[] x,
float[] y)
Returns true iff both arguments are null or have same dimensions and all
their elements are equal as defined by
this method . |
static boolean |
isMonotonic(Comparable[] val,
MathArrays.OrderDirection dir,
boolean strict)
Check that an array is monotonically increasing or decreasing.
|
static boolean |
isMonotonic(double[] val,
MathArrays.OrderDirection dir,
boolean strict)
Check that an array is monotonically increasing or decreasing.
|
static double |
linearCombination(double[] a,
double[] b)
Compute a linear combination accurately.
|
static double |
linearCombination(double a1,
double b1,
double a2,
double b2)
Compute a linear combination accurately.
|
static double |
linearCombination(double a1,
double b1,
double a2,
double b2,
double a3,
double b3)
Compute a linear combination accurately.
|
static double |
linearCombination(double a1,
double b1,
double a2,
double b2,
double a3,
double b3,
double a4,
double b4)
Compute a linear combination accurately.
|
static double[] |
normalizeArray(double[] values,
double normalizedSum)
Normalizes an array to make it sum to a specified value.
|
static double |
safeNorm(double[] v)
Returns the Cartesian norm (2-norm), handling both overflow and underflow.
|
static void |
sortInPlace(double[] x,
double[]... yList)
Sort an array in ascending order in place and perform the same reordering
of entries on other arrays.
|
static void |
sortInPlace(double[] x,
MathArrays.OrderDirection dir,
double[]... yList)
Sort an array in place and perform the same reordering of entries on
other arrays.
|
public static double distance1(double[] p1, double[] p2)
p1
- the first pointp2
- the second pointpublic static int distance1(int[] p1, int[] p2)
p1
- the first pointp2
- the second pointpublic static double distance(double[] p1, double[] p2)
p1
- the first pointp2
- the second pointpublic static double distance(int[] p1, int[] p2)
p1
- the first pointp2
- the second pointpublic static double distanceInf(double[] p1, double[] p2)
p1
- the first pointp2
- the second pointpublic static int distanceInf(int[] p1, int[] p2)
p1
- the first pointp2
- the second pointpublic static boolean isMonotonic(Comparable[] val, MathArrays.OrderDirection dir, boolean strict)
val
- Values.dir
- Ordering direction.strict
- Whether the order should be strict.true
if sorted, false
otherwise.public static boolean isMonotonic(double[] val, MathArrays.OrderDirection dir, boolean strict)
val
- Values.dir
- Ordering direction.strict
- Whether the order should be strict.true
if sorted, false
otherwise.public static boolean checkOrder(double[] val, MathArrays.OrderDirection dir, boolean strict, boolean abort)
val
- Values.dir
- Ordering direction.strict
- Whether the order should be strict.abort
- Whether to throw an exception if the check fails.true
if the array is sorted.NonMonotonicSequenceException
- if the array is not sorted
and abort
is true
.public static void checkOrder(double[] val, MathArrays.OrderDirection dir, boolean strict)
val
- Values.dir
- Ordering direction.strict
- Whether the order should be strict.NonMonotonicSequenceException
- if the array is not sorted.public static void checkOrder(double[] val)
val
- Values.NonMonotonicSequenceException
- if the array is not sorted.public static double safeNorm(double[] v)
Minpack Copyright Notice (1999) University of Chicago. All rights reserved |
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
|
v
- Vector of doubles.public static void sortInPlace(double[] x, double[]... yList)
x = [3, 1, 2], y = [1, 2, 3]
and z = [0, 5, 7]
, then
sortInPlace(x, y, z)
will update x
to [1, 2, 3]
,
y
to [2, 3, 1]
and z
to [5, 7, 0]
.x
- Array to be sorted and used as a pattern for permutation
of the other arrays.yList
- Set of arrays whose permutations of entries will follow
those performed on x
.DimensionMismatchException
- if any y
is not the same
size as x
.NullArgumentException
- if x
or any y
is null.public static void sortInPlace(double[] x, MathArrays.OrderDirection dir, double[]... yList)
sortInPlace
method, but
allows the order of the sort to be provided in the dir
parameter.x
- Array to be sorted and used as a pattern for permutation
of the other arrays.dir
- Order direction.yList
- Set of arrays whose permutations of entries will follow
those performed on x
.DimensionMismatchException
- if any y
is not the same
size as x
.NullArgumentException
- if x
or any y
is nullpublic static int[] copyOf(int[] source)
source
array.source
- Array to be copied.public static double[] copyOf(double[] source)
source
array.source
- Array to be copied.public static int[] copyOf(int[] source, int len)
source
array.source
- Array to be copied.len
- Number of entries to copy. If smaller then the source
length, the copy will be truncated, if larger it will padded with
zeroes.public static double[] copyOf(double[] source, int len)
source
array.source
- Array to be copied.len
- Number of entries to copy. If smaller then the source
length, the copy will be truncated, if larger it will padded with
zeroes.public static double linearCombination(double[] a, double[] b)
ai bi
to high accuracy.
It does so by using specific multiplication and addition algorithms to
preserve accuracy and reduce cancellation effects.
a
- Factors.b
- Factors.Σi ai bi
.public static double linearCombination(double a1, double b1, double a2, double b2)
This method computes a1×b1 + a2×b2 to high accuracy. It does so by using specific multiplication and addition algorithms to preserve accuracy and reduce cancellation effects. It is based on the 2005 paper Accurate Sum and Dot Product by Takeshi Ogita, Siegfried M. Rump, and Shin'ichi Oishi published in SIAM J. Sci. Comput.
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second termlinearCombination(double, double, double, double, double, double)
,
linearCombination(double, double, double, double, double, double, double, double)
public static double linearCombination(double a1, double b1, double a2, double b2, double a3, double b3)
This method computes a1×b1 + a2×b2 + a3×b3 to high accuracy. It does so by using specific multiplication and addition algorithms to preserve accuracy and reduce cancellation effects. It is based on the 2005 paper Accurate Sum and Dot Product by Takeshi Ogita, Siegfried M. Rump, and Shin'ichi Oishi published in SIAM J. Sci. Comput.
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third termlinearCombination(double, double, double, double)
,
linearCombination(double, double, double, double, double, double, double, double)
public static double linearCombination(double a1, double b1, double a2, double b2, double a3, double b3, double a4, double b4)
This method computes a1×b1 + a2×b2 + a3×b3 + a4×b4 to high accuracy. It does so by using specific multiplication and addition algorithms to preserve accuracy and reduce cancellation effects. It is based on the 2005 paper Accurate Sum and Dot Product by Takeshi Ogita, Siegfried M. Rump, and Shin'ichi Oishi published in SIAM J. Sci. Comput.
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third terma4
- first factor of the third termb4
- second factor of the third termlinearCombination(double, double, double, double)
,
linearCombination(double, double, double, double, double, double)
public static boolean equals(float[] x, float[] y)
Precision.equals(float,float)
.x
- first arrayy
- second arraypublic static boolean equalsIncludingNaN(float[] x, float[] y)
this method
.x
- first arrayy
- second arraypublic static boolean equals(double[] x, double[] y)
true
iff both arguments are null
or have same
dimensions and all their elements are equal as defined by
Precision.equals(double,double)
.x
- First array.y
- Second array.true
if the values are both null
or have same
dimension and equal elements.public static boolean equalsIncludingNaN(double[] x, double[] y)
true
iff both arguments are null
or have same
dimensions and all their elements are equal as defined by
this method
.x
- First array.y
- Second array.true
if the values are both null
or have same
dimension and equal elements.public static double[] normalizeArray(double[] values, double normalizedSum)
x |-> x * normalizedSum / sumapplied to each non-NaN element x of the input array, where sum is the sum of the non-NaN entries in the input array.
Throws IllegalArgumentException if normalizedSum
is infinite
or NaN and ArithmeticException if the input array contains any infinite elements
or sums to 0.
Ignores (i.e., copies unchanged to the output array) NaNs in the input array.
values
- Input array to be normalizednormalizedSum
- Target sum for the normalized arrayMathArithmeticException
- if the input array contains infinite
elements or sums to zero.MathIllegalArgumentException
- if the target sum is infinite or NaN
.Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.