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

com.linkedin.dagli.preparer.Preparer2 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
// AUTOGENERATED CODE.  DO NOT MODIFY DIRECTLY!  Instead, please modify the preparer/PreparerX.ftl file.
// See the README in the module's src/template directory for details.
package com.linkedin.dagli.preparer;

import com.linkedin.dagli.objectio.ObjectReader;
import com.linkedin.dagli.transformer.PreparedTransformer2;
import com.linkedin.dagli.util.invariant.Arguments;

import com.linkedin.dagli.tuple.Tuple2;


public interface Preparer2> extends Preparer {
  @Override
  default void processUnsafe(Object[] values) {
    Arguments.check(values.length == 2, "2 arguments must be provided");
    process((A) values[0], (B) values[1]);
  }

  /**
   * 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 value1 the first value of the preparation example to be processed
   * @param value2 the second value of the preparation example to be processed
   */
  void process(A value1, B value2);

  @Override
  default PreparerResultMixed, N> finishUnsafe(
      ObjectReader inputs) {
    return finish(inputs == null ? null : inputs.lazyMap(Tuple2::fromArrayUnsafe));
  }

  /**
   * Completes preparation to obtain the final, prepared transformer result.  This method is called after all
   * preparation data has been process(...)'ed.
   *
   * @param inputs an {@link ObjectReader} that can be used by the {@link Preparer} to iterate over the preparation data
   *               as many times as desired.
   * @return a {@link PreparerResultMixed} containing the resultant prepared transformers (often these are the same
   *         instance; a {@link Preparer} can, however, return a different transformer to be used on preparation and
   *         future ("new") data, which is useful in certain sophisticated use cases)
   */
  PreparerResultMixed, N> finish(
      ObjectReader> inputs);

  /**
   * Casts a preparer to a "supertype".  This cast is safe due to the semantics of preparers.
   *
   * @param preparer the preparer to cast
   * @param  the new type of input #1
   * @param  the new type of input #2
   * @param  the new result type
   * @param  the new prepared transformer type
   * @return the provided {@code preparer}, cast to the desired "supertype"
   */
  @SuppressWarnings("unchecked")
  static > Preparer2 cast(
      Preparer2 preparer) {
    // safe due to semantics of preparers:
    return (Preparer2) preparer;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy