Class RealOps

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

public final class RealOps extends Object
This class provides low level methods for computing ops on real tensors. These methods can be applied to either sparse or dense real tensors.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    abs(double[] src)
    Computes the element-wise absolute value of a tensor.
    static double[]
    round(double[] src)
    Rounds the values of a tensor to the nearest integer.
    static double[]
    round(double[] src, int precision)
    Rounds the values of a tensor with specified precision.
    static double[]
    roundToZero(double[] src, double threshold)
    Rounds values which are close to zero in absolute value to zero.
    static double[]
    scalDiv(double[] src, double divisor, double[] dest)
    Computes the scalar division of a tensor.
    static double[]
    scalMult(double[] src, double factor, double[] dest)
    Computes the scalar multiplication of a tensor.
    static double[]
    scalMult(double[] src, double factor, int start, int stop, double[] dest)
    Computes the scalar multiplication of a tensor.
    static double[]
    scalMult(double[] src, double factor, int start, int n, int stride, double[] dest)
    Scales entries by the specified factor within src starting at index start and scaling a total of n elements spaced by stride.
    static double[]
    sqrt(double[] src)
    Computes the element-wise square root of a tensor.

    Methods inherited from class java.lang.Object

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

    • scalMult

      public static double[] scalMult(double[] src, double factor, double[] dest)
      Computes the scalar multiplication of a tensor.
      Parameters:
      src - Entries of the tensor.
      factor - Scalar value to multiply.
      dest - Array to store result in. May be null.
      Returns:
      A reference to the dest array if it was not null. Otherwise, a new array will be formed.
      Throws:
      ArrayIndexOutOfBoundsException - If dest is not at least the size of src.
    • scalMult

      public static double[] scalMult(double[] src, double factor, int start, int stop, double[] dest)
      Computes the scalar multiplication of a tensor.
      Parameters:
      src - Entries of the tensor.
      factor - Scalar value to multiply.
      start - Starting index of scalar multiplication.
      stop - Stopping index of scalar multiplication.
      dest - Array to store result in. May be null.
      Returns:
      A reference to the dest array if it was not null. Otherwise, a new array will be formed.
      Throws:
      ArrayIndexOutOfBoundsException - If dest is not the size of src.
    • scalMult

      public static double[] scalMult(double[] src, double factor, int start, int n, int stride, double[] dest)

      Scales entries by the specified factor within src starting at index start and scaling a total of n elements spaced by stride.

      More formally, this method scales elements by the specified factor at indices: start, start + stride, start + 2*stride, ..., start + (n-1)*stride.

      This method may be used to scale a row or column of a matrix a as follows:

      • Maximum absolute value within row i:
        scale(a.data, i*a.numCols, a.numCols, 1, dest);
      • Maximum absolute value within column j:
        scale(a.data, j, a.numRows, a.numRows, dest);
      Parameters:
      src - The array containing values to scale.
      factor - Factor by which to scale elements.
      start - The starting index in src to begin scaling.
      n - The number of elements to scale within src1.
      stride - The gap (in indices) between consecutive elements to scale within src.
      dest - The array to store the result in. May be null or the same array as src to perform the operation in-place. Assumed to be at least as large as src but this is not explicitly enforced.
      Returns:
      If dest == null a new array containing all elements of src with the appropriate values scaled. Otherwise, A reference to the dest array.
    • scalDiv

      public static double[] scalDiv(double[] src, double divisor, double[] dest)
      Computes the scalar division of a tensor.
      Parameters:
      src - Entries of the tensor.
      divisor - Scalar value to divide.
      dest - Array to store result in. May be null.
      Returns:
      A reference to the dest array if it was not null. Otherwise, a new array will be formed.
    • sqrt

      public static double[] sqrt(double[] src)
      Computes the element-wise square root of a tensor.
      Parameters:
      src - Elements of the tensor.
      Returns:
      The element-wise square root of the tensor.
    • abs

      public static double[] abs(double[] src)
      Computes the element-wise absolute value of a tensor.
      Parameters:
      src - Elements of the tensor.
      Returns:
      The element-wise absolute value of the tensor.
    • round

      public static double[] round(double[] src)
      Rounds the values of a tensor to the nearest integer. Also see round(double[], int).
      Parameters:
      src - Entries of the tensor to round.
      Returns:
      The result of rounding all data of the source tensor to the nearest integer.
      Throws:
      IllegalArgumentException - If precision is negative.
    • round

      public static double[] round(double[] src, int precision)
      Rounds the values of a tensor with specified precision. Note, if precision is zero, round(double[]) is preferred.
      Parameters:
      src - Entries of the tensor to round.
      precision - Precision to round to (i.e. the number of decimal places).
      Returns:
      The result of rounding all data of the source tensor with the specified precision.
      Throws:
      IllegalArgumentException - If precision is negative.
    • roundToZero

      public static double[] roundToZero(double[] src, double threshold)
      Rounds values which are close to zero in absolute value to zero.
      Parameters:
      threshold - Threshold for rounding values to zero. That is, if a value in this tensor is less than the threshold in absolute value then it will be rounded to zero. This value must be non-negative.
      Returns:
      A copy of this matrix with rounded values.
      Throws:
      IllegalArgumentException - If threshold is negative.