Class ValidateParameters

java.lang.Object
org.flag4j.util.ValidateParameters

public final class ValidateParameters extends Object
This utility class contains several methods for ensuring parameters satisfy some condition.
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 two Shape objects are equivalent.
    static void
    ensureGreaterEq(double threshold, double value, String name)
    Checks if value >= threshold.
    static void
    ensureGreaterEq(int threshold, int value)
    Checks if values[i] >= threshold for all i = 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 if values[i] <= threshold for all i = 0, 1, ..., values.length.
    static void
    ensureLessEq(double threshold, double value, String name)
    Checks if values <= threshold.
    static void
    ensureLessEq(int threshold, int... values)
    Checks if values[i] <= threshold for all i = 0, 1, ..., values.length.
    static void
    ensureLessEq(BigInteger threshold, int value, String name)
    Checks if values <= threshold.
    static void
    ensureMatMultShapes(Shape shape1, Shape shape2)
    Checks if two Shape objects satisfy the requirements of matrix-matrix or matrix-vector multiplication.
    static void
    ensureNonNegative(int value)
    Checks if value >= 0.
    static void
    ensureNonNegative(int... values)
    Checks if values 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 of N 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 if value > 0.
    static void
    ensureRank(Shape shape, int expRank)
    Checks that a shape has the specified rank.
    static void
    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
    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
    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 provided axes are valid with respect to the rank of the given rank.
    static void
    ensureValidAxes(Shape shape, int... axes)
    Checks if all provided axes are valid with respect to the rank of the given shape.
    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 given shape.
    static void
    validateTensorIndices(Shape shape, int[]... indices)
    Checks that a set of nD indices are valid indices for a tensor with the specified shape.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • ensureEqualShape

      public static void ensureEqualShape(Shape shape1, Shape shape2)
      Checks if two Shape objects are equivalent.
      Parameters:
      shape1 - First shape.
      shape2 - Second shape.
      Throws:
      TensorShapeException - If shapes are not equivalent.
    • ensureMatMultShapes

      public static void ensureMatMultShapes(Shape shape1, Shape shape2)
      Checks if two Shape 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

      public static void ensureTotalEntriesEqual(Shape shape1, Shape shape2)
      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

      public static void ensureTotalEntriesEq(Object[][] 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(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

      public static void ensureTrue(boolean expr, String errMsg)
      Ensures that a boolean is true.
      Parameters:
      expr - Boolean to check the truth of.
      errMsg - Error message in the case where expr == 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 - If a==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 if values[i] >= threshold for all i = 0, 1, ..., values.length.
      Parameters:
      threshold - Threshold value.
      value - Value to compare against threshold.
      Throws:
      IllegalArgumentException - If values[i] < threshold for any i = 0, 1, ..., values.length.
    • ensureGreaterEq

      public static void ensureGreaterEq(double threshold, double value, String name)
      Checks if value >= threshold.
      Parameters:
      threshold - Threshold value.
      value - Values to compare against threshold.
      name - Name of parameter.
      Throws:
      IllegalArgumentException - If value < threshold.
    • ensureLessEq

      public static void ensureLessEq(double threshold, double... values)
      Checks if values[i] <= threshold for all i = 0, 1, ..., values.length.
      Parameters:
      threshold - Threshold value.
      values - Values to compare against threshold.
      Throws:
      IllegalArgumentException - If values[i] > threshold for any i = 0, 1, ..., values.length.
    • ensureLessEq

      public static void ensureLessEq(int threshold, int... values)
      Checks if values[i] <= threshold for all i = 0, 1, ..., values.length.
      Parameters:
      threshold - Threshold value.
      values - Values to compare against threshold.
      Throws:
      IllegalArgumentException - values[i] > threshold for any i = 0, 1, ..., values.length.
    • ensureLessEq

      public static void ensureLessEq(double threshold, double value, String name)
      Checks if values <= threshold.
      Parameters:
      threshold - Threshold value.
      value - Value to compare against threshold.
      name - Name of parameter.
      Throws:
      IllegalArgumentException - If values > threshold.
    • ensureLessEq

      public static void ensureLessEq(BigInteger threshold, int value, String name)
      Checks if values <= threshold.
      Parameters:
      threshold - Threshold value.
      value - Value to compare against threshold.
      name - Name of parameter.
      Throws:
      IllegalArgumentException - If values > threshold.
    • ensurePositive

      public static void ensurePositive(int value)
      Checks if value > 0.
      Parameters:
      value - Value of interest.
      Throws:
      IllegalArgumentException - If value <= 0.
      See Also:
    • ensureNonNegative

      public static void ensureNonNegative(int value)
      Checks if value >= 0.
      Parameters:
      value - Value of interest.
      Throws:
      IllegalArgumentException - If value < 0.
      See Also:
    • ensureNonNegative

      public static void ensureNonNegative(int... values)
      Checks if values contains only non-negative values.
      Parameters:
      values - Values of interest.
      Throws:
      IllegalArgumentException - If any element of values is negative.
      See Also:
    • ensureSquareMatrix

      public static void ensureSquareMatrix(Shape shape)
      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

      public static void ensureSquare(Shape shape)
      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

      public static void ensureRank(Shape shape, int expRank)
      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 of N axis are a permutation of {0, 1, 2, ..., N-1}.
      Parameters:
      axes - List of axes of interest.
      Throws:
      IllegalArgumentException - If axis 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 - If axis 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 - If value 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 any indices are not within [0, upperBound).
    • validateTensorIndex

      public static void validateTensorIndex(Shape shape, int... index)
      Checks if the provided nD index is contained in a tensor defined by the given shape.
      Parameters:
      shape - Shape of the tensor.
      index - nD index to check.
      Throws:
      IndexOutOfBoundsException - If index is not a valid nD index into a tensor of the specified shape.
    • validateTensorIndices

      public static void validateTensorIndices(Shape shape, int[]... indices)
      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

      public static void ensureValidAxes(Shape shape, int... axes)

      Checks if all provided axes are valid with respect to the rank of the given shape.

      Specifically, an axis is valid if axis >= 0 && axis < shape.getRank().

      Parameters:
      shape - Shape of interest.
      axes - Axes to validate.
      Throws:
      LinearAlgebraException - If axis < 0 || axis >= shape.getRank() for any axis in axes.
    • ensureValidAxes

      public static void ensureValidAxes(int rank, int... axes)

      Checks if all provided axes are valid with respect to the rank of the given rank.

      Specifically, an axis is valid if axis >= 0 && axis < rank.

      Parameters:
      rank - Rank of a tensor/shape.
      axes - Axes to validate.
      Throws:
      LinearAlgebraException - If axis < 0 || axis >= shape.getRank() for any axis in axes.