Class ValidateParameters
java.lang.Object
org.flag4j.util.ValidateParameters
This utility class contains several methods for ensuring parameters satisfy some condition.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
ensureAllEqual
(int... values) Checks if a set of values are all equal.static void
ensureAllGreaterEq
(double threshold, double... values) Checks if a set of values is greater than or equal to a specified threshold.static void
ensureAllGreaterEq
(int threshold, int... values) Checks if a set of values is greater than or equal to a specified threshold.static void
ensureArrayLengthsEq
(int... lengths) Checks that all array lengths are equal.static void
ensureAxis2D
(int axis) Checks that an axis is a valid 2D axis.static void
ensureEqualShape
(Shape shape1, Shape shape2) Checks if twoShape
objects are equivalent.static void
ensureGreaterEq
(double threshold, double value, String name) Checks ifvalue >= threshold
.static void
ensureGreaterEq
(int threshold, int value) Checks ifvalues[i] >= threshold
for alli = 0, 1, ..., values.length
.static void
ensureInRange
(double value, double lowerBound, double upperBound, String paramName) Checks that a value is within the specified inclusive range.static void
ensureLessEq
(double threshold, double... values) Checks ifvalues[i] <= threshold
for alli = 0, 1, ..., values.length
.static void
ensureLessEq
(double threshold, double value, String name) Checks ifvalues <= threshold
.static void
ensureLessEq
(int threshold, int... values) Checks ifvalues[i] <= threshold
for alli = 0, 1, ..., values.length
.static void
ensureLessEq
(BigInteger threshold, int value, String name) Checks ifvalues <= threshold
.static void
ensureMatMultShapes
(Shape shape1, Shape shape2) Checks if twoShape
objects satisfy the requirements of matrix-matrix or matrix-vector multiplication.static void
ensureNonNegative
(int value) Checks ifvalue >= 0
.static void
ensureNonNegative
(int... values) Checks ifvalues
contains only non-negative values.static void
ensureNotEquals
(double a, double b) Checks that two values are not equal.static void
ensurePermutation
(int... axes) Checks that a list ofN
axis are a permutation of{0, 1, 2, ..., N-1}
.static void
ensurePermutation
(int[] axes, int n) Checks that a list of axis are a permutation of{0, 1, 2, ..., n-1}
.static void
ensurePositive
(int value) Checks ifvalue > 0
.static void
ensureRank
(Shape shape, int expRank) Checks that a shape has the specified rank.static void
ensureSquare
(Shape shape) Checks if a shape represents a square tensor.static void
ensureSquareMatrix
(int numRows, int numCols) Checks if a shape represents a square matrix.static void
ensureSquareMatrix
(Shape shape) Checks if a shape represents a square matrix.static void
ensureTotalEntriesEq
(double[][] arr1, double[] arr2) Checks if arrays have the same number of total data.static void
ensureTotalEntriesEq
(int[][] arr1, double[] arr2) Checks if arrays have the same number of total data.static void
ensureTotalEntriesEq
(Object[][] arr1, double[] arr2) Checks if arrays have the same number of total data.static void
ensureTotalEntriesEqual
(Shape shape1, Shape shape2) Checks that two shapes have the same total number of data.static void
ensureTrue
(boolean expr, String errMsg) Ensures that a boolean is true.static void
ensureValidAxes
(int rank, int... axes) Checks if all providedaxes
are valid with respect to the rank of the givenrank
.static void
ensureValidAxes
(Shape shape, int... axes) Checks if all providedaxes
are valid with respect to the rank of the givenshape
.static void
validateArrayIndices
(int upperBound, int... indices) Checks that a set of indices is within[0, upperBound)
.static void
validateTensorIndex
(Shape shape, int... index) Checks if the provided nD index is contained in a tensor defined by the givenshape
.static void
validateTensorIndices
(Shape shape, int[]... indices) Checks that a set of nD indices are valid indices for a tensor with the specified shape.
-
Method Details
-
ensureEqualShape
Checks if twoShape
objects are equivalent.- Parameters:
shape1
- First shape.shape2
- Second shape.- Throws:
TensorShapeException
- If shapes are not equivalent.
-
ensureMatMultShapes
Checks if twoShape
objects satisfy the requirements of matrix-matrix or matrix-vector multiplication.- Parameters:
shape1
- First shape.shape2
- Second shape.- Throws:
LinearAlgebraException
- If shapes do not satisfy the requirements of matrix-matrix or matrix-vector multiplication.
-
ensureArrayLengthsEq
public static void ensureArrayLengthsEq(int... lengths) Checks that all array lengths are equal.- Parameters:
lengths
- An array of array lengths.- Throws:
IllegalArgumentException
- If all lengths are not equal.
-
ensureTotalEntriesEqual
Checks that two shapes have the same total number of data.- Parameters:
shape1
- First shape to compare.shape2
- Second shape to compare.- Throws:
TensorShapeException
- If the two shapes do not have the same total number of data.
-
ensureTotalEntriesEq
Checks if arrays have the same number of total data.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total data.
-
ensureTotalEntriesEq
public static void ensureTotalEntriesEq(double[][] arr1, double[] arr2) Checks if arrays have the same number of total data.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total data.
-
ensureTotalEntriesEq
public static void ensureTotalEntriesEq(int[][] arr1, double[] arr2) Checks if arrays have the same number of total data.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total data.
-
ensureAllEqual
public static void ensureAllEqual(int... values) Checks if a set of values are all equal.- Parameters:
values
- Values to check if they are equal.- Throws:
IllegalArgumentException
- If any of the specified values are not equal.
-
ensureTrue
Ensures that a boolean is true.- Parameters:
expr
- Boolean to check the truth of.errMsg
- Error message in the case whereexpr == false
.
-
ensureNotEquals
public static void ensureNotEquals(double a, double b) Checks that two values are not equal.- Parameters:
a
- First value.b
- Second value.- Throws:
IllegalArgumentException
- Ifa==b
.
-
ensureAllGreaterEq
public static void ensureAllGreaterEq(double threshold, double... values) Checks if a set of values is greater than or equal to a specified threshold.- Parameters:
threshold
- Threshold value.values
- Values to compare against threshold.- Throws:
IllegalArgumentException
- If any of the values are less than the threshold.
-
ensureAllGreaterEq
public static void ensureAllGreaterEq(int threshold, int... values) Checks if a set of values is greater than or equal to a specified threshold.- Parameters:
threshold
- Threshold value.values
- Values to compare against threshold.- Throws:
IllegalArgumentException
- If any of the values are less than the threshold.
-
ensureGreaterEq
public static void ensureGreaterEq(int threshold, int value) Checks ifvalues[i] >= threshold
for alli = 0, 1, ..., values.length
.- Parameters:
threshold
- Threshold value.value
- Value to compare against threshold.- Throws:
IllegalArgumentException
- Ifvalues[i] < threshold
for anyi = 0, 1, ..., values.length
.
-
ensureGreaterEq
Checks ifvalue >= threshold
.- Parameters:
threshold
- Threshold value.value
- Values to compare against threshold.name
- Name of parameter.- Throws:
IllegalArgumentException
- Ifvalue < threshold
.
-
ensureLessEq
public static void ensureLessEq(double threshold, double... values) Checks ifvalues[i] <= threshold
for alli = 0, 1, ..., values.length
.- Parameters:
threshold
- Threshold value.values
- Values to compare against threshold.- Throws:
IllegalArgumentException
- Ifvalues[i] > threshold
for anyi = 0, 1, ..., values.length
.
-
ensureLessEq
public static void ensureLessEq(int threshold, int... values) Checks ifvalues[i] <= threshold
for alli = 0, 1, ..., values.length
.- Parameters:
threshold
- Threshold value.values
- Values to compare against threshold.- Throws:
IllegalArgumentException
-values[i] > threshold
for anyi = 0, 1, ..., values.length
.
-
ensureLessEq
Checks ifvalues <= threshold
.- Parameters:
threshold
- Threshold value.value
- Value to compare against threshold.name
- Name of parameter.- Throws:
IllegalArgumentException
- Ifvalues > threshold
.
-
ensureLessEq
Checks ifvalues <= threshold
.- Parameters:
threshold
- Threshold value.value
- Value to compare against threshold.name
- Name of parameter.- Throws:
IllegalArgumentException
- Ifvalues > threshold
.
-
ensurePositive
public static void ensurePositive(int value) Checks ifvalue > 0
.- Parameters:
value
- Value of interest.- Throws:
IllegalArgumentException
- Ifvalue <= 0
.- See Also:
-
ensureNonNegative
public static void ensureNonNegative(int value) Checks ifvalue >= 0
.- Parameters:
value
- Value of interest.- Throws:
IllegalArgumentException
- Ifvalue < 0
.- See Also:
-
ensureNonNegative
public static void ensureNonNegative(int... values) Checks ifvalues
contains only non-negative values.- Parameters:
values
- Values of interest.- Throws:
IllegalArgumentException
- If any element ofvalues
is negative.- See Also:
-
ensureSquareMatrix
Checks if a shape represents a square matrix.- Parameters:
shape
- Shape to check.- Throws:
LinearAlgebraException
- If the shape is not of rank 2 with equal rows and columns.
-
ensureSquare
Checks if a shape represents a square tensor.- Parameters:
shape
- Shape to check.- Throws:
TensorShapeException
- If all axes of the shape are not the same length.
-
ensureSquareMatrix
public static void ensureSquareMatrix(int numRows, int numCols) Checks if a shape represents a square matrix.- Parameters:
numRows
- Number of rows in the matrix.numCols
- Number of columns in the matrix.- Throws:
LinearAlgebraException
- If the shape is not of rank 2 with equal rows and columns.
-
ensureRank
Checks that a shape has the specified rank.- Parameters:
shape
- Shape to check.expRank
- Expected rank.- Throws:
LinearAlgebraException
- If the specified shape does not have the expected rank.
-
ensureAxis2D
public static void ensureAxis2D(int axis) Checks that an axis is a valid 2D axis. That is, either axis is 0 or 1.- Parameters:
axis
- Axis to check.- Throws:
IllegalArgumentException
- If the axis is not a valid 2D axis.
-
ensurePermutation
public static void ensurePermutation(int... axes) Checks that a list ofN
axis are a permutation of{0, 1, 2, ..., N-1}
.- Parameters:
axes
- List of axes of interest.- Throws:
IllegalArgumentException
- Ifaxis
is not a permutation of{0, 1, 2, ..., N-1}
.
-
ensurePermutation
public static void ensurePermutation(int[] axes, int n) Checks that a list of axis are a permutation of{0, 1, 2, ..., n-1}
.- Parameters:
axes
- List of axes of interest.n
- The length of the permutation.- Throws:
IllegalArgumentException
- Ifaxis
is not a permutation of{0, 1, 2, ..., n-1}
.
-
ensureInRange
public static void ensureInRange(double value, double lowerBound, double upperBound, String paramName) Checks that a value is within the specified inclusive range.- Parameters:
value
- Value of interest.lowerBound
- Lower bound of range (inclusive).upperBound
- Upper bound of range (inclusive).paramName
- Name of the parameter.- Throws:
IllegalArgumentException
- Ifvalue
is not within the range[lowerBound, upperBound]
-
validateArrayIndices
public static void validateArrayIndices(int upperBound, int... indices) Checks that a set of indices is within[0, upperBound)
.- Parameters:
upperBound
- Upper bound of range for indices (exclusive).indices
- Array of indices to check.- Throws:
IndexOutOfBoundsException
- If anyindices
are not within[0, upperBound)
.
-
validateTensorIndex
Checks if the provided nD index is contained in a tensor defined by the givenshape
.- Parameters:
shape
- Shape of the tensor.index
- nD index to check.- Throws:
IndexOutOfBoundsException
- Ifindex
is not a valid nD index into a tensor of the specifiedshape
.
-
validateTensorIndices
Checks that a set of nD indices are valid indices for a tensor with the specified shape.- Parameters:
shape
- Shape of the tensor.indices
- Indices to validate.
-
ensureValidAxes
Checks if all provided
axes
are valid with respect to the rank of the givenshape
.Specifically, an axis is valid if
axis >= 0 && axis < shape.getRank()
.- Parameters:
shape
- Shape of interest.axes
- Axes to validate.- Throws:
LinearAlgebraException
- Ifaxis < 0 || axis >= shape.getRank()
for any axis inaxes
.
-
ensureValidAxes
public static void ensureValidAxes(int rank, int... axes) Checks if all provided
axes
are valid with respect to the rank of the givenrank
.Specifically, an axis is valid if
axis >= 0 && axis < rank
.- Parameters:
rank
- Rank of a tensor/shape.axes
- Axes to validate.- Throws:
LinearAlgebraException
- Ifaxis < 0 || axis >= shape.getRank()
for any axis inaxes
.
-