Class Tensors

java.lang.Object
com.linkedin.feathr.common.tensor.Tensors

public final class Tensors extends Object
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 Details

    • asScalarTensor

      public static TensorData asScalarTensor(TensorType type, Object scalar)
      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

      public static TensorData asDenseTensor(TensorType type, float[] floats)
      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

      public static TensorData asDenseTensor(TensorType type, int[] ints)
      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

      public static TensorData asDenseTensor(TensorType type, long[] longs)
      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

      public static TensorData asDenseTensor(TensorType type, double[] doubles)
      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

      public static TensorData asDenseTensor(TensorType type, List<?> values)
      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

      public static TensorData asSparseTensor(TensorType type, Set<?> dimensionValues)
      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

      public static TensorData asSparseTensor(TensorType type, Map<?,?> values)
      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.