Class Tensors
java.lang.Object
com.linkedin.feathr.common.tensor.Tensors
Utility methods for converting various collections to tensors.
Lists and arrays are represented as dense tensors.
Maps are represented as sparse tensors.
Sets are represented as sparse tensors with 1f as values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic TensorDataasDenseTensor(TensorType type, double[] doubles) Convert an array value to a dense tensor.static TensorDataasDenseTensor(TensorType type, float[] floats) Convert an array value to a dense tensor.static TensorDataasDenseTensor(TensorType type, int[] ints) Convert an array value to a dense tensor.static TensorDataasDenseTensor(TensorType type, long[] longs) Convert an array value to a dense tensor.static TensorDataasDenseTensor(TensorType type, List<?> values) Convert a list value to a dense tensor.static TensorDataasScalarTensor(TensorType type, Object scalar) Convert a scalar value to a tensor.static TensorDataasSparseTensor(TensorType type, Map<?, ?> values) Convert a map value to a sparse tensor.static TensorDataasSparseTensor(TensorType type, Set<?> dimensionValues) Convert a set value to a sparse tensor.
-
Method Details
-
asScalarTensor
Convert a scalar value to a tensor.- Parameters:
type- the type of the result.scalar- the scalar value.- Returns:
- a tensor with 0 dimensions and encapsulating the value.
-
asDenseTensor
Convert an array value to a dense tensor.- Parameters:
type- the type of the result.floats- the array value.- Returns:
- a tensor with 1 dimension (corresponding to the array's index) and encapsulating the values.
-
asDenseTensor
Convert an array value to a dense tensor.- Parameters:
type- the type of the result.ints- the array value.- Returns:
- a tensor with 1 dimension (corresponding to the array's index) and encapsulating the values.
-
asDenseTensor
Convert an array value to a dense tensor.- Parameters:
type- the type of the result.longs- the array value.- Returns:
- a tensor with 1 dimension (corresponding to the array's index) and encapsulating the values.
-
asDenseTensor
Convert an array value to a dense tensor.- Parameters:
type- the type of the result.doubles- the array value.- Returns:
- a tensor with 1 dimension (corresponding to the array's index) and encapsulating the values.
-
asDenseTensor
Convert a list value to a dense tensor.- Parameters:
type- the type of the result.values- the list value.- Returns:
- a tensor with 1 dimension (corresponding to the array's index) and encapsulating the values.
-
asSparseTensor
Convert a set value to a sparse tensor.- Parameters:
type- the type of the result.dimensionValues- the values for the single dimension.- Returns:
- a tensor with 1 dimension (corresponding to the set's values) and the tensor values set to 1.0.
-
asSparseTensor
Convert a map value to a sparse tensor.- Parameters:
type- the type of the result.values- the values for the single dimension and corresponding tensor values.- Returns:
- a tensor with 1 dimension (corresponding to the map's values) and the tensor values set to the map's values.
-