

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object org.apache.commons.math3.util.MathArrays
public class MathArrays
Arrays utilities.
Nested Class Summary  

static interface 
MathArrays.Function
Realvalued function that operate on an array or a part of it. 
static class 
MathArrays.OrderDirection
Specification of ordering direction. 
Method Summary  

static void 
checkNonNegative(long[] in)
Check that all entries of the input array are >= 0. 

static void 
checkNonNegative(long[][] in)
Check all entries of the input array are >= 0. 

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 void 
checkPositive(double[] in)
Check that all entries of the input array are strictly positive. 

static void 
checkRectangular(long[][] in)
Throws DimensionMismatchException if the input array is not rectangular. 

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 L_{2} (Euclidean) distance between two points. 

static double 
distance(int[] p1,
int[] p2)
Calculates the L_{2} (Euclidean) distance between two points. 

static double 
distance1(double[] p1,
double[] p2)
Calculates the L_{1} (sum of abs) distance between two points. 

static int 
distance1(int[] p1,
int[] p2)
Calculates the L_{1} (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 double[] 
ebeAdd(double[] a,
double[] b)
Creates an array whose contents will be the elementbyelement addition of the arguments. 

static double[] 
ebeDivide(double[] a,
double[] b)
Creates an array whose contents will be the elementbyelement division of the first argument by the second. 

static double[] 
ebeMultiply(double[] a,
double[] b)
Creates an array whose contents will be the elementbyelement multiplication of the arguments. 

static double[] 
ebeSubtract(double[] a,
double[] b)
Creates an array whose contents will be the elementbyelement subtraction of the second argument from the first. 

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(double[] val,
MathArrays.OrderDirection dir,
boolean strict)
Check that an array is monotonically increasing or decreasing. 

static

isMonotonic(T[] 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 (2norm), 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. 
Methods inherited from class java.lang.Object 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Method Detail 

public static double[] ebeAdd(double[] a, double[] b)
a
 First term of the addition.b
 Second term of the addition.
r
where r[i] = a[i] + b[i]
.
DimensionMismatchException
 if the array lengths differ.public static double[] ebeSubtract(double[] a, double[] b)
a
 First term.b
 Element to be subtracted.
r
where r[i] = a[i]  b[i]
.
DimensionMismatchException
 if the array lengths differ.public static double[] ebeMultiply(double[] a, double[] b)
a
 First factor of the multiplication.b
 Second factor of the multiplication.
r
where r[i] = a[i] * b[i]
.
DimensionMismatchException
 if the array lengths differ.public static double[] ebeDivide(double[] a, double[] b)
a
 Numerator of the division.b
 Denominator of the division.
r
where r[i] = a[i] / b[i]
.
DimensionMismatchException
 if the array lengths differ.public static double distance1(double[] p1, double[] p2)
p1
 the first pointp2
 the second point
public static int distance1(int[] p1, int[] p2)
p1
 the first pointp2
 the second point
public static double distance(double[] p1, double[] p2)
p1
 the first pointp2
 the second point
public static double distance(int[] p1, int[] p2)
p1
 the first pointp2
 the second point
public static double distanceInf(double[] p1, double[] p2)
p1
 the first pointp2
 the second point
public static int distanceInf(int[] p1, int[] p2)
p1
 the first pointp2
 the second point
public static <T extends Comparable<? super T>> boolean isMonotonic(T[] val, MathArrays.OrderDirection dir, boolean strict)
T
 the type of the elements in the specified arrayval
 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) throws NonMonotonicSequenceException
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) throws NonMonotonicSequenceException
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) throws NonMonotonicSequenceException
val
 Values.
NonMonotonicSequenceException
 if the array is not sorted.public static void checkRectangular(long[][] in) throws NullArgumentException, DimensionMismatchException
in
 array to be tested
NullArgumentException
 if input array is null
DimensionMismatchException
 if input array is not rectangularpublic static void checkPositive(double[] in) throws NotStrictlyPositiveException
in
 Array to be tested
NotStrictlyPositiveException
 if any entries of the array are not
strictly positive.public static void checkNonNegative(long[] in) throws NotPositiveException
in
 Array to be tested
NotPositiveException
 if any array entries are less than 0.public static void checkNonNegative(long[][] in) throws NotPositiveException
in
 Array to be tested
NotPositiveException
 if any array entries are less than 0.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) throws DimensionMismatchException, NullArgumentException
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) throws NullArgumentException, DimensionMismatchException
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) throws DimensionMismatchException
a_{i} b_{i}
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} a_{i} b_{i}
.
DimensionMismatchException
 if arrays dimensions don't matchpublic static double linearCombination(double a1, double b1, double a2, double b2)
This method computes a_{1}×b_{1} + a_{2}×b_{2} 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 term
linearCombination(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 a_{1}×b_{1} + a_{2}×b_{2} + a_{3}×b_{3} 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 term
linearCombination(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 a_{1}×b_{1} + a_{2}×b_{2} + a_{3}×b_{3} + a_{4}×b_{4} 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 term
linearCombination(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 array
public static boolean equalsIncludingNaN(float[] x, float[] y)
this method
.
x
 first arrayy
 second array
public 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) throws MathIllegalArgumentException, MathArithmeticException
x > x * normalizedSum / sumapplied to each nonNaN element x of the input array, where sum is the sum of the nonNaN 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 array
MathArithmeticException
 if the input array contains infinite
elements or sums to zero.
MathIllegalArgumentException
 if the target sum is infinite or NaN
.


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 