Class RealProperties

java.lang.Object
org.flag4j.linalg.ops.common.real.RealProperties

public final class RealProperties extends Object
This class provides low level methods for checking tensor properties. These methods can be applied to either sparse or dense real tensors.
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 a Double.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 among n elements in the array src, starting at index start and advancing by stride 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 among n elements in the array src, starting at index start and advancing by stride for each subsequent element.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 and b 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 and b 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 a Double.NaN.
      Parameters:
      src - Entries of the tensor.
      Returns:
      true is any entry of src is Double.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 of src is not finite. Otherwise, returns true.
    • 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 of src is infinite; 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. If data.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. If data.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. If data.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. If data.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 array src, starting at index start and advancing by stride 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 is Double.NaN the result of this method will be Double.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 in src to search.
      n - The number of elements to consider within src1.
      stride - The gap (in indices) between consecutive elements to search within src.
      Returns:
      • If any element of src is Double.NaN then the result will be Double.NaN.
      • Otherwise, the maximum absolute value found among all elements considered in src.
      Throws:
      IndexOutOfBoundsException - If the specified range extends beyond the array bounds.
    • minAbs

      public static double minAbs(double[] src, int start, int n, int stride)

      Returns the minimum absolute value among n elements in the array src, starting at index start and advancing by stride 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 is Double.NaN the result of this method will be Double.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 in src to search.
      n - The number of elements to consider within src1.
      stride - The gap (in indices) between consecutive elements to search within src.
      Returns:
      • If src.length == 0 then Double.POSITIVE_INFINITY will be returned.
      • If any element of src is Double.NaN then the result will be Double.NaN.
      • Otherwise, the minimum absolute value found among all elements considered innsrc.
      Throws:
      IndexOutOfBoundsException - If the specified range extends beyond the array bounds.