public final class DoubleUtils extends Object
double
and int
.Modifier and Type | Class and Description |
---|---|
static interface |
DoubleUtils.ifelse
Return a value with the same shape as
test which is filled with
elements selected from either yes or no depending on
whether the element of test is true or false . |
static class |
DoubleUtils.RoundingScheme
the available schemes to round a number
|
static interface |
DoubleUtils.which
Decide whether x satisfies the
boolean test. |
Modifier and Type | Field and Description |
---|---|
static String |
CSV_SEPARATOR
The default separator for CSV file parsing.
|
Modifier and Type | Method and Description |
---|---|
static double |
absoluteError(double x1,
double x0)
Compute the absolute difference between
x1 and x0 . |
static double |
bound(double value,
double lower,
double upper)
Bounds a given value by a given range.
|
static double[] |
collection2DoubleArray(Collection<? extends Number> numbers)
Convert a collection of numbers to a
double array. |
static int[] |
collection2IntArray(Collection<Integer> integers)
Convert a collection of
Integer s to an int array. |
static long[] |
collection2LongArray(Collection<Long> integers)
Convert a collection of
Long s to a long array. |
static int |
compare(double d1,
double d2,
double epsilon)
Compares two
double s up to a precision. |
static double[] |
concat(double[]... arr)
Concatenate an array of arrays into one array.
|
static double[][] |
copy2D(double[][] raw)
Copies a 2D array.
|
static double[] |
cumsum(double[] arr)
Gets the cumulative sums of the elements in an array.
|
static int[] |
cumsum(int[] arr)
Gets the cumulative sums of the elements in an array.
|
static double[] |
diff(double[] arr)
Gets the first differences of an array.
|
static double[][] |
diff(double[][] arr)
Gets the first differences of an array of vectors.
|
static double[][] |
diff(double[][] arr,
int lag,
int order)
Gets the lagged and iterated differences of vectors.
|
static double[] |
diff(double[] arr,
int lag,
int order)
Gets the lagged and iterated differences.
|
static int[] |
doubleArray2intArray(double... arr)
Convert a
double array to an int array, rounding down if
necessary. |
static List<Double> |
doubleArray2List(double... arr)
Convert a
double array to a list. |
static double |
doubleMod(double x,
double y)
Double modulo, analogous to x % y when x and y are ints.
|
static boolean |
equal(double[][] d1,
double[][] d2,
double epsilon)
Check if two 2D arrays,
double[][] , are close enough, hence
equal, entry-by-entry. |
static boolean |
equal(double[] d1,
double[] d2,
double epsilon)
Check if two
double arrays are close enough, hence equal,
entry-by-entry. |
static boolean |
equal(double d1,
double d2,
double epsilon)
Check if two
double s are close enough, hence equal. |
static boolean |
equal(int[] d1,
int[] d2)
Check if two
int arrays, int[] , are equal,
entry-by-entry. |
static double[] |
foreach(double[] doubles,
UnivariateRealFunction f)
Apply a univariate function f to each element in an array.
|
static boolean |
hasDuplicate(double[] arr,
double epsilon)
Check if a
double array contains any duplicates. |
static boolean |
hasZero(double[] d,
double epsilon)
Check if a
double array has any 0. |
static double[] |
ifelse(double[] arr,
DoubleUtils.ifelse selection)
Return a value with the same shape as
test which is filled with
elements selected from either yes or no depending on
whether the element of test is true or false . |
static double[] |
intArray2doubleArray(int... arr)
Convert an
int array to a double array. |
static List<Integer> |
intArray2List(int[] arr)
Convert an
int array to a list. |
static boolean |
isAllZeros(double[] d,
double epsilon)
Check if a
double array contains only 0s, entry-by-entry. |
static boolean |
isNegative(double d,
double epsilon)
Check if
d is negative. |
static boolean |
isNumber(double x)
Check if a
double is a number, i.e., it is not ∞ or
NaN . |
static boolean |
isPositive(double d,
double epsilon)
Check if
d is positive. |
static boolean |
isPow2(int n)
Check if an integer is a power of 2.
|
static boolean |
isZero(double d,
double epsilon)
Check if
d is zero. |
static void |
leftShift(double... arr)
Perform a in-memory left-shift (by 1 cell} to an array.
|
static void |
leftShift(double[] arr,
int k)
Perform a in-memory right-shift (by
k cells} to an array. |
static double[] |
leftShiftCopy(double... arr)
Get a left shifted (by 1 cell) copy of an array.
|
static double[] |
leftShiftCopy(double[] arr,
int k)
Get a left shifted (by
k cells) copy of an array. |
static int |
maxIndex(boolean moveOnTies,
int from,
int to,
double... doubles)
Get the index of the maximum of the values, skipping
Double.NaN . |
static int |
maxIndex(double... doubles)
Get the index of the maximum of the values, skipping
Double.NaN . |
static int |
minIndex(boolean moveOnTies,
int from,
int to,
double... doubles)
Get the index of the minimum of the values, skipping
Double.NaN . |
static int |
minIndex(double... doubles)
Get the index of the minimum of the values, skipping
Double.NaN . |
static double[] |
noNaN(double[] doubles)
Remove the
NaN from an array. |
static int[] |
order(double[] arr)
Returns a permutation which rearranges its first argument into
ascending or descending order.
|
static int[] |
order(double[] arr,
boolean ascending)
Returns a permutation which rearranges its first argument into
ascending or descending order.
|
static double[] |
readCSV1d(InputStream stream)
Read a single-column CSV file (output by
write.csv from R) into a
1-D double array. |
static double[] |
readCSV1d(InputStream stream,
boolean hasIndex,
boolean hasHeading)
Read a single-column CSV file (output by
write.csv from R) into a
1-D double array. |
static double[] |
readCSV1d(InputStream stream,
boolean hasIndex,
boolean hasHeading,
String separator)
Read a single-column CSV file (output by
write.csv from R) into a
1-D double array, with a given separator which overrides the
default separator . |
static double[] |
readCSV1d(String fileName)
Read a single-column CSV file (output by
write.csv from R) into a
1-D double array. |
static double[] |
readCSV1d(String fileName,
boolean hasIndex,
boolean hasHeading)
Read a single-column CSV file (output by
write.csv from R) into a
1-D double array. |
static double[] |
readCSV1d(String fileName,
boolean hasIndex,
boolean hasHeading,
String separator)
Read a single-column CSV file (output by
write.csv from R) into a
1-D double array, with a given separator which overrides the
default separator . |
static double[][] |
readCSV2d(InputStream stream)
Read a multi-column CSV stream (output by
write.csv from R) into
a 2-D double array. |
static double[][] |
readCSV2d(InputStream stream,
boolean hasIndex,
boolean hasHeading)
Read a multi-column CSV stream (output by
write.csv from R) into
a 2-D double array. |
static double[][] |
readCSV2d(InputStream stream,
boolean hasIndex,
boolean hasHeading,
String separator)
Read a multi-column CSV stream (output by
write.csv from R) into
a 2-D double array, with a given separator which overrides the
default separator . |
static double[][] |
readCSV2d(String fileName)
Read a multi-column CSV file (output by
write.csv from R) into a
2-D double array. |
static double[][] |
readCSV2d(String fileName,
boolean hasIndex,
boolean hasHeading)
Read a multi-column CSV file (output by
write.csv from R) into a
2-D double array. |
static double[][] |
readCSV2d(String fileName,
boolean hasIndex,
boolean hasHeading,
String separator)
Read a multi-column CSV file (output by
write.csv from R) into a
2-D double array, with a given separator which overrides the
default separator . |
static double |
relativeError(double x1,
double x0)
Compute the relative error for {x1, x0}.
|
static double[] |
rep(double value,
int times)
Generates an array of
double s of repeated values. |
static int[] |
rep(int value,
int times)
Generates an array of
int s of repeated values. |
static void |
reverse(double... arr)
Reverse a
double array. |
static void |
reverse(int... arr)
Reverse an
int array. |
static double[] |
reverseCopy(double... arr)
Get a reversed copy of a
double array. |
static int[] |
reverseCopy(int... arr)
Get a reversed copy of a
int array. |
static void |
reverseRange(double[] array,
int fromIndex,
int toIndex)
Reverses a range of elements in an array.
|
static void |
rightShift(double... arr)
Perform a in-memory right-shift (by 1 cell} to an array.
|
static void |
rightShift(double[] arr,
int k)
Perform a in-memory right-shift (by
k cells} to an array. |
static double[] |
rightShiftCopy(double... arr)
Get a right shifted (by 1 cell) copy of an array.
|
static double[] |
rightShiftCopy(double[] arr,
int k)
Get a right shifted (by
k cells) copy of an array. |
static double |
round(double d,
DoubleUtils.RoundingScheme scheme)
Round up or down a number to an integer.
|
static double |
round(double d,
int scale)
Round a number to the precision specified.
|
static double[] |
select(double[] arr,
DoubleUtils.which test)
Select the array elements which satisfy the
boolean test. |
static int[] |
select(int[] arr,
DoubleUtils.which test)
Select the array elements which satisfy the
boolean test. |
static double[] |
seq(double from,
double to,
double inc)
Generates a sequence of
double s from from up to
to with increments inc . |
static double[] |
seq(double from,
double to,
int n)
Generate a sequence of
n equi-spaced double values, from
start to end (inclusive). |
static double[] |
seq(int n,
double start,
double inc)
Generate a sequence of
double values with a given start value and
a given constant increment. |
static int[] |
seq(int from,
int to)
Generates a sequence of
int s from from up to to
with increments 1. |
static int[] |
seq(int from,
int to,
int inc)
Generates a sequence of
int s from from up to to
with increments inc . |
static int[] |
shellsort(double... arr)
Sort an array using Shell sort.
|
static double[] |
subarray(double[] arr,
int[] indices)
Get a sub-array of the original array with the given indices.
|
static int[] |
subarray(int[] arr,
int[] indices)
Get a sub-array of the original array with the given indices.
|
static double[] |
toPrimitive(Double[] arr)
Convert a
Double array to a primitive double array. |
static String |
toString(double... arr)
Print out numbers to a string.
|
static String |
toString(double[][] arr)
Print out a 2D array,
double[][] to a string. |
static int[] |
which(double[] arr,
DoubleUtils.which test)
Get the indices of the array elements which satisfy the
boolean
test. |
static int[] |
which(int[] arr,
DoubleUtils.which test)
Get the indices of the array elements which satisfy the
boolean
test. |
public static final String CSV_SEPARATOR
public static int compare(double d1, double d2, double epsilon)
double
s up to a precision. This implementation is
preferred to Double.compare(double, double)
because our
implementation returns 0 (equality), i.e.,
DoubleUtils.compare(0.0, -0.0)
returns 0
;
Double.compare(0.0, -0.0)
returns 1
.d1
- a double
d2
- a double
epsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0d1
is close enough to d2
; 1 if d1 >
d2; -1 if d1 ≤ d2public static boolean isZero(double d, double epsilon)
d
is zero.d
- a double
epsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if d
is close enough to 0public static boolean isPositive(double d, double epsilon)
d
is positive.d
- a double
epsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if d
is bigger than 0 by epsilon
public static boolean isNegative(double d, double epsilon)
d
is negative.d
- a double
epsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if d
is smaller than 0 by epsilon
public static boolean equal(double d1, double d2, double epsilon)
double
s are close enough, hence equal.d1
- a double
d2
- a double
epsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if d1
is close enough to d2
,
false
otherwisepublic static boolean equal(double[] d1, double[] d2, double epsilon)
double
arrays are close enough, hence equal,
entry-by-entry.d1
- a double[]
d2
- a double[]
epsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if all entries in d1
are close enough to all
entries in d2
, false
otherwisepublic static boolean equal(double[][] d1, double[][] d2, double epsilon)
double[][]
, are close enough, hence
equal, entry-by-entry.d1
- a double[][]
d2
- a double[][]
epsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if all entries in d1
are close enough to all
entries in d2
, false
otherwisepublic static boolean equal(int[] d1, int[] d2)
int
arrays, int[]
, are equal,
entry-by-entry.d1
- an int
arrayd2
- an int
arraytrue
if all entries in d1
are the same as all
entries in d2
, false
otherwisepublic static int maxIndex(boolean moveOnTies, int from, int to, double... doubles)
Double.NaN
.moveOnTies
- true
if prefer the later one on tiesfrom
- the initial index of the range to be consideredto
- 1 after the last index of the range to be considereddoubles
- an array, double[]
public static int maxIndex(double... doubles)
Double.NaN
.doubles
- an array, double[]
public static int minIndex(boolean moveOnTies, int from, int to, double... doubles)
Double.NaN
.moveOnTies
- true
if prefer the later one on tiesfrom
- the initial index of the range to be consideredto
- 1 after the last index of the range to be considereddoubles
- an array, double[]
public static int minIndex(double... doubles)
Double.NaN
.doubles
- an array, double[]
public static double[] foreach(double[] doubles, UnivariateRealFunction f)
doubles
- an array, double[]
f
- a function to be applied to each elementpublic static double[] concat(double[]... arr)
arr
- an array, double[]
public static void reverse(double... arr)
double
array.arr
- an array, double[]
public static void reverseRange(double[] array, int fromIndex, int toIndex)
array
- the arrayfromIndex
- the index of the first element (inclusive)toIndex
- the index of the last element (exclusive)public static double[] reverseCopy(double... arr)
double
array.arr
- an array, double[]
public static void reverse(int... arr)
int
array.arr
- an array, int[]
public static int[] reverseCopy(int... arr)
int
array.arr
- an array, int[]
public static double[] leftShiftCopy(double... arr)
arr
- an array, double[]
public static double[] leftShiftCopy(double[] arr, int k)
k
cells) copy of an array. The rightmost
elements are filled by zeros.arr
- an array, double[]
k
- the number of cells to be shiftedpublic static void leftShift(double... arr)
arr
- an array, double[]
public static void leftShift(double[] arr, int k)
k
cells} to an array. The
leftmost elements are filled by zeros. No temporary array will be created
during the operation.arr
- an array, double[]
k
- the number of cells to be shiftedpublic static double[] rightShiftCopy(double... arr)
arr
- an array, double[]
public static double[] rightShiftCopy(double[] arr, int k)
k
cells) copy of an array. The leftmost
elements are filled by zeros.arr
- an array, double[]
k
- the number of cells to be shiftedpublic static void rightShift(double... arr)
arr
- an array, double[]
public static void rightShift(double[] arr, int k)
k
cells} to an array. The
leftmost elements are filled by zeros. No temporary array will be created
during the operation.arr
- an array, double[]
k
- the number of cells to be shiftedpublic static int[] shellsort(double... arr)
arr
- an array, double[]
arr
is sorted in ascending orderpublic static boolean isAllZeros(double[] d, double epsilon)
double
array contains only 0s, entry-by-entry.d
- a double
arrayepsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if all entries in d
are close enough to 0,
false
otherwisepublic static boolean hasZero(double[] d, double epsilon)
double
array has any 0.d
- a double
arrayepsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if an entry in d
are close enough to 0,
false
otherwisepublic static boolean isNumber(double x)
double
is a number, i.e., it is not ∞
or
NaN
.x
- a double
true
if x is not ∞
or NaN
public static boolean isPow2(int n)
n
- an integertrue
if n is a power of 2.public static boolean hasDuplicate(double[] arr, double epsilon)
double
array contains any duplicates.arr
- a double
arrayepsilon
- a precision parameter: when a number |x| ≤ ε,
it is considered 0true
if there is a duplicatepublic static int[] doubleArray2intArray(double... arr)
double
array to an int
array, rounding down if
necessary.arr
- a double
arrayint
arraypublic static double[] intArray2doubleArray(int... arr)
int
array to a double
array.arr
- an int
arraydouble
arraypublic static double[] collection2DoubleArray(Collection<? extends Number> numbers)
double
array.numbers
- the collection of numbersdouble
array containing the numbers in the input
collectionpublic static List<Double> doubleArray2List(double... arr)
double
array to a list.arr
- a double
arraypublic static int[] collection2IntArray(Collection<Integer> integers)
Integer
s to an int
array.integers
- a collection of integersint
array of the integerspublic static long[] collection2LongArray(Collection<Long> integers)
Long
s to a long
array.integers
- a collection of long integerslong
array of the long integerspublic static List<Integer> intArray2List(int[] arr)
int
array to a list.arr
- an int
arraypublic static double[] toPrimitive(Double[] arr)
Double
array to a primitive double
array.
Double.NaN
is used when an input Double
instance is
null
.arr
- a Double
arraypublic static double round(double d, DoubleUtils.RoundingScheme scheme)
d
- a numberscheme
- the rounding schemedouble
public static double round(double d, int scale)
d
- a numberscale
- the number of decimal pointspublic static double absoluteError(double x1, double x0)
x1
and x0
. This
function is symmetric.
ε = | x1 - x0 |
x1
- x1
x0
- x0
public static double relativeError(double x1, double x0)
ε = | (x1 - x0) / x0 | = | x1/x0 - 1 |
x1
- x1
x0
- x0
public static String toString(double... arr)
arr
- a double
arrayString
representation of the numberspublic static String toString(double[][] arr)
double[][]
to a string.arr
- a double[][]
public static double[] rep(double value, int times)
double
s of repeated values.value
- the repeated valuetimes
- the length of the arraypublic static int[] rep(int value, int times)
int
s of repeated values.value
- the repeated valuetimes
- the length of the arraypublic static double[] seq(int n, double start, double inc)
double
values with a given start value and
a given constant increment.n
- the total number of valuesstart
- the first valueinc
- the incrementpublic static double[] seq(double from, double to, double inc)
double
s from from
up to
to
with increments inc
. The last number in the sequence
is smaller than or equal to to
for positive inc
. The last
number in the sequence is bigger than or equal to to
for negative
inc
.from
- the first number in the sequenceto
- the bound of the sequenceinc
- the incrementdouble
spublic static double[] seq(double from, double to, int n)
n
equi-spaced double
values, from
start
to end
(inclusive).from
- the first valueto
- the last valuen
- the total number of valuesn
equi-spaced valuespublic static int[] seq(int from, int to, int inc)
int
s from from
up to to
with increments inc
. The last number in the sequence is smaller
than or equal to to
for positive inc
. The last number in
the sequence is bigger than or equal to to
for negative
inc
.from
- the first number in the sequenceto
- the bound of the sequenceinc
- the incrementint
spublic static int[] seq(int from, int to)
int
s from from
up to to
with increments 1. That is, [from, to], inclusively.from
- the first number in the sequenceto
- the bound of the sequenceint
spublic static double[] diff(double[] arr, int lag, int order)
arr
- an array, double[]
lag
- an integer indicating which lag to useorder
- an integer indicating the order of the difference. This is
the number of times diff
is applied to the data. E.g.,
diff(x, 1, 2) = diff(diff(x, 1, 1), 1, 1)
.public static double[] diff(double[] arr)
arr
- an array, double[]
public static double[][] diff(double[][] arr, int lag, int order)
arr
- a double[][]
; row view; must not be jaggedlag
- an integer indicating which lag to useorder
- an integer indicating the order of the difference. This is
the number of times diff
is applied to the data. E.g.,
diff(x, 1, 2) = diff(diff(x, 1, 1), 1, 1)
.public static double[][] diff(double[][] arr)
arr
- a double[][]
; row view; must not be jaggedpublic static double[] cumsum(double[] arr)
arr
- an array, double[]
cumsum
public static int[] cumsum(int[] arr)
arr
- an array, int[]
cumsum
public static double[] ifelse(double[] arr, DoubleUtils.ifelse selection)
test
which is filled with
elements selected from either yes
or no
depending on
whether the element of test is true
or false
.arr
- an arrayselection
- the boolean
test to decide true
or
false
and return valuespublic static int[] which(double[] arr, DoubleUtils.which test)
boolean
test.arr
- an array. double[]
test
- the boolean
test to decide true
or
false
(which to select)public static int[] which(int[] arr, DoubleUtils.which test)
boolean
test.arr
- an array. int[]
test
- the boolean
test to decide true
or
false
(which to select)public static double[] select(double[] arr, DoubleUtils.which test)
boolean
test. R does
not have a 'select' function. The R-equivalent is
arr[which(...
]}.arr
- an array, double[]
test
- the boolean
test to determine which elements to be
selectedpublic static int[] select(int[] arr, DoubleUtils.which test)
boolean
test. R does
not have a 'select' function. The R-equivalent is
arr[which(...
]}.arr
- an array, int[]
test
- the boolean
test to determine which elements to be
selectedpublic static double[] noNaN(double[] doubles)
NaN
from an array.doubles
- an array, double[]
public static double[] subarray(double[] arr, int[] indices)
arr[indices]
.arr
- an array, double[]
indices
- an array of indices to selectarr[indices]
.public static int[] subarray(int[] arr, int[] indices)
arr[indices]
.arr
- an array, int[]
indices
- an array of indices to selectarr[indices]
.public static int[] order(double[] arr, boolean ascending)
order(...
}.arr
- an array, int[]
ascending
- true
if arranging elements in ascending order;
false if descending orderpublic static int[] order(double[] arr)
order(...
}.arr
- an array, int[]
public static double[][] readCSV2d(String fileName) throws IOException
write.csv
from R) into a
2-D double
array. By default, the CSV file contains both the
index column (as the first column) and the heading row (as the first
row), and use the default separator
.fileName
- the name of the CSV filedouble[][]
IOException
- when error has occurred while reading the filepublic static double[][] readCSV2d(String fileName, boolean hasIndex, boolean hasHeading) throws IOException
write.csv
from R) into a
2-D double
array. The default separator
is
used.fileName
- the name of the CSV filehasIndex
- whether or not the file contains an index columnhasHeading
- whether or not the file contains a heading rowdouble[][]
IOException
- when error has occurred while reading the filepublic static double[][] readCSV2d(String fileName, boolean hasIndex, boolean hasHeading, String separator) throws IOException
write.csv
from R) into a
2-D double
array, with a given separator which overrides the
default separator
.fileName
- the name of the CSV filehasIndex
- whether or not the file contains an index columnhasHeading
- whether or not the file contains a heading rowseparator
- the separatordouble[][]
IOException
- when error has occurred while reading the filepublic static double[][] readCSV2d(InputStream stream) throws IOException
write.csv
from R) into
a 2-D double
array. By default, the CSV file contains both the
index column (as the first column) and the heading row (as the first
row), and use the default separator
.stream
- the CSV input streamdouble[][]
IOException
- when error has occurred while reading the filepublic static double[][] readCSV2d(InputStream stream, boolean hasIndex, boolean hasHeading) throws IOException
write.csv
from R) into
a 2-D double
array. The default separator
is used.stream
- the CSV input streamhasIndex
- whether or not the file contains an index columnhasHeading
- whether or not the file contains a heading rowdouble[][]
IOException
- when error has occurred while reading the filepublic static double[][] readCSV2d(InputStream stream, boolean hasIndex, boolean hasHeading, String separator) throws IOException
write.csv
from R) into
a 2-D double
array, with a given separator which overrides the
default separator
.stream
- the CSV input streamhasIndex
- whether or not the file contains an index columnhasHeading
- whether or not the file contains a heading rowseparator
- the separatordouble[][]
IOException
- when error has occurred while reading the filepublic static double[] readCSV1d(String fileName) throws IOException
write.csv
from R) into a
1-D double
array. By default, the CSV file contains both the
index column (as the first column) and the heading row (as the first
row), and use the default separator
.fileName
- the name of the CSV filedouble[]
IOException
- when error has occurred while reading the filepublic static double[] readCSV1d(String fileName, boolean hasIndex, boolean hasHeading) throws IOException
write.csv
from R) into a
1-D double
array. The default separator
is
used.fileName
- the name of the CSV filehasIndex
- whether or not the file contains an index columnhasHeading
- whether or not the file contains a heading rowdouble[]
IOException
- when error has occurred while reading the filepublic static double[] readCSV1d(String fileName, boolean hasIndex, boolean hasHeading, String separator) throws IOException
write.csv
from R) into a
1-D double
array, with a given separator which overrides the
default separator
.fileName
- the name of the CSV filehasIndex
- whether or not the file contains an index columnhasHeading
- whether or not the file contains a heading rowseparator
- the separatordouble[]
IOException
- when error has occurred while reading the filepublic static double[] readCSV1d(InputStream stream) throws IOException
write.csv
from R) into a
1-D double
array. By default, the CSV file contains both the
index column (as the first column) and the heading row (as the first
row), and use the default separator
.stream
- the CSV input streamdouble[]
IOException
- when error has occurred while reading the filepublic static double[] readCSV1d(InputStream stream, boolean hasIndex, boolean hasHeading) throws IOException
write.csv
from R) into a
1-D double
array. The default separator
is
used.stream
- the CSV input streamhasIndex
- whether or not the file contains an index columnhasHeading
- whether or not the file contains a heading rowdouble[]
IOException
- when error has occurred while reading the filepublic static double[] readCSV1d(InputStream stream, boolean hasIndex, boolean hasHeading, String separator) throws IOException
write.csv
from R) into a
1-D double
array, with a given separator which overrides the
default separator
.stream
- the CSV input streamhasIndex
- whether or not the file contains an index columnhasHeading
- whether or not the file contains a heading rowseparator
- the separatordouble[]
IOException
- when error has occurred while reading the filepublic static double[][] copy2D(double[][] raw)
raw
- a 2D arraypublic static double doubleMod(double x, double y)
x
- a doubley
- a doublepublic static double bound(double value, double lower, double upper)
Math.min(Math.max(value, lower), upper)
value
- the original valuelower
- the lower bound of the rangeupper
- the upper bound of the rangeCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.