Modifier and Type | Class and Description |
---|---|
static class |
MAMath.MinMax
Holds a minimum and maximum value.
|
static class |
MAMath.ScaleOffset
Holds a scale and offset.
|
Constructor and Description |
---|
MAMath() |
Modifier and Type | Method and Description |
---|---|
static Array |
add(Array a,
Array b)
Add elements of two arrays together, allocating the result array.
|
static void |
addDouble(Array result,
Array a,
Array b)
Add elements of two arrays together as doubles, place sum in the result array.
|
static MAMath.ScaleOffset |
calcScaleOffsetSkipMissingData(Array a,
double missingValue,
int nbits)
Calculate the scale/offset for an array of numbers.
|
static boolean |
conformable(Array a,
Array b)
Check that two arrays are conformable.
|
static boolean |
conformable(int[] shapeA,
int[] shapeB)
Check that two array shapes are conformable.
|
static Array |
convert(Array org,
DataType wantType)
Convert original array to desired type
|
static Array |
convert2packed(Array unpacked,
double missingValue,
int nbits,
DataType packedType) |
static Array |
convert2Unpacked(Array packed,
MAMath.ScaleOffset scaleOffset) |
static void |
copy(Array result,
Array a)
Copy array a to array result, the result array will be in canonical order
The operation type is taken from the type of a.
|
static void |
copy(DataType dataType,
IndexIterator from,
IndexIterator to)
Copy using iterators.
|
static void |
copyBoolean(Array result,
Array a)
copy array a to array result as bytes
The array a and result must be type boolean
|
static void |
copyByte(Array result,
Array a)
copy array a to array result as bytes
The values from the array a are converted to byte (if needed),
and then converted to the type of result (if needed).
|
static void |
copyChar(Array result,
Array a)
copy array a to array result as char
The values from the array a are converted to char (if needed),
and then converted to the type of result (if needed).
|
static void |
copyDouble(Array result,
Array a)
copy array a to array result as doubles
The values from the arrays a are converted to double (if needed),
and then converted to the type of result (if needed).
|
static void |
copyFloat(Array result,
Array a)
copy array a to array result as floats
The values from the arrays a are converted to float (if needed),
and then converted to the type of result (if needed).
|
static void |
copyInt(Array result,
Array a)
copy array a to array result as integers
The values from the arrays a are converted to integer (if needed),
and then converted to the type of result (if needed).
|
static void |
copyLong(Array result,
Array a)
copy array a to array result as longs
The values from the array a are converted to long (if needed),
and then converted to the type of result (if needed).
|
static void |
copyObject(Array result,
Array a)
copy array a to array result as an Object
The array a and result must be type object
|
static void |
copyShort(Array result,
Array a)
copy array a to array result as shorts
The values from the array a are converted to short (if needed),
and then converted to the type of result (if needed).
|
static boolean |
equals(Array array1,
Array array2)
Returns true if the specified arrays have the same data type, shape, and equal corresponding elements.
|
static double |
getMaximum(Array a) |
static double |
getMaximumSkipMissingData(Array a,
double missingValue) |
static double |
getMinimum(Array a) |
static double |
getMinimumSkipMissingData(Array a,
double missingValue) |
static MAMath.MinMax |
getMinMax(Array a)
Find min and max value in this array, getting values as doubles.
|
static MAMath.MinMax |
getMinMaxSkipMissingData(Array a,
double missingValue) |
static MAMath.MinMax |
getMinMaxSkipMissingData(Array a,
IsMissingEvaluator eval) |
static int |
hashCode(Array array)
An implementation of
Object.hashCode() that is consistent with equals(Array, Array) . |
static boolean |
nearlyEquals(Array data1,
Array data2)
Returns true if the specified arrays have the same size, signedness, and approximately equal corresponding
elements.
|
static int |
reducedRank(int[] shape)
Calculate the reduced rank of this shape, by subtracting dimensions with length 1
|
static void |
setDouble(Array result,
double val)
Set all the elements of this array to the given double value.
|
static double |
sumDouble(Array a)
sum all of the elements of array a as doubles.
|
static double |
sumDoubleSkipMissingData(Array a,
double missingValue)
sum all of the elements of array a as doubles.
|
public static Array add(Array a, Array b) throws IllegalArgumentException
a
- add values from hereb
- add values from hereIllegalArgumentException
- a and b are not conformableUnsupportedOperationException
- dont support this data type yetpublic static void addDouble(Array result, Array a, Array b) throws IllegalArgumentException
result
- result arraya
- operandb
- operandIllegalArgumentException
- a,b,and result are not conformablepublic static MAMath.ScaleOffset calcScaleOffsetSkipMissingData(Array a, double missingValue, int nbits)
If signed: then max value unpacked = 2^(n-1) - 1 packed min value unpacked = -(2^(n-1) - 1) packed note that -2^(n-1) is unused, and a good place to map missing values by solving 2 eq in 2 unknowns, we get: scale = (max - min) / (2^n - 2) offset = (max + min) / 2 If unsigned then max value unpacked = 2^n - 1 packed min value unpacked = 0 packed and: scale = (max - min) / (2^n - 1) offset = min One could modify this to allow a holder for missing values.
a
- array to convert (not changed)missingValue
- skip thesenbits
- map into this many bitspublic static boolean conformable(Array a, Array b)
a
- operandb
- operandpublic static boolean conformable(int[] shapeA, int[] shapeB)
shapeA
- shape of array 1shapeB
- shape of array 2public static Array convert(Array org, DataType wantType)
org
- original arraywantType
- desired typepublic static Array convert2packed(Array unpacked, double missingValue, int nbits, DataType packedType)
public static Array convert2Unpacked(Array packed, MAMath.ScaleOffset scaleOffset)
public static void copy(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and b are not conformableUnsupportedOperationException
- dont support this data type yetpublic static void copy(DataType dataType, IndexIterator from, IndexIterator to) throws IllegalArgumentException
dataType
- use this operation type (eg DataType.DOUBLE uses getDoubleNext())from
- copy from hereto
- copy to hereIllegalArgumentException
- a and b are not conformableUnsupportedOperationException
- dont support this data typepublic static void copyBoolean(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static void copyByte(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static void copyChar(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static void copyDouble(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static void copyFloat(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static void copyInt(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static void copyLong(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static void copyObject(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static void copyShort(Array result, Array a) throws IllegalArgumentException
result
- copy to herea
- copy from hereIllegalArgumentException
- a and result are not conformablepublic static boolean equals(Array array1, Array array2)
Object.equals(java.lang.Object)
implementations.
Note that floating-point elements must be exactly equal, not merely within some epsilon of each other. This is
because it's impossible to write a strictly-conforming Object.equals(java.lang.Object)
implementation when an
epsilon is incorporated, due to the transitivity requirement.
nearlyEquals(ucar.ma2.Array, ucar.ma2.Array)
is an alternative to this method that returns true if the corresponding elements are
"approximately" equal to each other.
array1
- one array to be tested for equality.array2
- the other array to be tested for equality.public static double getMaximum(Array a)
public static double getMaximumSkipMissingData(Array a, double missingValue)
public static double getMinimum(Array a)
public static double getMinimumSkipMissingData(Array a, double missingValue)
public static MAMath.MinMax getMinMax(Array a)
a
- the array.public static MAMath.MinMax getMinMaxSkipMissingData(Array a, double missingValue)
public static MAMath.MinMax getMinMaxSkipMissingData(Array a, IsMissingEvaluator eval)
public static int hashCode(Array array)
Object.hashCode()
that is consistent with equals(Array, Array)
.array
- an array to hash.public static boolean nearlyEquals(Array data1, Array data2)
float
elements must be within Misc.defaultMaxRelativeDiffFloat
of each other, as
determined by Misc.nearlyEquals(double, double, double)
. Similarly, double
elements must be within
Misc.defaultMaxRelativeDiffDouble
of each other.
equals(Array, Array)
is an alternative to this method that requires that corresponding elements be
exactly equal. It is suitable for use in Object.equals(java.lang.Object)
implementations, whereas this method isn't.
data1
- one array to be tested for equality.data2
- the other array to be tested for equality.public static int reducedRank(int[] shape)
shape
- shape of the arraypublic static void setDouble(Array result, double val)
result
- change this Arrayval
- set all elements to this valuepublic static double sumDouble(Array a)
a
- read values from this Arraypublic static double sumDoubleSkipMissingData(Array a, double missingValue)
a
- read values from this ArraymissingValue
- skip values equal to this, or which are NaNs