Package com.linkedin.feathr.common
Class TensorUtils
java.lang.Object
com.linkedin.feathr.common.TensorUtils
INTERNAL debugging utility functions.
In the future, this class may be deprecated.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic TensorDataconvertNestedMapToTensor(Map<String, Object> map, TensorType tensorType) Convert a nested map into Tensor.static TensorDataconvertNestedMapToTensor(Map<String, Object> map, TensorType tensorType, TensorBuilderFactory tensorBuilderFactory) Convert a nested map into Tensor.static Map<ReadableTuple,Float> convertTensorToMap(TensorData tensor) Converts a tensor to a map.static Map<ReadableTuple,Object> Converts a tensor to a map.static LOLTensorDatastatic String[]convertToStrings(TensorType tensorType, ReadableTuple readableTuple, int numCols) static StringgetDebugString(TensorType type, TensorData data, int maxStringLenLimit) static long[]getShape(TensorType tensorType) Get shape of the tensor as an arraystatic TensorTypeparseTensorType(String syntax) Deprecated.static TensorDatapopulateTensor(Representable[] columnTypes, Object[][] data, TensorBuilder tensorBuilder) Creates a Tensor object with the associated columnTypes and data using TensorBuilderstatic intsafeRatio(int numerator, int denominator) static <K> Function<ReadableTuple,K> wrapKeyGen(TensorType inputTensor, Function<String[], K> keyGen)
-
Field Details
-
DEFAULT_MAX_STRING_LEN
public static final int DEFAULT_MAX_STRING_LEN- See Also:
-
-
Method Details
-
getDebugString
-
convertNestedMapToTensor
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 usingTensorType.getDimensionTypes()along with DimensionType#setDimensionValue(WriteableTuple, int, Object)} method and populates the output tensor- Parameters:
map- A nested map to be converted to tensortensorType- 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 usingTensorType.getDimensionTypes()(int, String)} method and populates the output tensor- Parameters:
map- A nested map to be converted to tensortensorType- TensorType of the output tensortensorBuilderFactory- Factory to generate correct implementation of tensor- Returns:
- A tensor representation of input nested map
-
convertTensorToMap
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
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
-
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
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 tensordata- 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 itensorBuilder- tensorbuilder representing the data
-
parseTensorType
Deprecated. -
safeRatio
public static int safeRatio(int numerator, int denominator)
-
TensorTypes.parseTensorType(java.lang.String)