Class TransformSemiRing

java.lang.Object
org.flag4j.linalg.ops.common.semiring_ops.TransformSemiRing

public final class TransformSemiRing extends Object
A utility class for computing transformations on Semiring arrays.
  • Method Details

    • mapReduce

      public static <T extends Semiring<T>> Semiring mapReduce(T[] values, Function<T,T> mapper, BinaryOperator<T> accumulator)
      Applies a map-reduce procedure to an array of Semiring values. This is equivalent to reduce(map(values, mapper), accumulator).
      Parameters:
      values - Values to apply map-reduce to; must not be null.
      mapper - Mapper to apply during the mapping step; must not be null.
      accumulator - Accumulator to use during the reduction step.
      Returns:
      The result of applying the map-reduce procedure using the specified mapper and accumulator to the values array.
    • map

      public static <T extends Semiring<T>> T[] map(T[] values, Function<T,T> mapper)

      Applies a specified function to each element of the given array and returns a new array containing the results of the mapping operation. This produces a new array where each element is the result of applying the provided mapper function to the corresponding element in the input array.

      For example, if the array contains elements [a, b, c] and the mapper function multiplies each element by 2, the returned array will contain [2a, 2b, 2c].

      Parameters:
      values - the array of field elements to map; must not be null
      mapper - the mapping function to apply to each element; must not be null
      Returns:
      a new array containing the results of applying the mapper function to each element in the values array
      Throws:
      NullPointerException - if values or mapper is null
      IllegalArgumentException - if values is empty
    • reduce

      public static <T extends Semiring<T>> Semiring<T> reduce(T[] values, BinaryOperator<T> accumulator)

      Reduces the given array of field elements to a single element by repeatedly applying a binary operator to combine elements. The reduction is performed from left to right, starting with the first element in the array and hence is a "left-reduce" or "left fold".

      The reduce operation applies the specified accumulator function to the first element and the second element, then applies it to the result and the third element, and so on until all elements have been combined into a single result. The operation assumes that the array contains at least one element.

      For example, if the array contains elements [a, b, c, d] and the accumulator is a function which adds elements, the method would compute (((a + b) + c) + d).

      Parameters:
      values - The array of field elements to reduce. Cannot be empty or null.
      accumulator - The binary operator to combine elements.
      Returns:
      the result of lef-reducing all elements values using the specified accumulator.
      Throws:
      IllegalArgumentException - if values is empty
      NullPointerException - if values or accumulator is null