Package ucar.array
Class Arrays
- java.lang.Object
-
- ucar.array.Arrays
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Array<T>
combine(ArrayType dataType, int[] shape, List<Array<?>> dataArrays)
Combine list of Array's by copying the underlying Array's into a single primitive arraystatic long
computeSize(int[] shape)
Compute total number of elements in the array.static byte[]
convertCharToByte(char[] from)
static Object
copyPrimitiveArray(Array<?> data)
Copy all the data out of the Array into a 1d primitive array of the appropriate type.static boolean
equalDoubles(Array<Double> arr1, Array<Double> arr2)
Compare values which must be equal to withinMisc.defaultMaxRelativeDiffDouble
.static boolean
equalFloats(Array<Float> arr1, Array<Float> arr2)
Compare values which must be equal to withinMisc.defaultMaxRelativeDiffFloat
.static boolean
equalNumbers(Array<Number> arr1, Array<Number> arr2)
Compare values which must be equal to withinMisc.defaultMaxRelativeDiffFloat
.static <T> Array<T>
factory(ArrayType dataType, int[] shape, Object dataArray)
Create Array using java array of T, or java primitive array, as storage.static <T> Array<T>
factoryFill(ArrayType dataType, int[] shape, Number fillValue)
Create Array using empty java array of T, or java primitive array, same size as shape.static <T> Array<T>
flip(Array<T> org, int dim)
Create a new Array using same backing store as the org Array, by flipping the index so that it runs from shape[index]-1 to 0.static com.google.protobuf.ByteString
getByteString(Array<Byte> from)
Convert the Array into a ByteString.static MinMax
getMinMaxSkipMissingData(Array<? extends Number> a, IsMissingEvaluator eval)
Get the min and max of the array, skipping missing data if eval.hasMissing().static <T> Array<T>
makeArray(ArrayType type, int npts, double start, double incr, int... shape)
Make a regular numeric array from a start and incr.static String
makeStringFromChar(Array<Byte> from)
Create a String out of an Array\of rank zero or one. static Array<String>
makeStringsFromChar(Array<Byte> from)
Create an Array of Strings out of an Array\of any rank. static <T> Array<T>
permute(Array<T> org, int[] dims)
Create a new Array using same backing store as the org Array, by permuting the indices.static <T> Array<T>
reduce(Array<T> org)
Create a new Array using same backing store as the org Array, by eliminating any dimensions with length one.static <T> Array<T>
reduce(Array<T> org, int dim)
Create a new Array using same backing store as the org Array, by eliminating the specified dimension, which must have length 1.static <T> Array<T>
reduceFirst(Array<T> org, int ndim)
Create a new Array using same backing store as the org Array, by eliminating the first ndim dimensions, iff they have length 1.static int[]
removeVlen(int[] shape)
If there are any VLEN dimensions (length < 0), remove it and all dimensions to the right.static <T> Array<T>
reshape(Array<T> org, int[] shape)
Create a new Array using same backing store with given shapestatic <T> Array<T>
section(Array<T> org, Section section)
Create a new Array as a subsection of the org Array, without rank reduction.static <T> Array<T>
slice(Array<T> org, int dim, int value)
Create a new Array using same backing store as the org Array, by fixing the specified dimension at the specified index value.static double
sumDouble(Array<?> array)
Sum all the values in the Array as doubles.static Array<Double>
toDouble(Array<?> array)
Convert a numeric array to double values.static <T> Array<T>
transpose(Array<T> org, int dim1, int dim2)
Create a new Array using same backing store as the org Array, by transposing two of the indices.
-
-
-
Method Detail
-
factory
public static <T> Array<T> factory(ArrayType dataType, int[] shape, Object dataArray)
Create Array using java array of T, or java primitive array, as storage. Do not use this for Vlens or Structures. The dataArray is not copied, for efficiency. The calling routine must not reuse the primitive array.- Parameters:
dataType
- data type of the data. Vlen detected from the shape.shape
- multidimensional shape, must have same total length as dataArray.dataArray
- must be java primitive array or String[]
-
factoryFill
public static <T> Array<T> factoryFill(ArrayType dataType, int[] shape, Number fillValue)
Create Array using empty java array of T, or java primitive array, same size as shape. Do not use this for Vlens or Structures.*- Parameters:
shape
- multidimensional shape
-
combine
public static <T> Array<T> combine(ArrayType dataType, int[] shape, List<Array<?>> dataArrays)
Combine list of Array's by copying the underlying Array's into a single primitive array- Parameters:
dataType
- of the dataArrays and of the result.shape
- of the result.dataArrays
- the composite data.- Returns:
- composite Array, formed by copying the dataArrays, must be of type dataType.
-
flip
public static <T> Array<T> flip(Array<T> org, int dim)
Create a new Array using same backing store as the org Array, by flipping the index so that it runs from shape[index]-1 to 0.- Parameters:
org
- original Arraydim
- dimension to flip- Returns:
- the new Array
-
permute
public static <T> Array<T> permute(Array<T> org, int[] dims)
Create a new Array using same backing store as the org Array, by permuting the indices.- Parameters:
org
- original Arraydims
- the old index dims[k] becomes the new kth index.- Returns:
- the new Array
-
reshape
public static <T> Array<T> reshape(Array<T> org, int[] shape)
Create a new Array using same backing store with given shape- Parameters:
org
- original Arrayshape
- the new shape- Returns:
- the new Array
-
reduce
public static <T> Array<T> reduce(Array<T> org)
Create a new Array using same backing store as the org Array, by eliminating any dimensions with length one.- Parameters:
org
- original Array- Returns:
- the new Array, or the same Array if no reduction was done
-
reduce
public static <T> Array<T> reduce(Array<T> org, int dim)
Create a new Array using same backing store as the org Array, by eliminating the specified dimension, which must have length 1.- Parameters:
org
- original Arraydim
- dimension to eliminate: must be of length one.- Returns:
- the new Array, or the same Array if no reduction was done
-
reduceFirst
public static <T> Array<T> reduceFirst(Array<T> org, int ndim)
Create a new Array using same backing store as the org Array, by eliminating the first ndim dimensions, iff they have length 1.- Parameters:
org
- original Arrayndim
- number of dimensions to reduce.- Returns:
- the new Array, or the same Array if no reduction was done
-
section
public static <T> Array<T> section(Array<T> org, Section section) throws InvalidRangeException
Create a new Array as a subsection of the org Array, without rank reduction. No data is moved, so the new Array references the same backing store as the original. Vlen is transferred over unchanged.- Parameters:
org
- original Arraysection
- list of Ranges that specify the array subset. Must be same rank as original Array. A particular Range: 1) may be a subset, or 2) may be null, meaning use entire Range.- Returns:
- the new Array
- Throws:
InvalidRangeException
-
slice
public static <T> Array<T> slice(Array<T> org, int dim, int value) throws InvalidRangeException
Create a new Array using same backing store as the org Array, by fixing the specified dimension at the specified index value. This reduces rank by 1.- Parameters:
org
- original Arraydim
- which dimension to fixvalue
- at what index value- Returns:
- a new Array, with reduced rank.
- Throws:
InvalidRangeException
-
transpose
public static <T> Array<T> transpose(Array<T> org, int dim1, int dim2)
Create a new Array using same backing store as the org Array, by transposing two of the indices.- Parameters:
org
- original Arraydim1
- transpose these two indicesdim2
- transpose these two indices- Returns:
- the new Array
-
computeSize
public static long computeSize(@Nullable int[] shape)
Compute total number of elements in the array. Stop at vlen.- Parameters:
shape
- length of array in each dimension.- Returns:
- total number of elements in the array.
-
removeVlen
public static int[] removeVlen(int[] shape)
If there are any VLEN dimensions (length < 0), remove it and all dimensions to the right.- Parameters:
shape
- multidimensional shape- Returns:
- modified shape, if needed.
-
copyPrimitiveArray
public static Object copyPrimitiveArray(Array<?> data)
Copy all the data out of the Array into a 1d primitive array of the appropriate type.
-
sumDouble
public static double sumDouble(Array<?> array)
Sum all the values in the Array as doubles. Must be an array of Number.
-
toDouble
public static Array<Double> toDouble(Array<?> array)
Convert a numeric array to double values.
-
getMinMaxSkipMissingData
public static MinMax getMinMaxSkipMissingData(Array<? extends Number> a, @Nullable IsMissingEvaluator eval)
Get the min and max of the array, skipping missing data if eval.hasMissing().
-
makeArray
public static <T> Array<T> makeArray(ArrayType type, int npts, double start, double incr, int... shape)
Make a regular numeric array from a start and incr.- Parameters:
type
- type of arraynpts
- number of pointsstart
- starting valueincr
- incrementshape
- shape of resulting array. if not set, use 1 dim array of length npts.
-
makeStringsFromChar
public static Array<String> makeStringsFromChar(Array<Byte> from)
Create an Array of Strings out of an Array\of any rank. If there is a null (zero) value in from, the String will end there. The null is not returned as part of the String. - Returns:
- Array of Strings of rank - 1.
-
makeStringFromChar
public static String makeStringFromChar(Array<Byte> from)
Create a String out of an Array\of rank zero or one. If there is a null (zero) value in from, the String will end there. The null is not returned as part of the String.
-
getByteString
public static com.google.protobuf.ByteString getByteString(Array<Byte> from)
Convert the Array into a ByteString.
-
convertCharToByte
public static byte[] convertCharToByte(char[] from)
-
equalDoubles
public static boolean equalDoubles(Array<Double> arr1, Array<Double> arr2)
Compare values which must be equal to withinMisc.defaultMaxRelativeDiffDouble
.
-
equalFloats
public static boolean equalFloats(Array<Float> arr1, Array<Float> arr2)
Compare values which must be equal to withinMisc.defaultMaxRelativeDiffFloat
.
-
equalNumbers
public static boolean equalNumbers(Array<Number> arr1, Array<Number> arr2)
Compare values which must be equal to withinMisc.defaultMaxRelativeDiffFloat
.
-
-