public class Utils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Utils.AtomicDoubleArray |
static class |
Utils.AtomicFloatArray |
static class |
Utils.AtomicIntArray |
static class |
Utils.AtomicLongArray |
static class |
Utils.ExpectedExceptionForDebug |
static class |
Utils.IcedArrayList<T extends Iced>
Simple wrapper around ArrayList with support for H2O serialization
|
static class |
Utils.IcedDouble |
static class |
Utils.IcedHashMap<K extends Iced,V extends Iced>
Simple wrapper around HashMap with support for H2O serialization
|
static class |
Utils.IcedInt |
static class |
Utils.IcedLong |
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern[] |
ILLEGAL_CHARACTERS
Java-string illegal characters which need to be escaped
|
static java.lang.String[] |
REPLACEMENTS |
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
add(byte[] a,
byte[] b) |
static double[][] |
add(double[][] a,
double[][] b) |
static double[] |
add(double[] a,
double[] b) |
static float[][] |
add(float[][] a,
float[][] b) |
static float[] |
add(float[] a,
float[] b) |
static int[][] |
add(int[][] a,
int[][] b) |
static int[] |
add(int[] a,
int[] b) |
static long[][] |
add(long[][] a,
long[][] b) |
static long[] |
add(long[] a,
long[] b) |
static double[][] |
append(double[][] a,
double[][] b) |
static double[] |
append(double[] a,
double e) |
static int[] |
append(int[] a,
int[] b) |
static long[][][] |
append(long[][][] a,
long[][] e) |
static java.lang.String[] |
append(java.lang.String[] a,
java.lang.String[] b) |
static <T> T[] |
append(T[] a,
T... b) |
static double |
approxExp(double x)
Fast approximate exp
|
static double |
approxInvSqrt(double x)
Fast approximate 1./sqrt
|
static float |
approxInvSqrt(float x)
Fast approximate 1./sqrt
|
static double |
approxLog(double x)
Fast approximate log for values greater than 1, otherwise exact
|
static double |
approxSqrt(double x)
Fast approximate sqrt
|
static float |
approxSqrt(float x)
Fast approximate sqrt
|
static float |
approxSumSquares(float[] a,
int from,
int to)
Approximate sumSquares
|
static double |
avg(double[] nums) |
static double |
avg(long[] nums) |
static java.lang.String |
className(java.lang.String path) |
static void |
clearFolder(java.io.File folder) |
static void |
clearFolder(java.lang.String folder) |
static void |
close(java.io.Closeable... closeable) |
static void |
close(java.net.Socket s) |
static int[][] |
compose(int[][] first,
int[][] second) |
static int[] |
compose(int[] first,
int[] transf) |
static boolean |
contains(int[] a,
int d) |
static boolean |
contains(java.lang.String[] names,
java.lang.String name) |
static boolean |
contains(java.lang.String s,
java.lang.CharSequence cs)
Returns true if given string contains at least on of character of
given sequence.
|
static java.lang.String[] |
createConfusionMatrixHeader(long[] xs,
java.lang.String[] ds) |
static int[] |
difference(int[] a,
int[] b) |
static double[] |
div(double[] nums,
double n) |
static float[] |
div(float[] nums,
float n) |
static float[] |
div(float[] nums,
int n) |
static java.lang.String[] |
domainUnion(java.lang.String[] a,
java.lang.String[] b)
Clever union of String arrays.
|
static float |
entropy(byte[] f) |
static boolean |
equalsWithinOneSmallUlp(double a,
double b) |
static boolean |
equalsWithinOneSmallUlp(float a,
float b)
Compare two numbers to see if they are within one ulp of the smaller decade.
|
static java.lang.String |
escapeJava(java.lang.String s)
Escape all " and \ characters to provide a proper Java-like string
Does not escape unicode characters.
|
static int[] |
filter(int[] values,
boolean[] filter,
int fcnt) |
static Key[] |
generateNumKeys(Key mk,
int num)
Generate given numbers of keys by suffixing key by given numbered suffix.
|
static Key[] |
generateNumKeys(Key mk,
int num,
java.lang.String delim) |
static Key |
generateShuffledKey(Key mk) |
static int |
get4(byte[] buf,
int off) |
static double |
get8d(byte[] buf,
int off) |
static java.util.Random |
getDeterRNG(long seed) |
static byte[] |
getFirstUnzipedBytes(Key k) |
static byte[] |
getFirstUnzipedBytes(Value v) |
static int |
getPoisson(double lambda,
java.util.Random rng)
Poisson-distributed RNG
|
static java.util.Random |
getRNG(long... seed) |
static java.lang.String |
getStackAsString(java.lang.Throwable t) |
static H2ORandomRNG.RNGKind |
getUsedRNGKind() |
static H2ORandomRNG.RNGType |
getUsedRNGType() |
static ParseDataset.Compression |
guessCompressionMethod(byte[] bits) |
static boolean |
hasNaNsOrInfs(double[] arr) |
static boolean |
isEmpty(int[] a) |
static boolean |
isInt(java.lang.String s) |
static java.lang.String |
join(char sep,
java.lang.Iterable it) |
static java.lang.String |
join(char sep,
java.lang.Object[] array) |
static <T> T[] |
join(T[] a,
T[] b) |
static double |
lnF(double what) |
static ValueArray |
loadAndParseKey(Key okey,
java.lang.String path) |
static ValueArray |
loadAndParseKey(java.lang.String path) |
static int[] |
mapping(int[] dom)
Returns a mapping of given domain to values (0, ...
|
static int |
maxIndex(float[] from) |
static int |
maxIndex(float[] from,
java.util.Random rand) |
static int |
maxIndex(int[] from) |
static int |
maxIndex(int[] from,
java.util.Random rand)
Returns the index of the largest value in the array.
|
static double |
maxValue(double[] from) |
static float |
maxValue(float[] from) |
static long |
maxValue(long[] from) |
static int |
minIndex(float[] from) |
static int |
minIndex(int[] from) |
static float |
minValue(float[] from) |
static long |
minValue(long[] from) |
static double[] |
mult(double[] nums,
double n) |
static float[] |
mult(float[] nums,
float n) |
static int |
numInts(java.lang.String... a)
Returns number of strings which represents a number.
|
static byte[] |
or(byte[] a,
byte[] b) |
static int[] |
or(int[] a,
int[] b) |
static java.lang.String |
p2d(double d) |
static java.lang.String |
p5d(double d) |
static int[][] |
pack(int[] values,
boolean[] usemap) |
static int[] |
partitione(int len,
float[] ratio)
Divide given size into partitions based on given ratios.
|
static long[] |
partitione(long len,
float[] ratio) |
static java.lang.String |
pprint(double[][] arr) |
static java.lang.String |
pprint(double[][] arr,
java.text.DecimalFormat dformat) |
static void |
printConfusionMatrix(java.lang.StringBuilder sb,
long[][] cm,
java.lang.String[] domain,
boolean html) |
static java.lang.String |
readConsole() |
static java.lang.String |
readFile(java.io.File file) |
static void |
readFile(java.io.File file,
java.io.OutputStream out) |
static int[] |
remove(int[] a,
int i) |
static <T> T[] |
remove(T[] a,
int i) |
static java.lang.StringBuilder |
replace(java.lang.StringBuilder sb,
java.lang.CharSequence from,
java.lang.CharSequence to)
Replace given characters in a given string builder.
|
static java.lang.String |
sampleToString(double[] val,
int max) |
static java.lang.String |
sampleToString(int[] val,
int max) |
static int[] |
seq(int start,
int stop)
Generates sequence (start, stop) of integers: (start, start+1, ...., stop-1)
|
static int |
set4(byte[] buf,
int off,
int x) |
static int |
set8d(byte[] buf,
int off,
double d) |
static void |
setUsedRNGKind(H2ORandomRNG.RNGKind kind) |
static void |
setUsedRNGType(H2ORandomRNG.RNGType rngType) |
static int[] |
shuffleArray(int[] a,
int n,
int[] result,
long seed,
int startIndex)
Extract a shuffled array of integers
|
static void |
shuffleArray(long[] a,
long seed) |
static float[] |
sortAccording(float[] ary,
java.lang.Integer[] sortOrder)
Create a new sorted array according to given sort order
|
static int[] |
sortAccording(int[] ary,
java.lang.Integer[] sortOrder) |
static java.lang.String[] |
sortAccording(java.lang.String[] ary,
java.lang.Integer[] sortOrder) |
static void |
sortAccording2(boolean[] ary,
java.lang.Integer[] sortOrder)
Sort given array according given sort order.
|
static void |
sortAccording2(int[] ary,
java.lang.Integer[] sortOrder)
Sort given array according given sort order.
|
static void |
sortWith(int[] ary,
int[] ary2)
Sort two arrays - the second one is sorted according the first one.
|
static <T> T[] |
subarray(T[] a,
int off,
int len) |
static double |
sum(double[] from) |
static float |
sum(float[] from) |
static int |
sum(int[] from) |
static long |
sum(long[] from) |
static float |
sumSquares(float[] a) |
static float |
sumSquares(float[] a,
int from,
int to) |
static java.io.File |
tmp()
Returns the system temporary folder, e.g.
|
static int[] |
toInt(java.lang.String[] a,
int off,
int len) |
static java.lang.String[] |
toString(int[] dom) |
static java.lang.String[] |
toString(long[] dom) |
static java.lang.String[] |
toStringMap(int first,
int last) |
static int[] |
union(int[] a,
int[] b)
Returns a union of given sorted arrays.
|
static java.lang.String[] |
union(java.lang.String[] a,
java.lang.String[] b,
boolean lexo)
Union of given String arrays.
|
static java.lang.String[] |
union(java.lang.String[] a,
java.lang.String[] b,
int aoff,
int alen,
int boff,
int blen,
boolean lexo) |
static int[] |
unpackInts(long... longs) |
static byte[] |
unzipBytes(byte[] bs,
ParseDataset.Compression cmp) |
static java.io.File |
writeFile(java.io.File file,
java.lang.String content) |
static java.io.File |
writeFile(java.lang.String content) |
static void |
writeFileAndClose(java.io.File file,
java.io.InputStream in) |
public static final java.util.regex.Pattern[] ILLEGAL_CHARACTERS
public static final java.lang.String[] REPLACEMENTS
public static int maxIndex(int[] from, java.util.Random rand)
public static int maxIndex(float[] from, java.util.Random rand)
public static int maxIndex(int[] from)
public static int maxIndex(float[] from)
public static int minIndex(int[] from)
public static int minIndex(float[] from)
public static double maxValue(double[] from)
public static float maxValue(float[] from)
public static float minValue(float[] from)
public static long maxValue(long[] from)
public static long minValue(long[] from)
public static boolean equalsWithinOneSmallUlp(float a, float b)
a
- First numberb
- Second numberpublic static boolean equalsWithinOneSmallUlp(double a, double b)
public static double lnF(double what)
public static java.lang.String p2d(double d)
public static java.lang.String p5d(double d)
public static int set4(byte[] buf, int off, int x)
public static int get4(byte[] buf, int off)
public static int set8d(byte[] buf, int off, double d)
public static double get8d(byte[] buf, int off)
public static long sum(long[] from)
public static int sum(int[] from)
public static float sum(float[] from)
public static double sum(double[] from)
public static float sumSquares(float[] a)
public static float approxSumSquares(float[] a, int from, int to)
a
- Array with numbersfrom
- starting index (inclusive)to
- ending index (exclusive)public static float sumSquares(float[] a, int from, int to)
public static java.lang.String sampleToString(int[] val, int max)
public static java.lang.String sampleToString(double[] val, int max)
public static java.util.Random getDeterRNG(long seed)
public static void setUsedRNGKind(H2ORandomRNG.RNGKind kind)
public static java.util.Random getRNG(long... seed)
public static void setUsedRNGType(H2ORandomRNG.RNGType rngType)
public static H2ORandomRNG.RNGType getUsedRNGType()
public static H2ORandomRNG.RNGKind getUsedRNGKind()
public static float entropy(byte[] f)
public static int[] unpackInts(long... longs)
public static void shuffleArray(long[] a, long seed)
public static int[] shuffleArray(int[] a, int n, int[] result, long seed, int startIndex)
a
- input arrayn
- number of elements to extractresult
- array to store the results into (will be of size n)seed
- random number seedstartIndex
- offset into apublic static void close(java.io.Closeable... closeable)
public static void close(java.net.Socket s)
public static java.lang.String readConsole()
public static java.io.File writeFile(java.lang.String content)
public static java.io.File writeFile(java.io.File file, java.lang.String content)
public static void writeFileAndClose(java.io.File file, java.io.InputStream in)
public static java.lang.String readFile(java.io.File file)
public static void readFile(java.io.File file, java.io.OutputStream out)
public static java.lang.String join(char sep, java.lang.Object[] array)
public static java.lang.String join(char sep, java.lang.Iterable it)
public static byte[] or(byte[] a, byte[] b)
public static int[] or(int[] a, int[] b)
public static byte[] add(byte[] a, byte[] b)
public static int[] add(int[] a, int[] b)
public static int[][] add(int[][] a, int[][] b)
public static long[] add(long[] a, long[] b)
public static long[][] add(long[][] a, long[][] b)
public static float[] add(float[] a, float[] b)
public static float[][] add(float[][] a, float[][] b)
public static double[] add(double[] a, double[] b)
public static double[][] add(double[][] a, double[][] b)
public static double[][] append(double[][] a, double[][] b)
public static int[] append(int[] a, int[] b)
public static java.lang.String[] append(java.lang.String[] a, java.lang.String[] b)
public static double[] append(double[] a, double e)
public static long[][][] append(long[][][] a, long[][] e)
public static <T> T[] append(T[] a, T... b)
public static <T> T[] remove(T[] a, int i)
public static int[] remove(int[] a, int i)
public static <T> T[] subarray(T[] a, int off, int len)
public static void clearFolder(java.lang.String folder)
public static void clearFolder(java.io.File folder)
public static java.io.File tmp()
public static ValueArray loadAndParseKey(java.lang.String path)
public static ValueArray loadAndParseKey(Key okey, java.lang.String path)
public static byte[] getFirstUnzipedBytes(Key k)
public static byte[] getFirstUnzipedBytes(Value v)
public static ParseDataset.Compression guessCompressionMethod(byte[] bits)
public static byte[] unzipBytes(byte[] bs, ParseDataset.Compression cmp)
public static final boolean hasNaNsOrInfs(double[] arr)
public static java.lang.String getStackAsString(java.lang.Throwable t)
public static int[] mapping(int[] dom)
public static java.lang.String[] toString(long[] dom)
public static java.lang.String[] toString(int[] dom)
public static java.lang.String[] toStringMap(int first, int last)
public static int[] compose(int[] first, int[] transf)
public static int[][] compose(int[][] first, int[][] second)
public static java.lang.String pprint(double[][] arr)
public static java.lang.String pprint(double[][] arr, java.text.DecimalFormat dformat)
public static boolean isEmpty(int[] a)
public static boolean contains(int[] a, int d)
public static int[] difference(int[] a, int[] b)
public static int[] seq(int start, int stop)
public static java.lang.String className(java.lang.String path)
public static double avg(double[] nums)
public static double avg(long[] nums)
public static float[] div(float[] nums, int n)
public static float[] div(float[] nums, float n)
public static double[] div(double[] nums, double n)
public static float[] mult(float[] nums, float n)
public static double[] mult(double[] nums, double n)
public static final double approxSqrt(double x)
x
- public static final float approxSqrt(float x)
x
- public static final double approxInvSqrt(double x)
x
- public static final float approxInvSqrt(float x)
x
- public static final double approxExp(double x)
x
- public static final double approxLog(double x)
x
- public static java.lang.StringBuilder replace(java.lang.StringBuilder sb, java.lang.CharSequence from, java.lang.CharSequence to)
sb
- string builder containing a string to be modifiedfrom
- characters to replacedto
- replacement characterspublic static boolean contains(java.lang.String s, java.lang.CharSequence cs)
s
- stringcs
- a sequence of characterpublic static boolean contains(java.lang.String[] names, java.lang.String name)
public static java.lang.String escapeJava(java.lang.String s)
public static java.lang.String[] domainUnion(java.lang.String[] a, java.lang.String[] b)
a
- a set of stringsb
- a set of stringspublic static java.lang.String[] union(java.lang.String[] a, java.lang.String[] b, boolean lexo)
a
- first arrayb
- second arraylexo
- - true if domains are sorted in lexicographical order or false for numeric domainspublic static java.lang.String[] union(java.lang.String[] a, java.lang.String[] b, int aoff, int alen, int boff, int blen, boolean lexo)
public static int[] union(int[] a, int[] b)
public static <T> T[] join(T[] a, T[] b)
public static int numInts(java.lang.String... a)
public static boolean isInt(java.lang.String s)
public static int[] toInt(java.lang.String[] a, int off, int len)
public static int[] filter(int[] values, boolean[] filter, int fcnt)
public static int[][] pack(int[] values, boolean[] usemap)
public static int getPoisson(double lambda, java.util.Random rng)
lambda
- Lambda parameterpublic static float[] sortAccording(float[] ary, java.lang.Integer[] sortOrder)
public static java.lang.String[] sortAccording(java.lang.String[] ary, java.lang.Integer[] sortOrder)
public static int[] sortAccording(int[] ary, java.lang.Integer[] sortOrder)
public static void sortWith(int[] ary, int[] ary2)
public static void sortAccording2(int[] ary, java.lang.Integer[] sortOrder)
public static void sortAccording2(boolean[] ary, java.lang.Integer[] sortOrder)
public static java.lang.String[] createConfusionMatrixHeader(long[] xs, java.lang.String[] ds)
public static void printConfusionMatrix(java.lang.StringBuilder sb, long[][] cm, java.lang.String[] domain, boolean html)
public static final int[] partitione(int len, float[] ratio)
len
- number to be split into partitionsratio
- split ratio of each partitionpublic static final long[] partitione(long len, float[] ratio)
public static Key[] generateNumKeys(Key mk, int num)