Class Array<T>
java.lang.Object
org.apache.sysds.runtime.frame.data.columns.Array<T>
- All Implemented Interfaces:
org.apache.hadoop.io.Writable
- Direct Known Subclasses:
ABooleanArray,ACompressedArray,CharArray,DoubleArray,FloatArray,HashIntegerArray,HashLongArray,IntegerArray,LongArray,OptionalArray,RaggedArray,StringArray
Generic, resizable native arrays for the internal representation of the columns in the FrameBlock. We use this custom
class hierarchy instead of Trove or other libraries in order to avoid unnecessary dependencies.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intParallelization threshold for parallelizing vector operations -
Method Summary
Modifier and TypeMethodDescriptionfinal Pair<Types.ValueType,Boolean> Analyze the column to figure out if the value type can be refined to a better type.abstract Pair<Types.ValueType,Boolean> analyzeValueType(int maxCells) Analyze the column to figure out if the value type can be refined to a better type.abstract voidAppend a string value to the current Array, this should in general be avoided, and appending larger blocks at a time should be preferred.Append other array, if the other array is fitting in current allocated size use that allocated size, otherwise allocate new array to combine the other with this.abstract voidAppend a value of the same type of the Array.static longGet the base memory cost of the Arrays allocation.Array<?>Change the allocated array to a different type.Array<?>changeType(Types.ValueType t, boolean containsNull) Change type taking into consideration if the target type must be able to contain Null.final Array<?>changeType(Array<?> ret) Change type by moving this arrays value into the given ret array.final Array<?>changeType(Array<?> ret, int rl, int ru) Put the changed value types into the given ret array inside the range specified.Array<?>final Array<?>changeTypeWithNulls(Array<?> ret) final Array<?>changeTypeWithNulls(Array<?> ret, int l, int u) clone()Overwrite of the java internal clone function for arrays, return a clone of underlying data that is mutable, (not immutable data.) Immutable data is dependent on the individual allocated arraysbooleananalyze if the array contains null values.booleanabstract booleanEquals operation on arrays.double[]extractDouble(double[] ret, int rl, int ru) Extract the sub array into the ret array as doubles.abstract voidfill the entire array with specific value.abstract voidfill the entire array with specific value.final voidfindEmpty(boolean[] select) Find the empty rows, it is assumed that the input is to be only modified to set variables to true.voidfindEmptyInverse(boolean[] select) Find the filled rows, it is assumed that the input i to be only modified to set variables to true;abstract Objectget()Get the underlying array out of the column Group, it is the responsibility of the caller to know what type it is.abstract Tget(int index) Get the value at a given index.abstract byte[]Return the current allocated Array as a byte[], this is used to serialize the allocated Arrays out to the PythonAPI.abstract doublegetAsDouble(int i) Get the index's value.doublegetAsNaNDouble(int i) Get the index's value.final SoftReference<Map<T,Integer>> getCache()Get the current cached recode map.abstract longGet the exact serialized size on disk of this array.abstract ArrayFactory.FrameArrayTypeGet the internal FrameArrayType, to specify the encoding of the Types, note there are more Frame Array Types than there is ValueTypes.longGet in memory size, not counting reference to this object.getInternal(int index) Get the internal value at a given index.Get the minimum and maximum length of the contained values as string type.getNulls()Get a recode map that maps each unique value in the array, to a long ID.getRecodeMap(int estimate) Get a recode map that maps each unique value in the array, to a long ID.getRecodeMap(int estimate, ExecutorService pool, int k) Get a recode map that maps each unique value in the array, to a long ID.abstract Types.ValueTypeGet the current value type of this array.abstract doublehashDouble(int idx) Hash the given index of the array.abstract booleanisEmpty()Get if this array is empty, aka filled with empty values.abstract booleanisNotEmpty(int i) abstract booleananalyze if this array can be shallow serialized.double[]minMax()Get the minimum and maximum double value of this array.double[]minMax(int l, int u) Get the minimum and maximum double value of a specific sub part of this array.abstract booleanabstract voidreset(int size) Reset the Array and set to a different size.select(boolean[] select, int nTrue) Slice out the true indices in the select input and return the sub array.select(int[] indices) Slice out the specified indices and return the sub array.abstract voidset(int index, double value) Set index to given double value (cast to the correct type of this array)final voidSet range to given arrays valuevoidSet range to given arrays value with an offset into other arrayabstract voidSet index to the given value of the string parsed.abstract voidSet index to the given value of same typefinal voidsetCache(SoftReference<Map<T, Integer>> m) Set the cached hashmap cache of this Array allocation, to be used in transformEncode.abstract voidsetFromOtherType(int rl, int ru, Array<?> value) Set range to given arrays valueabstract voidsetFromOtherTypeNz(int rl, int ru, Array<?> value) Set non default values in the range from the value array givenfinal voidsetFromOtherTypeNz(Array<?> value) Set non default values from the value array givenvoidsetM(HashMapToInt<T> map, int si, AMapToData m, int i) Set the index i in the map given based on the mapping provided.voidsetM(HashMapToInt<T> map, AMapToData m, int i) Set the index i in the map given based on the mapping provided.abstract voidSet non default values in the range from the value array givenfinal voidSet non default values from the value array givenfinal intsize()Get the number of elements in the array, this does not necessarily reflect the current allocated size.slice(int rl, int ru) Slice out the sub range and return new array with the specified type.statistics(int nSamples) Get the compression statistics of this array allocation.toString()Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.io.Writable
readFields, write
-
Field Details
-
ROW_PARALLELIZATION_THRESHOLD
public static int ROW_PARALLELIZATION_THRESHOLDParallelization threshold for parallelizing vector operations
-
-
Method Details
-
getCache
Get the current cached recode map.- Returns:
- The cached recode map
-
setCache
Set the cached hashmap cache of this Array allocation, to be used in transformEncode.- Parameters:
m- The element to cache.
-
getRecodeMap
Get a recode map that maps each unique value in the array, to a long ID. Null values are ignored, and not included in the mapping. The resulting recode map in stored in a soft reference to speed up repeated calls to the same column.- Returns:
- A recode map
-
getRecodeMap
Get a recode map that maps each unique value in the array, to a long ID. Null values are ignored, and not included in the mapping. The resulting recode map in stored in a soft reference to speed up repeated calls to the same column.- Parameters:
estimate- The estimated number of unique values in this Array to start the initial hashmap size at- Returns:
- A recode map
-
getRecodeMap
public final Map<T,Integer> getRecodeMap(int estimate, ExecutorService pool, int k) throws InterruptedException, ExecutionException Get a recode map that maps each unique value in the array, to a long ID. Null values are ignored, and not included in the mapping. The resulting recode map in stored in a soft reference to speed up repeated calls to the same column.- Parameters:
estimate- the estimated number of unique values in this array.pool- An executor pool to be used for parallel execution (Note this method does not shutdown the pool)k- Parallelization degree allowed- Returns:
- A recode map
- Throws:
ExecutionException- if the parallel execution failsInterruptedException- if the parallel execution fails
-
size
public final int size()Get the number of elements in the array, this does not necessarily reflect the current allocated size.- Returns:
- the current number of elements
-
get
Get the value at a given index. This method returns objects that have a high overhead in allocation. Therefore it is not as efficient as using the vectorized operations specified in the object.- Parameters:
index- The index to query- Returns:
- The value returned as an object
-
getInternal
Get the internal value at a given index. For instance HashIntegerArray would return the underlying long not a string.- Parameters:
index- the index to get- Returns:
- The value to get
-
get
Get the underlying array out of the column Group, it is the responsibility of the caller to know what type it is. Also it is not guaranteed that the underlying data structure does not allocate an appropriate response to the caller. This in practice means that if called there is a possibility that the entire array is allocated again. So the method should only be used for debugging purposes not for performance.- Returns:
- The underlying array.
-
getAsDouble
public abstract double getAsDouble(int i) Get the index's value. returns 0 in case of Null.- Parameters:
i- index to get value from- Returns:
- the value
-
getAsNaNDouble
public double getAsNaNDouble(int i) Get the index's value. returns Double.NaN in case of Null.- Parameters:
i- index to get value from- Returns:
- the value
-
set
Set index to the given value of same type- Parameters:
index- The index to setvalue- The value to assign
-
set
public abstract void set(int index, double value) Set index to given double value (cast to the correct type of this array)- Parameters:
index- the index to setvalue- the value to set it to (before casting to correct value type)
-
set
Set index to the given value of the string parsed.- Parameters:
index- The index to setvalue- The value to assign
-
setFromOtherType
Set range to given arrays value- Parameters:
rl- row lowerru- row upper (inclusive)value- value array to take values from (other type)
-
set
Set range to given arrays value- Parameters:
rl- row lowerru- row upper (inclusive)value- value array to take values from (same type) offset by rl.
-
set
Set range to given arrays value with an offset into other array- Parameters:
rl- row lowerru- row upper (inclusive)value- value array to take values fromrlSrc- the offset into the value array to take values from
-
setNz
Set non default values from the value array given- Parameters:
value- array of same type and length
-
setNz
Set non default values in the range from the value array given- Parameters:
rl- row startru- row upper inclusivevalue- value array of same type
-
setFromOtherTypeNz
Set non default values from the value array given- Parameters:
value- array of other type
-
setFromOtherTypeNz
Set non default values in the range from the value array given- Parameters:
rl- row startru- row end inclusivevalue- value array of different type
-
append
Append a string value to the current Array, this should in general be avoided, and appending larger blocks at a time should be preferred.- Parameters:
value- The value to append
-
append
Append a value of the same type of the Array. This should in general be avoided, and appending larger blocks at a time should be preferred.- Parameters:
value- The value to append
-
append
Append other array, if the other array is fitting in current allocated size use that allocated size, otherwise allocate new array to combine the other with this. This method should use the set range function, and should be preferred over the append single values.- Parameters:
other- The other array of same type to append to this.- Returns:
- The combined arrays.
-
slice
Slice out the sub range and return new array with the specified type. If the conversion fails fallback to normal slice.- Parameters:
rl- row startru- row end (not included)- Returns:
- A new array of sub range.
-
reset
public abstract void reset(int size) Reset the Array and set to a different size. This method is used to reuse an already allocated Array, without extra allocation. It should only be done in cases where the Array is no longer in use in any FrameBlocks.- Parameters:
size- The size to reallocate into.
-
getAsByteArray
public abstract byte[] getAsByteArray()Return the current allocated Array as a byte[], this is used to serialize the allocated Arrays out to the PythonAPI.- Returns:
- The array as bytes
-
getValueType
Get the current value type of this array.- Returns:
- The current value type.
-
analyzeValueType
Analyze the column to figure out if the value type can be refined to a better type. The return is in two parts, first the type it can be, second if it contains nulls.- Returns:
- A better or equivalent value type to represent the column, including null information.
-
analyzeValueType
Analyze the column to figure out if the value type can be refined to a better type. The return is in two parts, first the type it can be, second if it contains nulls.- Parameters:
maxCells- maximum number of cells to analyze- Returns:
- A better or equivalent value type to represent the column, including null information.
-
getFrameArrayType
Get the internal FrameArrayType, to specify the encoding of the Types, note there are more Frame Array Types than there is ValueTypes.- Returns:
- The FrameArrayType
-
getInMemorySize
public long getInMemorySize()Get in memory size, not counting reference to this object.- Returns:
- the size in memory of this object.
-
baseMemoryCost
public static long baseMemoryCost()Get the base memory cost of the Arrays allocation.- Returns:
- The base memory cost
-
getExactSerializedSize
public abstract long getExactSerializedSize()Get the exact serialized size on disk of this array.- Returns:
- The exact size on disk
-
getNulls
-
containsNull
public boolean containsNull()analyze if the array contains null values.- Returns:
- If the array contains null.
-
possiblyContainsNaN
public abstract boolean possiblyContainsNaN() -
changeType
Change type taking into consideration if the target type must be able to contain Null.- Parameters:
t- The target typecontainsNull- If the target should be able to contain null- Returns:
- The changed type array.
-
changeTypeWithNulls
-
changeTypeWithNulls
-
changeTypeWithNulls
-
changeType
Change the allocated array to a different type. If the type is the same a deep copy is returned for safety.- Parameters:
t- The type to change to- Returns:
- A new column array.
-
changeType
Change type by moving this arrays value into the given ret array.- Parameters:
ret- The Array to put this arrays values into- Returns:
- The ret array given
-
changeType
Put the changed value types into the given ret array inside the range specified.- Parameters:
ret- The Array to put this arrays values intorl- inclusive lower boundru- exclusive upper bound- Returns:
- The ret array given.
-
getMinMaxLength
Get the minimum and maximum length of the contained values as string type.- Returns:
- A Pair of first the minimum length, second the maximum length
-
fill
fill the entire array with specific value.- Parameters:
val- the value to fill with.
-
fill
fill the entire array with specific value.- Parameters:
val- the value to fill with.
-
isShallowSerialize
public abstract boolean isShallowSerialize()analyze if this array can be shallow serialized. to allow caching without modification.- Returns:
- boolean saying true if shallow serialization is available
-
isEmpty
public abstract boolean isEmpty()Get if this array is empty, aka filled with empty values.- Returns:
- boolean saying true if empty
-
select
Slice out the specified indices and return the sub array.- Parameters:
indices- The indices to slice out- Returns:
- the sliced out indices in an array format
-
select
Slice out the true indices in the select input and return the sub array.- Parameters:
select- a boolean vector specifying what to selectnTrue- number of true values inside select- Returns:
- the sliced out indices in an array format
-
findEmpty
public final void findEmpty(boolean[] select) Find the empty rows, it is assumed that the input is to be only modified to set variables to true.- Parameters:
select- Modify this to true in indexes that are not empty.
-
isNotEmpty
public abstract boolean isNotEmpty(int i) -
findEmptyInverse
public void findEmptyInverse(boolean[] select) Find the filled rows, it is assumed that the input i to be only modified to set variables to true;- Parameters:
select- modify this to true in indexes that are empty.
-
clone
Overwrite of the java internal clone function for arrays, return a clone of underlying data that is mutable, (not immutable data.) Immutable data is dependent on the individual allocated arrays- Returns:
- A clone
-
toString
-
hashDouble
public abstract double hashDouble(int idx) Hash the given index of the array. It is allowed to return NaN on null elements.- Parameters:
idx- The index to hash- Returns:
- The hash value of that index.
-
getIterator
-
equals
-
extractDouble
public double[] extractDouble(double[] ret, int rl, int ru) Extract the sub array into the ret array as doubles. The ret array is filled from - rl, meaning that the ret array should be of length ru - rl.- Parameters:
ret- The array to returnrl- The row to start atru- The row to end at (not inclusive.)- Returns:
- The ret array given as argument
-
equals
Equals operation on arrays.- Parameters:
other- The other array to compare to.- Returns:
- True if the arrays are equivalent.
-
statistics
Get the compression statistics of this array allocation.- Parameters:
nSamples- The number of sample elements suggested (not forced) to be used.- Returns:
- The compression statistics of this array.
-
minMax
public double[] minMax()Get the minimum and maximum double value of this array. Note that we ignore NaN Values.- Returns:
- The min and max in index 0 and 1 of the array.
-
minMax
public double[] minMax(int l, int u) Get the minimum and maximum double value of a specific sub part of this array. Note that we ignore NaN Values.- Parameters:
l- The lower index to search fromu- The upper index to end at (not inclusive)- Returns:
- The min and max in index 0 and 1 of the array in the range.
-
setM
Set the index i in the map given based on the mapping provided. The map should be guaranteed to contain all unique values.- Parameters:
map- A map containing all unique values of this arraym- The MapToData to set the value part of the Map fromi- The index to set in m
-
setM
Set the index i in the map given based on the mapping provided. The map should be guaranteed to contain all unique values except null. Therefore in case of null we set the provided si value.- Parameters:
map- A map containing all unique values of this arraysi- The default value to use in m if this Array contains null at index im- The MapToData to set the value part of the Map fromi- The index to set in m
-