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 voidensureAllEqual(int... values) Checks if a set of values are all equal.static voidensureAllGreaterEq(double threshold, double... values) Checks if a set of values is greater than or equal to a specified threshold.static voidensureAllGreaterEq(int threshold, int... values) Checks if a set of values is greater than or equal to a specified threshold.static voidensureArrayLengthsEq(int... lengths) Checks that all array lengths are equal.static voidensureAxis2D(int axis) Checks that an axis is a valid 2D axis.static voidensureEqualShape(Shape shape1, Shape shape2) Checks if twoShapeobjects are equivalent.static voidensureGreaterEq(double threshold, double value, String name) Checks ifvalue >= threshold.static voidensureGreaterEq(int threshold, int value) Checks ifvalues[i] >= thresholdfor alli = 0, 1, ..., values.length.static voidensureInRange(double value, double lowerBound, double upperBound, String paramName) Checks that a value is within the specified inclusive range.static voidensureLessEq(double threshold, double... values) Checks ifvalues[i] <= thresholdfor alli = 0, 1, ..., values.length.static voidensureLessEq(double threshold, double value, String name) Checks ifvalues <= threshold.static voidensureLessEq(int threshold, int... values) Checks ifvalues[i] <= thresholdfor alli = 0, 1, ..., values.length.static voidensureLessEq(BigInteger threshold, int value, String name) Checks ifvalues <= threshold.static voidensureMatMultShapes(Shape shape1, Shape shape2) Checks if twoShapeobjects satisfy the requirements of matrix-matrix or matrix-vector multiplication.static voidensureNonNegative(int value) Checks ifvalue >= 0.static voidensureNonNegative(int... values) Checks ifvaluescontains only non-negative values.static voidensureNonNegative(int value, String name) Checks ifvalue >= 0.static voidensureNotEquals(double a, double b) Checks that two values are not equal.static voidensurePermutation(int... axes) Checks that a list ofNaxis are a permutation of{0, 1, 2, ..., N-1}.static voidensurePermutation(int[] axes, int n) Checks that a list of axis are a permutation of{0, 1, 2, ..., n-1}.static voidensurePositive(int value) Checks ifvalue > 0.static voidensureRank(Shape shape, int expRank) Checks that a shape has the specified rank.static voidensureSquare(Shape shape) Checks if a shape represents a square tensor.static voidensureSquareMatrix(int numRows, int numCols) Checks if a shape represents a square matrix.static voidensureSquareMatrix(Shape shape) Checks if a shape represents a square matrix.static voidensureTotalEntriesEq(double[][] arr1, double[] arr2) Checks if arrays have the same number of total data.static voidensureTotalEntriesEq(int[][] arr1, double[] arr2) Checks if arrays have the same number of total data.static voidensureTotalEntriesEq(Object[][] arr1, double[] arr2) Checks if arrays have the same number of total data.static voidensureTotalEntriesEqual(Shape shape1, Shape shape2) Checks that two shapes have the same total number of data.static voidensureTrue(boolean expr, String errMsg) Ensures that a boolean is true.static voidensureValidAxes(int rank, int... axes) Checks if all providedaxesare valid with respect to the rank of the givenrank.static voidensureValidAxes(Shape shape, int... axes) Checks if all providedaxesare valid with respect to the rank of the givenshape.static voidvalidateArrayIndices(int upperBound, int... indices) Checks that a set of indices is within[0, upperBound).static voidvalidateTensorIndex(Shape shape, int... index) Checks if the provided nD index is contained in a tensor defined by the givenshape.static voidvalidateTensorIndices(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 twoShapeobjects are equivalent.- Parameters:
shape1- First shape.shape2- Second shape.- Throws:
TensorShapeException- If shapes are not equivalent.
-
ensureMatMultShapes
Checks if twoShapeobjects 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] >= thresholdfor alli = 0, 1, ..., values.length.- Parameters:
threshold- Threshold value.value- Value to compare against threshold.- Throws:
IllegalArgumentException- Ifvalues[i] < thresholdfor 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] <= thresholdfor alli = 0, 1, ..., values.length.- Parameters:
threshold- Threshold value.values- Values to compare against threshold.- Throws:
IllegalArgumentException- Ifvalues[i] > thresholdfor anyi = 0, 1, ..., values.length.
-
ensureLessEq
public static void ensureLessEq(int threshold, int... values) Checks ifvalues[i] <= thresholdfor alli = 0, 1, ..., values.length.- Parameters:
threshold- Threshold value.values- Values to compare against threshold.- Throws:
IllegalArgumentException-values[i] > thresholdfor 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
Checks ifvalue >= 0.- Parameters:
value- Value of interest.- Throws:
IllegalArgumentException- Ifvalue < 0.- See Also:
-
ensureNonNegative
public static void ensureNonNegative(int... values) Checks ifvaluescontains only non-negative values.- Parameters:
values- Values of interest.- Throws:
IllegalArgumentException- If any element ofvaluesis 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 ofNaxis are a permutation of{0, 1, 2, ..., N-1}.- Parameters:
axes- List of axes of interest.- Throws:
IllegalArgumentException- Ifaxisis 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- Ifaxisis 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- Ifvalueis 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 anyindicesare 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- Ifindexis 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
axesare 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
axesare 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.
-