Class FieldOps

java.lang.Object
org.flag4j.linalg.ops.common.field_ops.FieldOps

public final class FieldOps extends Object
This utility class contains ops for tensors whose elements are members of a Field.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <V extends Field<V>>
    void
    add(double[] src, V scalar, V[] dest)
    Adds a scalar value to each entry of the src tensor.
    static <V extends Field<V>>
    void
    add(V[] src, double scalar, V[] dest)
    Adds a primitive scalar value to each entry of the src tensor.
    static <V extends Field<V>>
    void
    conj(V[] src, V[] dest)
    Computes the element-wise complex conjugate of a tensor.
    static <V extends Field<V>>
    void
    div(double[] src, V scalar, V[] dest)
    Divides each entry of the src tensor by a scalar.
    static <V extends Field<V>>
    void
    div(V[] src, double scalar, V[] dest)
    Divides each entry of the src tensor by a primitive scalar.
    static <V extends Field<V>>
    void
    div(V[] src, V scalar, V[] dest)
    Divides each entry of the src tensor by a scalar.
    static <V extends Field<V>>
    boolean
    isFinite(V[] src)
    Checks if all elements of a tensor are finite.
    static <V extends Field<V>>
    boolean
    isInfinite(V[] src)
    Checks if any element of a tensor is infinite.
    static <V extends Field<V>>
    boolean
    isNaN(V[] src)
    Checks if any element of a tensor is NaN.
    static <V extends Field<V>>
    void
    mult(double[] src, V scalar, V[] dest)
    Multiplies a scalar value to each entry of the src tensor.
    static <V extends Field<V>>
    void
    mult(V[] src, double scalar, V[] dest)
    Multiplies a primitive scalar value to each entry of the src tensor.
    static <V extends Field<V>>
    void
    recip(V[] src, V[] dest)
    Computes the reciprocals, element-wise, of a tensor.
    static <V extends Field<V>>
    void
    scalMult(double[] entries, V factor, V[] dest)
    Computes the scalar multiplication of a tensor.
    static <T extends Field<T>>
    T[]
    scalMult(T[] src, double factor, int start, int n, int stride, T[] dest)
    Scales entries by the specified factor within src starting at index start and scaling a total of n elements spaced by stride.
    static <V extends Field<V>>
    void
    scalMult(V[] src, double factor, V[] dest)
    Computes the scalar multiplication of a tensor with a scalar value.
    static <V extends Field<V>>
    void
    sqrt(V[] src, V[] dest)
    Computes the element-wise square root of a tensor.
    static <V extends Field<V>>
    void
    sub(double[] src, V scalar, V[] dest)
    Subtracts a scalar value from each entry of the src tensor.
    static <V extends Field<V>>
    void
    sub(V[] src, double scalar, V[] dest)
    Subtracts a primitive scalar value from each entry of the src tensor.

    Methods inherited from class java.lang.Object

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

    • add

      public static <V extends Field<V>> void add(V[] src, double scalar, V[] dest)
      Adds a primitive scalar value to each entry of the src tensor.
      Parameters:
      src - Entries of the tensor to add the scalar to.
      scalar - Scalar to add to each entry of the tensor.
      dest - Array to store the result of adding the scalar to each entry of the tensor. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • add

      public static <V extends Field<V>> void add(double[] src, V scalar, V[] dest)
      Adds a scalar value to each entry of the src tensor.
      Parameters:
      src - Entries of the tensor to add the scalar to.
      scalar - Scalar to add to each entry of the tensor.
      dest - Array to store the result of adding the scalar to each entry of the tensor. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • sub

      public static <V extends Field<V>> void sub(V[] src, double scalar, V[] dest)
      Subtracts a primitive scalar value from each entry of the src tensor.
      Parameters:
      src - Entries of the tensor to subtract scalar from.
      scalar - Scalar to subtract from entry of the tensor.
      dest - Array to store the result of subtracting the scalar from each entry of the tensor. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • sub

      public static <V extends Field<V>> void sub(double[] src, V scalar, V[] dest)
      Subtracts a scalar value from each entry of the src tensor.
      Parameters:
      src - Entries of the tensor to subtract scalar from.
      scalar - Scalar to subtract from entry of the tensor.
      dest - Array to store the result of subtracting the scalar from each entry of the tensor. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • mult

      public static <V extends Field<V>> void mult(V[] src, double scalar, V[] dest)
      Multiplies a primitive scalar value to each entry of the src tensor.
      Parameters:
      src - Entries of the tensor to multiply the scalar to.
      scalar - Scalar to multiply to each entry of the tensor.
      dest - Array to store the result of multiplying the scalar to each entry of the tensor. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • mult

      public static <V extends Field<V>> void mult(double[] src, V scalar, V[] dest)
      Multiplies a scalar value to each entry of the src tensor.
      Parameters:
      src - Entries of the tensor to multiply the scalar to.
      scalar - Scalar to multiply to each entry of the tensor.
      dest - Array to store the result of multiplying the scalar to each entry of the tensor. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • div

      public static <V extends Field<V>> void div(V[] src, V scalar, V[] dest)
      Divides each entry of the src tensor by a scalar.
      Parameters:
      src - Entries of the tensor.
      scalar - Scalar to divide each entry of the tensor by.
      dest - Array to store the result of divided each entry of the tensor by the scalar. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • div

      public static <V extends Field<V>> void div(double[] src, V scalar, V[] dest)
      Divides each entry of the src tensor by a scalar.
      Parameters:
      src - Entries of the tensor.
      scalar - Scalar to divide each entry of the tensor by.
      dest - Array to store the result of divided each entry of the tensor by the scalar. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • div

      public static <V extends Field<V>> void div(V[] src, double scalar, V[] dest)
      Divides each entry of the src tensor by a primitive scalar.
      Parameters:
      src - Entries of the tensor.
      scalar - Scalar to divide each entry of the tensor by.
      dest - Array to store the result of divided each entry of the tensor by the scalar. May be the same array as src.
      Throws:
      ArrayIndexOutOfBoundsException - If dest.length < src.length.
    • sqrt

      public static <V extends Field<V>> void sqrt(V[] src, V[] dest)
      Computes the element-wise square root of a tensor.
      Parameters:
      src - Elements of the tensor.
      dest - Array to store the result in. May be the same array as src.
      Throws:
      IllegalArgumentException - If dest.length < src.length.
    • scalMult

      public static <V extends Field<V>> void scalMult(V[] src, double factor, V[] dest)
      Computes the scalar multiplication of a tensor with a scalar value.
      Parameters:
      src - Elements of the tensor.
      factor - Factor to scale all elements of src by.
      dest - Array to store the result in. May be the same array as src.
      Throws:
      IllegalArgumentException - If dest.length < src.length.
    • scalMult

      public static <V extends Field<V>> void scalMult(double[] entries, V factor, V[] dest)
      Computes the scalar multiplication of a tensor.
      Parameters:
      entries - Entries of the tensor.
      factor - Scalar value to multiply.
      dest - Array to store the result in. May be the same array as src.
      Throws:
      IllegalArgumentException - If dest.length < src.length.
    • scalMult

      public static <T extends Field<T>> T[] scalMult(T[] src, double factor, int start, int n, int stride, T[] 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.
    • conj

      public static <V extends Field<V>> void conj(V[] src, V[] dest)
      Computes the element-wise complex conjugate of a tensor.
      Parameters:
      src - Entries of the tensor.
      dest - Array to store the result in. May be the same array as src.
      Throws:
      IllegalArgumentException - If dest.length < src.length.
    • recip

      public static <V extends Field<V>> void recip(V[] src, V[] dest)
      Computes the reciprocals, element-wise, of a tensor.
      Parameters:
      src - Elements of the tensor.
      dest - Array to store the result in. May be the same array as src.
      Throws:
      IllegalArgumentException - If dest.length < src.length.
    • isFinite

      public static <V extends Field<V>> boolean isFinite(V[] src)
      Checks if all elements of a tensor are finite.
      Parameters:
      src - Elements of the tensor.
      Returns:
      true if every entry of src is finite; false otherwise.
    • isInfinite

      public static <V extends Field<V>> boolean isInfinite(V[] src)
      Checks if any element of a tensor is infinite.
      Parameters:
      src - Elements of the tensor.
      Returns:
      true if any entry of src is infinite; false otherwise.
    • isNaN

      public static <V extends Field<V>> boolean isNaN(V[] src)
      Checks if any element of a tensor is NaN.
      Parameters:
      src - Elements of the tensor.
      Returns:
      true if any entry of src is NaN; false otherwise.