Class DenseTensorBuilder

java.lang.Object
com.linkedin.feathr.common.tensorbuilder.DenseTensorBuilder
All Implemented Interfaces:
WriteableTuple, BulkTensorBuilder, TensorBuilder, TypedOperator

public class DenseTensorBuilder extends Object implements TensorBuilder, BulkTensorBuilder
Build a dense tensor based on input column types and shape, All columns except the last one, must have Primitive.INT representation. The last column type is considered to be value type and determines
  • Constructor Details

    • DenseTensorBuilder

      public DenseTensorBuilder(Representable[] columnTypes, long[] shape)
    • DenseTensorBuilder

      public DenseTensorBuilder(TensorType tensorType)
  • Method Details

    • getStaticCardinality

      public int getStaticCardinality()
      Description copied from interface: BulkTensorBuilder
      The full count of the tensor values, ignoring a possible unknown dimension.
      Specified by:
      getStaticCardinality in interface BulkTensorBuilder
    • hasVariableCardinality

      public boolean hasVariableCardinality()
      Description copied from interface: BulkTensorBuilder
      If the actual cardinality can be a multiple of the static cardinality, as opposed to exactly equal.
      Specified by:
      hasVariableCardinality in interface BulkTensorBuilder
    • append

      public TensorBuilder append()
      Description copied from interface: TensorBuilder
      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.
      Specified by:
      append in interface TensorBuilder
      Returns:
      a reference to this TensorBuilder (`this`)
    • start

      public TensorBuilder start(int estimatedRows)
      Description copied from interface: TensorBuilder
      Initializes this TensorBuilder. This method (or overloaded TensorBuilder.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.
      Specified by:
      start in interface TensorBuilder
      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`)
    • getOutputTypes

      public Representable[] getOutputTypes()
      Specified by:
      getOutputTypes in interface TypedOperator
    • getTypes

      public Representable[] getTypes()
      Specified by:
      getTypes in interface WriteableTuple
      Returns:
      the types of all dimensions and the value as a single array.
    • setInt

      public TensorBuilder setInt(int column, int value)
      DenseTensorBuilder's setInt should be used seldomly. The proper usage to construct DenseTensors is by using the build() method and passing in the associated arrays. By calling setInt for non value columns, the currentIndex is changed to point to the associated location in the value array. It assumes the usage is correct (append one row at a time and not overriding a given column, aka calling setInt on the same column multiple times). Ex of incorrect usage: shape is [2,2] setInt(0, 0), setInt(0, 1) -> Here the currentIndex is set for column 0 with value 0 and then changed to column 0 with value 1. Ex of correct usage: setInt(0,0), setInt(1,0) -> Here the currentIndex is set for column 0 with value 0 and column 1 with value 0. Setting the value here will be associated with the correct currentIndex and the correct row.
      Specified by:
      setInt in interface WriteableTuple
      Parameters:
      column - The column in the tuple to write to
      value - The int value to be written
      Returns:
      A reference to this object (`this`)
    • setLong

      public TensorBuilder setLong(int column, long value)
      Description copied from interface: WriteableTuple
      Sets the specified column to a given `long`
      Specified by:
      setLong in interface WriteableTuple
      Parameters:
      column - The column in the tuple to write to
      value - The long value to be written
      Returns:
      A reference to this object (`this`)
    • setFloat

      public TensorBuilder setFloat(int column, float value)
      Description copied from interface: WriteableTuple
      Sets the specified column to a given `float`
      Specified by:
      setFloat in interface WriteableTuple
      Parameters:
      column - The column in the tuple to write to
      value - The float value to be written
      Returns:
      A reference to this object (`this`)
    • setDouble

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

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

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

      public TensorBuilder setBytes(int column, byte[] value)
      Description copied from interface: WriteableTuple
      Sets the specified column to a given `byte array`
      Specified by:
      setBytes in interface WriteableTuple
      Parameters:
      column - The column in the tuple to write to
      value - The byte array value to be written
      Returns:
      A reference to this object (`this`)
    • build

      public TensorData build(float[] floats)
      Specified by:
      build in interface BulkTensorBuilder
    • build

      public TensorData build(int[] ints)
      Specified by:
      build in interface BulkTensorBuilder
    • build

      public TensorData build(long[] longs)
      Specified by:
      build in interface BulkTensorBuilder
    • build

      public TensorData build(double[] doubles)
      Specified by:
      build in interface BulkTensorBuilder
    • build

      public TensorData build(boolean[] booleans)
      Specified by:
      build in interface BulkTensorBuilder
    • build

      public TensorData build(List<?> values)
      Specified by:
      build in interface BulkTensorBuilder
    • build

      public TensorData build(ByteBuffer values)
      Specified by:
      build in interface BulkTensorBuilder
    • build

      public TensorData build(boolean sort)
      Description copied from interface: TensorBuilder
      Build the tensor
      Specified by:
      build in interface TensorBuilder
      Parameters:
      sort - if set to true, the built tensor's rows will be sorted lexicographically
      Returns:
      the built tensor