类 MAMath
- java.lang.Object
-
- org.meteoinfo.ndarray.MAMath
-
public class MAMath extends java.lang.ObjectElement by element algebra on Arrays- 作者:
- caron
- 另请参阅:
Index
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classMAMath.MinMaxHolds a minimum and maximum value.static classMAMath.ScaleOffsetHolds a scale and offset.
-
构造器概要
构造器 构造器 说明 MAMath()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static Arrayadd(Array a, Array b)Add elements of two arrays together, allocating the result array.static voidaddDouble(Array result, Array a, Array b)Add elements of two arrays together as doubles, place sum in the result array.static MAMath.ScaleOffsetcalcScaleOffsetSkipMissingData(Array a, double missingValue, int nbits, boolean isUnsigned)Calculate the scale/offset for an array of numbers.static booleanconformable(int[] shapeA, int[] shapeB)Check that two array shapes are conformable.static booleanconformable(Array a, Array b)Check that two arrays are conformable.static Arrayconvert(Array org, DataType wantType)Convert original array to desired typestatic Arrayconvert2packed(Array unpacked, double missingValue, int nbits, boolean isUnsigned, DataType packedType)static Arrayconvert2Unpacked(Array packed, MAMath.ScaleOffset scaleOffset)static ArrayconvertUnsigned(Array unsigned)Convert unsigned data to signed data of a wider type.static voidcopy(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 voidcopy(DataType dataType, IndexIterator from, IndexIterator to)Copy using iterators.static voidcopyBoolean(Array result, Array a)copy array a to array result as bytes The array a and result must be type booleanstatic voidcopyByte(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 voidcopyChar(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 voidcopyDouble(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 voidcopyFloat(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 voidcopyInt(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 voidcopyLong(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 voidcopyObject(Array result, Array a)copy array a to array result as an Object The array a and result must be type objectstatic voidcopyShort(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 booleanfuzzyEquals(Array data1, Array data2)Returns true if the specified arrays have the same size, signedness, and approximately equal corresponding elements.static doublegetMaximum(Array a)static doublegetMaximumSkipMissingData(Array a, double missingValue)static doublegetMinimum(Array a)static doublegetMinimumSkipMissingData(Array a, double missingValue)static MAMath.MinMaxgetMinMax(Array a)Find min and max value in this array, getting values as doubles.static MAMath.MinMaxgetMinMaxSkipMissingData(Array a, double missingValue)static MAMath.MinMaxgetMinMaxSkipMissingData(Array a, IsMissingEvaluator eval)static booleanisEqual(Array data1, Array data2)static intreducedRank(int[] shape)Calculate the reduced rank of this shape, by subtracting dimensions with length 1static voidsetDouble(Array result, double val)Set all the elements of this array to the given double value.static doublesumDouble(Array a)sum all of the elements of array a as doubles.static doublesumDoubleSkipMissingData(Array a, double missingValue)sum all of the elements of array a as doubles.
-
-
-
方法详细资料
-
add
public static Array add(Array a, Array b) throws java.lang.IllegalArgumentException
Add elements of two arrays together, allocating the result array. The result type and the operation type are taken from the type of a.- 参数:
a- add values from hereb- add values from here- 返回:
- result = a + b
- 抛出:
java.lang.IllegalArgumentException- a and b are not conformablejava.lang.UnsupportedOperationException- dont support this data type yet
-
addDouble
public static void addDouble(Array result, Array a, Array b) throws java.lang.IllegalArgumentException
Add elements of two arrays together as doubles, place sum in the result array. The values from the arrays a and b are converted to double (if needed), and the sum is converted to the type of result (if needed).- 参数:
result- result arraya- operandb- operand- 抛出:
java.lang.IllegalArgumentException- a,b,and result are not conformable
-
conformable
public static boolean conformable(Array a, Array b)
Check that two arrays are conformable.- 参数:
a- operandb- operand- 返回:
- true if conformable
-
conformable
public static boolean conformable(int[] shapeA, int[] shapeB)Check that two array shapes are conformable. The shapes must match exactly, except that dimensions of length 1 are ignored.- 参数:
shapeA- shape of array 1shapeB- shape of array 2- 返回:
- true if conformable
-
convertUnsigned
public static Array convertUnsigned(Array unsigned)
Convert unsigned data to signed data of a wider type.- 参数:
unsigned- must be of type byte, short or int- 返回:
- converted data of type short, int, or long
-
convert
public static Array convert(Array org, DataType wantType)
Convert original array to desired type- 参数:
org- original arraywantType- desired type- 返回:
- converted data of desired type, or original array if it is already
-
copy
public static void copy(DataType dataType, IndexIterator from, IndexIterator to) throws java.lang.IllegalArgumentException
Copy using iterators. Will copy until !from.hasNext().- 参数:
dataType- use this operation type (eg DataType.DOUBLE uses getDoubleNext())from- copy from hereto- copy to here- 抛出:
java.lang.IllegalArgumentException- a and b are not conformablejava.lang.UnsupportedOperationException- dont support this data type
-
copy
public static void copy(Array result, Array a) throws java.lang.IllegalArgumentException
Copy array a to array result, the result array will be in canonical order The operation type is taken from the type of a.- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and b are not conformablejava.lang.UnsupportedOperationException- dont support this data type yet
-
copyDouble
public static void copyDouble(Array result, Array a) throws java.lang.IllegalArgumentException
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).- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
copyFloat
public static void copyFloat(Array result, Array a) throws java.lang.IllegalArgumentException
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).- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
copyLong
public static void copyLong(Array result, Array a) throws java.lang.IllegalArgumentException
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).- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
copyInt
public static void copyInt(Array result, Array a) throws java.lang.IllegalArgumentException
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).- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
copyShort
public static void copyShort(Array result, Array a) throws java.lang.IllegalArgumentException
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).- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
copyChar
public static void copyChar(Array result, Array a) throws java.lang.IllegalArgumentException
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).- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
copyByte
public static void copyByte(Array result, Array a) throws java.lang.IllegalArgumentException
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).- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
copyBoolean
public static void copyBoolean(Array result, Array a) throws java.lang.IllegalArgumentException
copy array a to array result as bytes The array a and result must be type boolean- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
copyObject
public static void copyObject(Array result, Array a) throws java.lang.IllegalArgumentException
copy array a to array result as an Object The array a and result must be type object- 参数:
result- copy to herea- copy from here- 抛出:
java.lang.IllegalArgumentException- a and result are not conformable
-
reducedRank
public static int reducedRank(int[] shape)
Calculate the reduced rank of this shape, by subtracting dimensions with length 1- 参数:
shape- shape of the array- 返回:
- rank without dimensions of length 1
-
getMinimum
public static double getMinimum(Array a)
-
getMaximum
public static double getMaximum(Array a)
-
getMinMax
public static MAMath.MinMax getMinMax(Array a)
Find min and max value in this array, getting values as doubles. Skip Double.NaN.- 参数:
a- the array.- 返回:
- MinMax
-
getMinMaxSkipMissingData
public static MAMath.MinMax getMinMaxSkipMissingData(Array a, IsMissingEvaluator eval)
-
getMinimumSkipMissingData
public static double getMinimumSkipMissingData(Array a, double missingValue)
-
getMaximumSkipMissingData
public static double getMaximumSkipMissingData(Array a, double missingValue)
-
getMinMaxSkipMissingData
public static MAMath.MinMax getMinMaxSkipMissingData(Array a, double missingValue)
-
setDouble
public static void setDouble(Array result, double val)
Set all the elements of this array to the given double value. The value is converted to the element type of the array, if needed.- 参数:
result- change this Arrayval- set all elements to this value
-
sumDouble
public static double sumDouble(Array a)
sum all of the elements of array a as doubles. The values from the array a are converted to double (if needed).- 参数:
a- read values from this Array- 返回:
- sum of elements
-
sumDoubleSkipMissingData
public static double sumDoubleSkipMissingData(Array a, double missingValue)
sum all of the elements of array a as doubles. The values from the array a are converted to double (if needed).- 参数:
a- read values from this ArraymissingValue- skip values equal to this, or which are NaNs- 返回:
- sum of elements
-
calcScaleOffsetSkipMissingData
public static MAMath.ScaleOffset calcScaleOffsetSkipMissingData(Array a, double missingValue, int nbits, boolean isUnsigned)
Calculate the scale/offset for an array of numbers.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 bitsisUnsigned- use signed or unsigned packed values- 返回:
- ScaleOffset, calculated as above.
-
convert2packed
public static Array convert2packed(Array unpacked, double missingValue, int nbits, boolean isUnsigned, DataType packedType)
-
convert2Unpacked
public static Array convert2Unpacked(Array packed, MAMath.ScaleOffset scaleOffset)
-
fuzzyEquals
public static boolean fuzzyEquals(Array data1, Array data2)
Returns true if the specified arrays have the same size, signedness, and approximately equal corresponding elements.floatelements must be within1.0e-5of each other anddoubleelements must be within1.0e-8of each other.- 参数:
data1- one array to be tested for equality.data2- the other array to be tested for equality.- 返回:
- true if the specified arrays have the same size, signedness, and approximately equal corresponding elems.
-
-