Class RealProperties
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
allClose
(double[] src1, double[] src2) Checks if all data of two arrays are 'close'.static boolean
allClose
(double[] src1, double[] src2, double relTol, double absTol) Checks if all data of two arrays are 'close'.static int
argmax
(double... entries) Finds the index of the maximum value within a tensor.static int
argmaxAbs
(double... entries) Finds the first index of the maximum absolute value within a tensor.static int
argmin
(double... entries) Finds the index of the minimum value within a tensor.static int
argminAbs
(double... entries) Finds the index of the minimum absolute value within a tensor.static boolean
isFinite
(double[] src) Checks if all elements of a tensor are finite.static boolean
isInfinite
(double[] src) Checks if any of the elements of a tensor is infinite.static boolean
isNaN
(double[] src) Checks if any of the elements of a tensor contain aDouble.NaN
.static boolean
isNeg
(double[] entries) Checks if a tensor only contain negative values.static boolean
isOnes
(double[] src) Checks if this tensor only contains ones.static boolean
isPos
(double[] entries) Checks if a tensor only contain positive values.static boolean
isZeros
(double[] src) Checks if an array contains only zeros.static double
max
(double... entries) Computes the maximum value in a tensor.static double
maxAbs
(double... entries) Computes the maximum absolute value in a tensor.static double
maxAbs
(double[] src, int start, int n, int stride) Returns the maximum absolute value amongn
elements in the arraysrc
, starting at indexstart
and advancing bystride
for each subsequent element.static double
min
(double... entries) Computes the minimum value in a tensor.static double
minAbs
(double... entries) Computes the minimum absolute value in a tensor.static double
minAbs
(double[] src, int start, int n, int stride) Returns the minimum absolute value amongn
elements in the arraysrc
, starting at indexstart
and advancing bystride
for each subsequent element.
-
Method Details
-
isPos
public static boolean isPos(double[] entries) Checks if a tensor only contain positive values. If the tensor is sparse, only the non-zero data are considered.- Parameters:
entries
- Entries of the tensor in question.- Returns:
true
if the tensor contains only positive values;false
otherwise.
-
isNeg
public static boolean isNeg(double[] entries) Checks if a tensor only contain negative values. If the tensor is sparse, only the non-zero data are considered.- Parameters:
entries
- Entries of the tensor in question.- Returns:
true
if the tensor contains only negative values;false
otherwise.
-
isZeros
public static boolean isZeros(double[] src) Checks if an array contains only zeros.- Parameters:
src
- Array to check if it only contains zeros.- Returns:
- True if the
src
array contains only zeros.
-
allClose
public static boolean allClose(double[] src1, double[] src2) Checks if all data of two arrays are 'close'.- Parameters:
src1
- First array in comparison.src2
- Second array in comparison.- Returns:
- True if both arrays have the same length and all data are 'close' element-wise, i.e.
elements
a
andb
at the same positions in the two arrays respectively and satisfy|a-b| <= (1E-08 + 1E-05*|b|)
. Otherwise, returns false. - See Also:
-
allClose
public static boolean allClose(double[] src1, double[] src2, double relTol, double absTol) Checks if all data of two arrays are 'close'.- Parameters:
src1
- First array in comparison.src2
- Second array in comparison.- Returns:
- True if both arrays have the same length and all data are 'close' element-wise, i.e.
elements
a
andb
at the same positions in the two arrays respectively and satisfy|a-b| <= (absTol + relTol*|b|)
. Otherwise, returns false. - See Also:
-
isOnes
public static boolean isOnes(double[] src) Checks if this tensor only contains ones.- Parameters:
src
- Elements of the tensor.- Returns:
true
if this tensor only contains ones;false
otherwise.
-
isNaN
public static boolean isNaN(double[] src) Checks if any of the elements of a tensor contain aDouble.NaN
.- Parameters:
src
- Entries of the tensor.- Returns:
true
is any entry ofsrc
isDouble.NaN
;false
otherwise.
-
isFinite
public static boolean isFinite(double[] src) Checks if all elements of a tensor are finite.- Parameters:
src
- Entries of the tensor.- Returns:
false
is any entry ofsrc
is notfinite
. Otherwise, returnstrue
.
-
isInfinite
public static boolean isInfinite(double[] src) Checks if any of the elements of a tensor is infinite.- Parameters:
src
- Entries of the tensor.- Returns:
true
is any entry ofsrc
isinfinite
;false
otherwise.
-
min
public static double min(double... entries) Computes the minimum value in a tensor. Note, if the data array is empty, this method will return 0 allowing this method to be used for real sparse or dense tensors.- Parameters:
entries
- Entries of the tensor.- Returns:
- The minimum value in the tensor.
-
max
public static double max(double... entries) Computes the maximum value in a tensor. Note, if the data array is empty, this method will return 0 allowing this method to be used for real sparse or dense tensors.- Parameters:
entries
- Entries of the tensor.- Returns:
- The maximum value in the tensor.
-
minAbs
public static double minAbs(double... entries) Computes the minimum absolute value in a tensor. Note, if the data array is empty, this method will return 0 allowing this method to be used for real sparse or dense tensors.- Parameters:
entries
- Entries of the tensor.- Returns:
- The minimum absolute value in the tensor.
-
maxAbs
public static double maxAbs(double... entries) Computes the maximum absolute value in a tensor. Note, if the data array is empty, this method will return 0 allowing this method to be used for real sparse or dense tensors.- Parameters:
entries
- Entries of the tensor.- Returns:
- The maximum absolute value in the tensor.
-
argmin
public static int argmin(double... entries) Finds the index of the minimum value within a tensor.- Parameters:
entries
- The data of the tensor.- Returns:
- The index of the minimum values within
data
. Ifdata.length == 0
then -1 will be returned.
-
argmax
public static int argmax(double... entries) Finds the index of the maximum value within a tensor.- Parameters:
entries
- The data of the tensor.- Returns:
- The index of the maximum values within
data
. Ifdata.length == 0
then -1 will be returned.
-
argminAbs
public static int argminAbs(double... entries) Finds the index of the minimum absolute value within a tensor.- Parameters:
entries
- The data of the tensor.- Returns:
- The index of the minimum absolute values within
data
. Ifdata.length == 0
then -1 will be returned.
-
argmaxAbs
public static int argmaxAbs(double... entries) Finds the first index of the maximum absolute value within a tensor.- Parameters:
entries
- The data of the tensor.- Returns:
- The index of the maximum absolute values within
data
. Ifdata.length == 0
then -1 will be returned.
-
maxAbs
public static double maxAbs(double[] src, int start, int n, int stride) Returns the maximum absolute value among
n
elements in the arraysrc
, starting at indexstart
and advancing bystride
for each subsequent element.More formally, this method examines the elements at indices:
start
,start + stride
,start + 2*stride
, ...,start + (n-1)*stride
.This method will propagate
Double.NaN
values meaning if at least one element considered isDouble.NaN
the result of this method will beDouble.NaN
.This method may be used to find the maximum absolute value within the row or column of a
matrix
a
as follows:- Maximum absolute value within row
i
:maxAbs(a.data, factor, i*a.numCols, a.numCols, 1);
- Maximum absolute value within column
j
:maxAbs(a.data, factor, j, a.numRows, a.numRows);
- Parameters:
src
- The array to search for maximum absolute value within.start
- The starting index insrc
to search.n
- The number of elements to consider withinsrc1
.stride
- The gap (in indices) between consecutive elements to search withinsrc
.- Returns:
- If any element of
src
isDouble.NaN
then the result will beDouble.NaN
. - Otherwise, the maximum absolute value found among all elements considered in
src
.
- If any element of
- Throws:
IndexOutOfBoundsException
- If the specified range extends beyond the array bounds.
- Maximum absolute value within row
-
minAbs
public static double minAbs(double[] src, int start, int n, int stride) Returns the minimum absolute value among
n
elements in the arraysrc
, starting at indexstart
and advancing bystride
for each subsequent element.More formally, this method examines the elements at indices:
start
,start + stride
,start + 2*stride
, ...,start + (n-1)*stride
.This method will propagate
Double.NaN
values meaning if at least one element considered isDouble.NaN
the result of this method will beDouble.NaN
.This method may be used to find the minimum absolute value within the row or column of a
matrix
a
as follows:- Minimum absolute value within row
i
:maxAbs(a.data, i*a.numCols, a.numCols, 1);
- Minimum absolute value within column
j
:maxAbs(a.data, j, a.numRows, a.numRows);
- Parameters:
src
- The array to search for Minimum absolute value within.start
- The starting index insrc
to search.n
- The number of elements to consider withinsrc1
.stride
- The gap (in indices) between consecutive elements to search withinsrc
.- Returns:
- If
src.length == 0
thenDouble.POSITIVE_INFINITY
will be returned. - If any element of
src
isDouble.NaN
then the result will beDouble.NaN
. - Otherwise, the minimum absolute value found among all elements considered inn
src
.
- If
- Throws:
IndexOutOfBoundsException
- If the specified range extends beyond the array bounds.
- Minimum absolute value within row
-