Package org.flag4j.util
Class ParameterChecks
java.lang.Object
org.flag4j.util.ParameterChecks
This class contains several methods for checking properties of shapes and arrays.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertArrayLengthsEq
(int... lengths) Checks that all array lengths are equal.static void
assertAxis2D
(int axis) Checks that an axis is a valid 2D axis.static void
assertBroadcastable
(Shape shape1, Shape shape2) Checks that two shapes can be broadcast, i.e.static void
assertEquals
(double... values) Checks if a set of values are all equal.static void
assertEquals
(int... values) Checks if a set of values are all equal.static void
assertEqualShape
(Shape shape1, Shape shape2) Checks if twoShape
objects are equivalent.static void
assertGreaterEq
(double threshold, double... values) Checks if a set of values is greater than or equal to a specified threshold.static void
assertGreaterEq
(double threshold, double value, String name) Checks if a set of values is greater than or equal to a specified threshold.static void
assertGreaterEq
(int threshold, int value) Checks if a single value is greater than or equal to a specified threshold.static void
assertGreaterEq
(int threshold, int... values) Checks if a set of values is greater than or equal to a specified threshold.static void
assertIndexInBounds
(int upperBound, int... indices) Checks that a set of indices is within[0, upperBound)
.static void
assertInRange
(double value, double lowerBound, double upperBound, String paramName) Checks that a value is within the specified inclusive range.static void
assertLessEq
(double threshold, double... values) Checks if a set of values is less than or equal to a specified threshold.static void
assertLessEq
(double threshold, double value, String name) Checks if a value is less than or equal to a specified threshold.static void
assertLessEq
(int threshold, int... values) Checks if a set of values is less than or equal to a specified threshold.static void
assertLessEq
(BigInteger threshold, int value, String name) Checks if a value is less than or equal to a specified threshold.static void
assertMatMultShapes
(Shape shape1, Shape shape2) Checks if twoShape
objects satisfy the requirements of matrix multiplication.static void
assertNonNegative
(int value) Checks if a value is non-negative.static void
assertNotEquals
(double a, double b) Checks that two values are not equal.static void
assertPermutation
(int... axes) Checks that a list ofN
axis are a permutation of{0, 1, 2, ..., N-1}
.static void
assertPositive
(int value) Checks if a value is positive.static void
assertRank
(int expRank, Shape shape) Checks that a shape has the specified rank.static void
assertSquare
(Shape shape) Checks if a shape represents a square tensor.static void
assertSquareMatrix
(int numRows, int numCols) Checks if a shape represents a square matrix.static void
assertSquareMatrix
(Shape shape) Checks if a shape represents a square matrix.static void
assertTotalEntriesEq
(double[][] arr1, double[] arr2) Checks if arrays have the same number of total entries.static void
assertTotalEntriesEq
(double[][] arr1, CNumber[] arr2) Checks if arrays have the same number of total entries.static void
assertTotalEntriesEq
(int[][] arr1, double[] arr2) Checks if arrays have the same number of total entries.static void
assertTotalEntriesEq
(int[][] arr1, CNumber[] arr2) Checks if arrays have the same number of total entries.static void
assertTotalEntriesEq
(Object[][] arr1, double[] arr2) Checks if arrays have the same number of total entries.static void
assertTotalEntriesEq
(Object[][] arr1, CNumber[] arr2) Checks if arrays have the same number of total entries.static void
assertValidIndex
(Shape shape, int... indices) Checks if the provided indices are contained in a tensor defined by the givenshape
.static void
assertValidIndices
(int length, int... indices) Checks if the provided indices are contained in an iterable with the givenlength
.
-
Constructor Details
-
ParameterChecks
private ParameterChecks()
-
-
Method Details
-
assertEqualShape
Checks if twoShape
objects are equivalent.- Parameters:
shape1
- First shape.shape2
- Second shape.- Throws:
LinearAlgebraException
- If shapes are not equivalent.
-
assertMatMultShapes
Checks if twoShape
objects satisfy the requirements of matrix multiplication.- Parameters:
shape1
- First shape.shape2
- Second shape.- Throws:
LinearAlgebraException
- If shapes do not satisfy the requirements of matrix multiplication.
-
assertArrayLengthsEq
public static void assertArrayLengthsEq(int... lengths) Checks that all array lengths are equal.- Parameters:
lengths
- An array of array lengths.- Throws:
IllegalArgumentException
- If all lengths are not equal.
-
assertBroadcastable
Checks that two shapes can be broadcast, i.e. have the same total number of entries.- Parameters:
shape1
- First shape to compare.shape2
- Second shape to compare.- Throws:
IllegalArgumentException
- If the two shapes do not have the same total number of entries.
-
assertTotalEntriesEq
Checks if arrays have the same number of total entries.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total entries.
-
assertTotalEntriesEq
public static void assertTotalEntriesEq(double[][] arr1, double[] arr2) Checks if arrays have the same number of total entries.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total entries.
-
assertTotalEntriesEq
public static void assertTotalEntriesEq(int[][] arr1, double[] arr2) Checks if arrays have the same number of total entries.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total entries.
-
assertTotalEntriesEq
Checks if arrays have the same number of total entries.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total entries.
-
assertTotalEntriesEq
Checks if arrays have the same number of total entries.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total entries.
-
assertTotalEntriesEq
Checks if arrays have the same number of total entries.- Parameters:
arr1
- First array.arr2
- Second array.- Throws:
IllegalArgumentException
- If arrays do not have the same number of total entries.
-
assertEquals
public static void assertEquals(double... 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.
-
assertEquals
public static void assertEquals(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.
-
assertNotEquals
public static void assertNotEquals(double a, double b) Checks that two values are not equal.- Parameters:
a
- First value.b
- Second value.- Throws:
IllegalArgumentException
- Ifa==b
.
-
assertGreaterEq
public static void assertGreaterEq(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.
-
assertGreaterEq
public static void assertGreaterEq(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.
-
assertGreaterEq
public static void assertGreaterEq(int threshold, int value) Checks if a single value is greater than or equal to a specified threshold.- Parameters:
threshold
- Threshold value.value
- Value to compare against threshold.- Throws:
IllegalArgumentException
- If the values is less than the threshold.
-
assertGreaterEq
Checks if a set of values is greater than or equal to a specified threshold.- Parameters:
threshold
- Threshold value.value
- Values to compare against threshold.name
- Name of parameter.- Throws:
IllegalArgumentException
- If any of the values are less than the threshold.
-
assertLessEq
public static void assertLessEq(double threshold, double... values) Checks if a set of values is less 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 greater than the threshold.
-
assertLessEq
public static void assertLessEq(int threshold, int... values) Checks if a set of values is less 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 greater than the threshold.
-
assertLessEq
Checks if a value is less than or equal to a specified threshold.- Parameters:
threshold
- Threshold value.value
- Value to compare against threshold.name
- Name of parameter.- Throws:
IllegalArgumentException
- If the value is greater than the threshold.
-
assertLessEq
Checks if a value is less than or equal to a specified threshold.- Parameters:
threshold
- Threshold value.value
- Value to compare against threshold.name
- Name of parameter.- Throws:
IllegalArgumentException
- If the value is greater than the threshold.
-
assertPositive
public static void assertPositive(int value) Checks if a value is positive.- Parameters:
value
- Value of interest.- Throws:
IllegalArgumentException
- Ifvalue
is not positive.- See Also:
-
assertNonNegative
public static void assertNonNegative(int value) Checks if a value is non-negative. Note, this method differs fromassertPositive(int)
as it allows zero values whereassertPositive(int)
does not. value- Parameters:
value
- Value of interest.- Throws:
IllegalArgumentException
- Ifvalue
is negative.- See Also:
-
assertSquareMatrix
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.
-
assertSquare
Checks if a shape represents a square tensor.- Parameters:
shape
- Shape to check.- Throws:
IllegalArgumentException
- If all axis of the shape are not the same length.
-
assertSquareMatrix
public static void assertSquareMatrix(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.
-
assertRank
Checks that a shape has the specified rank.- Parameters:
expRank
- Expected rank.shape
- Shape to check.- Throws:
LinearAlgebraException
- If the specified shape does not have the expected rank.
-
assertAxis2D
public static void assertAxis2D(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.
-
assertPermutation
public static void assertPermutation(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}
.
-
assertInRange
public static void assertInRange(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]
-
assertIndexInBounds
public static void assertIndexInBounds(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 if indices to check.- Throws:
IndexOutOfBoundsException
- If anyindices
or not within[0, upperBound)
.
-
assertValidIndex
Checks if the provided indices are contained in a tensor defined by the givenshape
.- Parameters:
shape
- Shape of the tensor.indices
- Indices to check. Must be same length as the number of dimensions inshape
.- Throws:
IndexOutOfBoundsException
- Ifindices
is not a valid index into a tensor of the specifiedshape
.
-
assertValidIndices
public static void assertValidIndices(int length, int... indices) Checks if the provided indices are contained in an iterable with the givenlength
.- Parameters:
length
- length of iterable.indices
- Indices to check.- Throws:
IndexOutOfBoundsException
- Ifindices
is not a valid index into an iterable of the specifiedlength
.
-