public class UtilFunctions extends Object
Modifier and Type | Field and Description |
---|---|
static long |
ADD_PRIME1 |
static HashSet<String> |
defaultNaString |
static int |
DIVIDE_PRIME |
static double |
DOUBLE_EPS |
Constructor and Description |
---|
UtilFunctions() |
Modifier and Type | Method and Description |
---|---|
static int |
compareTo(Types.ValueType vt,
Object in1,
Object in2) |
static int |
compareVersion(String version1,
String version2)
Compares two version strings of format x.y.z, where x is major,
y is minor, and z is maintenance release.
|
static long |
computeBlockIndex(long cellIndex,
int blockSize)
Computes the 1-based block index based on the global cell index and block size meta
data.
|
static long |
computeBlockNumber(int[] ix,
long[] dims,
int blen)
Calculates the number of the block this index refers to (basically a linearisation).
|
static int |
computeBlockSize(long len,
long blockIndex,
long blockSize)
Computes the actual block size based on matrix dimension, block index, and block size
meta data.
|
static int |
computeCellInBlock(long cellIndex,
int blockSize)
Computes the 0-based cell-in-block index based on the global cell index and block
size meta data.
|
static long |
computeCellIndex(long blockIndex,
int blockSize,
int cellInBlock)
Computes the global 1-based cell index based on the block index, block size meta data,
and specific 0-based in-block cell index.
|
static long[] |
computeNextTensorIndexes(TensorCharacteristics tc,
long[] ix)
Computes the next tensor indexes array.
|
static int |
computeNnz(BitSet a,
int ai,
int len) |
static int |
computeNnz(double[] a,
int ai,
int len) |
static int |
computeNnz(float[] a,
int ai,
int len) |
static int |
computeNnz(int[] a,
int ai,
int len) |
static int |
computeNnz(long[] a,
int ai,
int len) |
static long |
computeNnz(SparseBlock a,
int[] aix,
int ai,
int alen) |
static int |
computeNnz(String[] a,
int ai,
int len) |
static void |
computeSliceInfo(TensorCharacteristics tc,
long[] blockIx,
int[] outDims,
int[] offset)
Computes the slice dimensions and offsets for the block slice of another tensor with the size given by
TensorCharacteristics . |
static long[] |
computeTensorIndexes(TensorCharacteristics tc,
long blockIndex)
Computes the tensor indexes array given a blockIndex we ant to compute.
|
static boolean |
containsZero(double[] data,
int pos,
int len) |
static Types.ValueType[] |
copyOf(Types.ValueType[] schema1,
Types.ValueType[] schema2) |
static int |
countNonZeros(double[] data,
int pos,
int len) |
static Object |
doubleToObject(Types.ValueType vt,
double in) |
static Object |
doubleToObject(Types.ValueType vt,
double in,
boolean sparse) |
static String |
formatMemorySize(long arg)
Format a memory size with g/m/k quantifiers into its
number representation.
|
static int |
frequency(Types.ValueType[] schema,
Types.ValueType vt) |
static ArrayList<Integer> |
getAlignedBlockSizes(int len,
int k,
int align) |
static ArrayList<Integer> |
getBalancedBlockSizesDefault(int len,
int k,
boolean constK) |
static void |
getBlockBounds(TensorIndexes ix,
long[] dims,
int blen,
int[] lower,
int[] upper) |
static double |
getDouble(Object obj) |
static IndexRange |
getSelectedRangeForZeroOut(IndexedMatrixValue in,
int blen,
IndexRange indexRange) |
static IndexRange |
getSelectedRangeForZeroOut(Pair<Long,FrameBlock> in,
int blen,
IndexRange indexRange,
long lSrcRowIndex,
long lDestRowIndex) |
static int[] |
getSeqArray(int low,
int up,
int incr)
Obtain sequence array
|
static long |
getSeqLength(double from,
double to,
double incr) |
static long |
getSeqLength(double from,
double to,
double incr,
boolean check) |
static List<Integer> |
getSeqList(int low,
int up,
int incr)
Obtain sequence list
|
static int[] |
getSortedSampleIndexes(int range,
int sampleSize) |
static int[] |
getSortedSampleIndexes(int range,
int sampleSize,
long seed) |
static int |
intHashCode(int key1,
int key2) |
static int |
intHashCodeRobust(int key1,
int key2) |
static boolean |
isInBlockRange(MatrixIndexes ix,
int blen,
IndexRange ixrange) |
static boolean |
isInBlockRange(MatrixIndexes ix,
int blen,
long rl,
long ru,
long cl,
long cu) |
static boolean |
isInFrameBlockRange(Long ix,
int blen,
IndexRange ixrange) |
static boolean |
isInFrameBlockRange(Long ix,
int blen,
long rl,
long ru) |
static boolean |
isIntegerNumber(String str) |
static boolean |
isNonZero(Object obj) |
static int |
longHashCode(long key1) |
static int |
longHashCode(long key1,
long key2)
Returns the hash code for a long-long pair.
|
static int |
longHashCode(long key1,
long key2,
long key3)
Returns the hash code for a long-long-long triple.
|
static byte |
max(byte[] array) |
static Types.ValueType[] |
nCopies(int n,
Types.ValueType vt) |
static int |
nextIntPow2(int in) |
static double |
objectToDouble(Types.ValueType vt,
Object in) |
static Object |
objectToObject(Types.ValueType vt,
Object in) |
static Object |
objectToObject(Types.ValueType vt,
Object in,
boolean ignoreNull) |
static String |
objectToString(Object in) |
static String |
objectToString(Object in,
boolean ignoreNull)
Convert object to string
|
static long |
parseMemorySize(String arg)
Parses a memory size with optional g/m/k quantifiers into its
number representation.
|
static double |
parseToDouble(String str,
Set<String> isNan)
Safe double parsing including handling of NAs.
|
static int |
parseToInt(String str) |
static long |
parseToLong(String str) |
static long |
pow(int base,
int exp) |
static long |
prod(int[] arr) |
static long |
prod(int[] arr,
int off) |
static long |
prod(long[] arr) |
static String |
quote(String s) |
static int |
roundToNext(int val,
int factor) |
static Object |
stringToObject(Types.ValueType vt,
String in) |
static int |
toInt(double val) |
static int |
toInt(Object obj) |
static long |
toLong(double val) |
static long |
toMillis(String dateString) |
static String |
unquote(String s) |
public static final double DOUBLE_EPS
public static final long ADD_PRIME1
public static final int DIVIDE_PRIME
public static int intHashCode(int key1, int key2)
public static int intHashCodeRobust(int key1, int key2)
public static int longHashCode(long key1)
public static int longHashCode(long key1, long key2)
key1
- first long keykey2
- second long keypublic static int longHashCode(long key1, long key2, long key3)
key1
- first long keykey2
- second long keykey3
- third long keypublic static int nextIntPow2(int in)
public static long pow(int base, int exp)
public static long computeBlockIndex(long cellIndex, int blockSize)
cellIndex
- global cell indexblockSize
- block sizepublic static int computeCellInBlock(long cellIndex, int blockSize)
cellIndex
- global cell indexblockSize
- block sizepublic static long computeCellIndex(long blockIndex, int blockSize, int cellInBlock)
blockIndex
- block indexblockSize
- block sizecellInBlock
- 0-based cell-in-block indexpublic static int computeBlockSize(long len, long blockIndex, long blockSize)
len
- matrix dimensionblockIndex
- block indexblockSize
- block size metadatapublic static long[] computeNextTensorIndexes(TensorCharacteristics tc, long[] ix)
tc
- the tensor characteristicsix
- the tensor indexes array (will be changed)public static long[] computeTensorIndexes(TensorCharacteristics tc, long blockIndex)
UtilFunctions.computeNextTensorIndexes(TensorCharacteristics,long[])
.tc
- the tensor characteristicsblockIndex
- the number of the block ([0-tc.getNumBlocks()
[ valid)public static void computeSliceInfo(TensorCharacteristics tc, long[] blockIx, int[] outDims, int[] offset)
TensorCharacteristics
.tc
- tensor characteristics of the block to sliceblockIx
- the tensor block indexoutDims
- the slice dimension sizeoffset
- the offset where the slice should startpublic static long computeBlockNumber(int[] ix, long[] dims, int blen)
ix
- the dimensional indexesdims
- length of dimensionsblen
- length of blockspublic static ArrayList<Integer> getBalancedBlockSizesDefault(int len, int k, boolean constK)
public static ArrayList<Integer> getAlignedBlockSizes(int len, int k, int align)
public static boolean isInBlockRange(MatrixIndexes ix, int blen, long rl, long ru, long cl, long cu)
public static boolean isInFrameBlockRange(Long ix, int blen, long rl, long ru)
public static boolean isInBlockRange(MatrixIndexes ix, int blen, IndexRange ixrange)
public static boolean isInFrameBlockRange(Long ix, int blen, IndexRange ixrange)
public static IndexRange getSelectedRangeForZeroOut(IndexedMatrixValue in, int blen, IndexRange indexRange)
public static IndexRange getSelectedRangeForZeroOut(Pair<Long,FrameBlock> in, int blen, IndexRange indexRange, long lSrcRowIndex, long lDestRowIndex)
public static double parseToDouble(String str, Set<String> isNan)
str
- string to parse to doubleisNan
- collection of Nan string which if encountered should be parsed to nan valuepublic static int parseToInt(String str)
public static long parseToLong(String str)
public static int toInt(double val)
public static long toLong(double val)
public static int toInt(Object obj)
public static long getSeqLength(double from, double to, double incr)
public static long getSeqLength(double from, double to, double incr, boolean check)
public static List<Integer> getSeqList(int low, int up, int incr)
low
- lower bound (inclusive)up
- upper bound (inclusive)incr
- incrementpublic static int[] getSeqArray(int low, int up, int incr)
low
- lower bound (inclusive)up
- upper bound (inclusive)incr
- incrementpublic static int roundToNext(int val, int factor)
public static Object doubleToObject(Types.ValueType vt, double in)
public static Object doubleToObject(Types.ValueType vt, double in, boolean sparse)
public static Object stringToObject(Types.ValueType vt, String in)
public static double objectToDouble(Types.ValueType vt, Object in)
public static String objectToString(Object in, boolean ignoreNull)
in
- objectignoreNull
- If this flag has set, it will ignore null. This flag is mainly used in merge functionality to override data with "null" data.public static Object objectToObject(Types.ValueType vt, Object in)
public static Object objectToObject(Types.ValueType vt, Object in, boolean ignoreNull)
public static int compareTo(Types.ValueType vt, Object in1, Object in2)
public static int compareVersion(String version1, String version2)
version1
- first version stringversion2
- second version stringpublic static boolean isIntegerNumber(String str)
public static int[] getSortedSampleIndexes(int range, int sampleSize)
public static int[] getSortedSampleIndexes(int range, int sampleSize, long seed)
public static byte max(byte[] array)
public static long parseMemorySize(String arg)
arg
- memory size as readable stringpublic static String formatMemorySize(long arg)
arg
- byte count of memory sizepublic static double getDouble(Object obj)
public static boolean isNonZero(Object obj)
public static int computeNnz(double[] a, int ai, int len)
public static int computeNnz(float[] a, int ai, int len)
public static int computeNnz(long[] a, int ai, int len)
public static int computeNnz(int[] a, int ai, int len)
public static int computeNnz(BitSet a, int ai, int len)
public static int computeNnz(String[] a, int ai, int len)
public static long computeNnz(SparseBlock a, int[] aix, int ai, int alen)
public static Types.ValueType[] nCopies(int n, Types.ValueType vt)
public static int frequency(Types.ValueType[] schema, Types.ValueType vt)
public static Types.ValueType[] copyOf(Types.ValueType[] schema1, Types.ValueType[] schema2)
public static int countNonZeros(double[] data, int pos, int len)
public static boolean containsZero(double[] data, int pos, int len)
public static long prod(long[] arr)
public static long prod(int[] arr)
public static long prod(int[] arr, int off)
public static void getBlockBounds(TensorIndexes ix, long[] dims, int blen, int[] lower, int[] upper)
public static long toMillis(String dateString)
Copyright © 2020 The Apache Software Foundation. All rights reserved.