Interface TensorBuilder<T extends TensorBuilder<T>>

All Superinterfaces:
TypedOperator, WriteableTuple<T>
All Known Implementing Classes:
DenseTensorBuilder, UniversalTensorBuilder

public interface TensorBuilder<T extends TensorBuilder<T>> extends TypedOperator, WriteableTuple<T>
A stateful object used to build instances of tensors of some specific representation without knowing its details. Values are written to the builder row-wise. How to use: 1. Initialize the builder using start(int) 2. Set values for each column in the first row, using WriteableTuple.setInt(int, int), WriteableTuple.setFloat(int, float), etc. 3. Call append() to finish the row. 4. Repeat steps 2 and 3 for any remaining rows. 5. Call build() to build the TensorData object. Instances of TensorBuilder can be safely reused by calling start(int) to "reset" the builder. Except for any subclass implementation that explicitly states otherwise, instances of TensorBuilder MUST NOT be used in a concurrent fashion.
  • Method Details

    • build

      default TensorData build()
      Build the tensor Does NOT reset the internal state, so if you plan to reuse this instance, call start() or start(int) before reusing.
      Returns:
      the final built tensor, forcing lexicographical sorting.
    • build

      TensorData build(boolean sort)
      Build the tensor
      Parameters:
      sort - if set to true, the built tensor's rows will be sorted lexicographically
      Returns:
      the built tensor
    • setDouble

      default T setDouble(int index, double value)
      Description copied from interface: WriteableTuple
      Sets the specified column to a given `double`
      Specified by:
      setDouble in interface WriteableTuple<T extends TensorBuilder<T>>
      Parameters:
      index - The column in the tuple to write to
      value - The double value to be written
      Returns:
      A reference to this object (`this`)
    • setString

      default T setString(int index, String value)
      Description copied from interface: WriteableTuple
      Sets the specified column to a given `String`
      Specified by:
      setString in interface WriteableTuple<T extends TensorBuilder<T>>
      Parameters:
      index - The column in the tuple to write to
      value - The String value to be written
      Returns:
      A reference to this object (`this`)
    • setBoolean

      default T setBoolean(int index, boolean value)
      Description copied from interface: WriteableTuple
      Sets the specified column to a given `boolean`
      Specified by:
      setBoolean in interface WriteableTuple<T extends TensorBuilder<T>>
      Parameters:
      index - The column in the tuple to write to
      value - The double value to be written
      Returns:
      A reference to this object (`this`)
    • append

      T append()
      Tells this TensorBuilder that the current row is complete. This method MUST be called after using WriteableTuple.setInt(int, int), WriteableTuple.setFloat(int, float), etc. to set all the columns of the current row.
      Returns:
      a reference to this TensorBuilder (`this`)
    • start

      T start(int estimatedRows)
      Initializes this TensorBuilder. This method (or overloaded start() MUST be called before setting values to this TensorBuilder. This method may also be used to "reset" the builder, enabling it to be reused.
      Parameters:
      estimatedRows - The estimated number of rows in this tensor. Implementations can use this to allocate internal array sizes, for example.
      Returns:
      a reference to this TensorBuilder (`this`)
    • start

      default T start()
      Initializes this TensorBuilder. This method (or overloaded start(int) MUST be called before setting values to this TensorBuilder. This method may also be used to "reset" the builder, enabling it to be reused.
      Returns:
      a reference to this TensorBuilder (`this`)
    • copyColumn

      default T copyColumn(TensorIterator source, int sourceColumn, int destinationColumn)
      Copy a single column from source to this builder.
      Parameters:
      source - the source from which to copy
      sourceColumn - the index number of the column to be copied from the source
      destinationColumn - the index number of the column to be written to in this TensorBuilder
      Returns:
      a reference to this TensorBuilder (`this`)
    • copyColumns

      default T copyColumns(TensorIterator source, int[] sourceColumns)
      Copy multiple columns from source to this builder.
      Parameters:
      source - the source from which to copy
      sourceColumns - array of indices of the columns to be copied from the source and written to this TensorBuilder. Note that the columns are copied from the source into the same position in this builder; values read from column `i` are written to column `i`, etc.
      Returns:
      a reference to this TensorBuilder (`this`)
    • copyColumns

      default T copyColumns(TensorIterator left, TensorIterator right, int[] sourceColumns)
    • copyColumns

      default T copyColumns(TensorIterator left, TensorIterator right, int[] sourceColumns, int leftArity)
    • copyLeftColumns

      default T copyLeftColumns(TensorIterator source, int count)
      Copy some left-most columns from source to this builder (slightly more efficient than using an array of columns).
      Parameters:
      source - the source from which to copy
      count - the number of columns to copy, starting from the leftmost column (index 0)
      Returns:
      a reference to this TensorBuilder (`this`)