Class TensorUtils

java.lang.Object
com.linkedin.feathr.common.TensorUtils

@InternalApi public final class TensorUtils extends Object
INTERNAL debugging utility functions. In the future, this class may be deprecated.
  • Field Details

    • DEFAULT_MAX_STRING_LEN

      public static final int DEFAULT_MAX_STRING_LEN
      See Also:
  • Method Details

    • getDebugString

      public static String getDebugString(TensorType type, TensorData data, int maxStringLenLimit)
    • convertNestedMapToTensor

      public static TensorData convertNestedMapToTensor(Map<String,Object> map, TensorType tensorType)
      Convert a nested map into Tensor. A nested map contains keys in string format and value can either be a Primitive or another map. This method converts all the keys to their representation using TensorType.getDimensionTypes() along with DimensionType#setDimensionValue(WriteableTuple, int, Object)} method and populates the output tensor
      Parameters:
      map - A nested map to be converted to tensor
      tensorType - TensorType of the output tensor
    • convertNestedMapToTensor

      public static TensorData convertNestedMapToTensor(Map<String,Object> map, TensorType tensorType, TensorBuilderFactory tensorBuilderFactory)
      Convert a nested map into Tensor. A nested map contains keys in string format and value can either be a Primitive or another map. This method converts all the keys to their representation using TensorType.getDimensionTypes() (int, String)} method and populates the output tensor
      Parameters:
      map - A nested map to be converted to tensor
      tensorType - TensorType of the output tensor
      tensorBuilderFactory - Factory to generate correct implementation of tensor
      Returns:
      A tensor representation of input nested map
    • convertTensorToMap

      public static Map<ReadableTuple,Float> convertTensorToMap(TensorData tensor)
      Converts a tensor to a map. The map has keys of type ReadableTuple. The ReadableTuple corresponding to a row in the tensor and the value of the map corresponds to the FLOAT value of the given row in the tensor.
      Parameters:
      tensor - input tensor to convert to a map
      Returns:
      A map that represents the tensor
    • convertTensorToMapWithGenericValues

      public static Map<ReadableTuple,Object> convertTensorToMapWithGenericValues(TensorData tensor)
      Converts a tensor to a map. The map has keys of type ReadableTuple. The ReadableTuple corresponding to a row in the tensor and the value of the map corresponds to the Primitive value of the given row in the tensor.
      Parameters:
      tensor - input tensor to convert to a map
      Returns:
      A map that represents the tensor
    • convertToLOLTensor

      public static LOLTensorData convertToLOLTensor(TensorData ut)
    • convertToStrings

      public static String[] convertToStrings(TensorType tensorType, ReadableTuple readableTuple, int numCols)
    • wrapKeyGen

      public static <K> Function<ReadableTuple,K> wrapKeyGen(TensorType inputTensor, Function<String[],K> keyGen)
    • getShape

      public static long[] getShape(TensorType tensorType)
      Get shape of the tensor as an array
      Parameters:
      tensorType - Type for which shape needs to be computed
      Returns:
      long array with each element indicating shape of the dimensions
    • populateTensor

      public static TensorData populateTensor(Representable[] columnTypes, Object[][] data, TensorBuilder tensorBuilder)
      Creates a Tensor object with the associated columnTypes and data using TensorBuilder
      Parameters:
      columnTypes - columnTypes of the tensor
      data - data within the tensor data.length corresponds to the number of rows the tensor has data[i].length corresponds to the number of columns in a tensor row. Each element in data[i] corresponds to the dimension/value of the tensor at row i
      tensorBuilder - tensorbuilder representing the data
    • parseTensorType

      @Deprecated public static TensorType parseTensorType(String syntax)
    • safeRatio

      public static int safeRatio(int numerator, int denominator)