Interface TensorBuilder<T extends TensorBuilder<T>>
- All Superinterfaces:
TypedOperator,WriteableTuple<T>
- All Known Implementing Classes:
DenseTensorBuilder,UniversalTensorBuilder
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 Summary
Modifier and TypeMethodDescriptionappend()Tells this TensorBuilder that the current row is complete.default TensorDatabuild()Build the tensor Does NOT reset the internal state, so if you plan to reuse this instance, callstart()orstart(int)before reusing.build(boolean sort) Build the tensordefault TcopyColumn(TensorIterator source, int sourceColumn, int destinationColumn) Copy a single column from source to this builder.default TcopyColumns(TensorIterator source, int[] sourceColumns) Copy multiple columns from source to this builder.default TcopyColumns(TensorIterator left, TensorIterator right, int[] sourceColumns) default TcopyColumns(TensorIterator left, TensorIterator right, int[] sourceColumns, int leftArity) default TcopyLeftColumns(TensorIterator source, int count) Copy some left-most columns from source to this builder (slightly more efficient than using an array of columns).default TsetBoolean(int index, boolean value) Sets the specified column to a given `boolean`default TsetDouble(int index, double value) Sets the specified column to a given `double`default TSets the specified column to a given `String`default Tstart()Initializes this TensorBuilder.start(int estimatedRows) Initializes this TensorBuilder.Methods inherited from interface com.linkedin.feathr.common.tensorbuilder.TypedOperator
getOutputTypes
-
Method Details
-
build
Build the tensor Does NOT reset the internal state, so if you plan to reuse this instance, callstart()orstart(int)before reusing.- Returns:
- the final built tensor, forcing lexicographical sorting.
-
build
Build the tensor- Parameters:
sort- if set to true, the built tensor's rows will be sorted lexicographically- Returns:
- the built tensor
-
setDouble
Description copied from interface:WriteableTupleSets the specified column to a given `double`- Specified by:
setDoublein interfaceWriteableTuple<T extends TensorBuilder<T>>- Parameters:
index- The column in the tuple to write tovalue- The double value to be written- Returns:
- A reference to this object (`this`)
-
setString
Description copied from interface:WriteableTupleSets the specified column to a given `String`- Specified by:
setStringin interfaceWriteableTuple<T extends TensorBuilder<T>>- Parameters:
index- The column in the tuple to write tovalue- The String value to be written- Returns:
- A reference to this object (`this`)
-
setBoolean
Description copied from interface:WriteableTupleSets the specified column to a given `boolean`- Specified by:
setBooleanin interfaceWriteableTuple<T extends TensorBuilder<T>>- Parameters:
index- The column in the tuple to write tovalue- 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 usingWriteableTuple.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
Initializes this TensorBuilder. This method (or overloadedstart()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
Initializes this TensorBuilder. This method (or overloadedstart(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
Copy a single column from source to this builder.- Parameters:
source- the source from which to copysourceColumn- the index number of the column to be copied from the sourcedestinationColumn- the index number of the column to be written to in this TensorBuilder- Returns:
- a reference to this TensorBuilder (`this`)
-
copyColumns
Copy multiple columns from source to this builder.- Parameters:
source- the source from which to copysourceColumns- 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
-
copyColumns
default T copyColumns(TensorIterator left, TensorIterator right, int[] sourceColumns, int leftArity) -
copyLeftColumns
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 copycount- the number of columns to copy, starting from the leftmost column (index 0)- Returns:
- a reference to this TensorBuilder (`this`)
-