All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.linkedin.dagli.preparer.PreparerVariadic Maven / Gradle / Ivy

Go to download

DAG-oriented machine learning framework for bug-resistant, readable, efficient, maintainable and trivially deployable models in Java and other JVM languages

There is a newer version: 15.0.0-beta9
Show newest version
package com.linkedin.dagli.preparer;

import com.linkedin.dagli.objectio.ObjectReader;
import com.linkedin.dagli.transformer.PreparedTransformerVariadic;
import java.util.Arrays;
import java.util.List;

/**
 * Base interface for preparers of variadic-arity transformers.
 *
 * @param  the type of value produced by the transformer.
 * @param  the type of the resultant prepared transformer.
 */
public interface PreparerVariadic> extends Preparer {
  @Override
  default void processUnsafe(Object[] values) {
    // we don't own values, so we create a clone to prevent values from escaping
    process((List) Arrays.asList(values.clone()));
  }

  /**
   * Processes a single example of preparation data.  To prepare a {@link Preparer}, process(...) will be called on
   * each and every preparation example before finish(...) is called to complete preparation.
   *
   * This method is not assumed to be thread-safe and will not be invoked concurrently on the same {@link Preparer}.
   *
   * @param values The input values.  The Preparer must not modify this list.
   */
  void process(List values);

  @Override
  default PreparerResultMixed, N> finishUnsafe(
      ObjectReader inputs) {
    return finish(inputs == null ? null : inputs.lazyMap(arr -> (List) Arrays.asList(arr)));
  }

  /**
   * Finish preparation.
   *
   * @param inputs the preparation data, as previously seen by {@link PreparerVariadic#process(List)}
   * @return a {@link PreparerResultMixed} containing the resulting prepared transformers
   */
  PreparerResultMixed, N> finish(
      ObjectReader> inputs);
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy