Class BufferUtils
java.lang.Object
com.linkedin.feathr.common.tensorbuilder.BufferUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcompareBytes(byte[] left, byte[] right) static ByteBuffercreateByteBuffer(boolean[] booleans, Primitive valueType) static ByteBuffercreateByteBuffer(double[] doubles, Primitive valueType) Creates a ByteBuffer of specified valueType from an array of doublesstatic ByteBuffercreateByteBuffer(float[] floats, Primitive valueType) Creates a ByteBuffer of specified valueType from an array of floatsstatic ByteBuffercreateByteBuffer(int[] ints, Primitive valueType) Creates a ByteBuffer of specified valueType from an array of intsstatic ByteBuffercreateByteBuffer(long[] longs, Primitive valueType) Creates a ByteBuffer of specified valueType from an array of longsstatic ByteBuffercreateByteBuffer(List<?> values, Primitive valueType) Creates a byteBuffer of specified valueType from a collection of numbers or strings.static StringdecodeString(byte[] bytes) static StringdecodeString(ByteBuffer buffer) static intdecodeVarint(ByteBuffer buffer) static ByteBufferencodeString(String string) static intencodeVarint(ByteBuffer buffer, int value) Based on EncodeVarint64 in TensorFlow: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/lib/core/coding.cc#L110 Note that Java int is 32 bit, so this code is not fully identical.static intprimitiveSize(Primitive valueType) Return size of primitive types in terms of bytesstatic intvarintLength(int value) Based on VarintLength in TensorFlow: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/lib/core/coding.cc#L127 Note that Java int is 32 bit, so this code is not fully identical.
-
Method Details
-
encodeString
-
decodeString
-
decodeString
-
compareBytes
public static int compareBytes(byte[] left, byte[] right) -
primitiveSize
Return size of primitive types in terms of bytes- Parameters:
valueType- type for which size is required- Returns:
- size of the valueType in terms of bytes
-
createByteBuffer
Creates a byteBuffer of specified valueType from a collection of numbers or strings. -
createByteBuffer
Creates a ByteBuffer of specified valueType from an array of floats- Parameters:
floats- an array of floatsvalueType- floats are coerced to this type before being added to ByteBuffer- Returns:
- ByteBuffer containing all floats coerced into specified valueType
-
createByteBuffer
Creates a ByteBuffer of specified valueType from an array of longs- Parameters:
longs- an array of longsvalueType- longs are coerced to this type before being added to ByteBuffer- Returns:
- ByteBuffer containing all longs coerced into specified valueType
-
createByteBuffer
Creates a ByteBuffer of specified valueType from an array of ints- Parameters:
ints- an array of intsvalueType- ints are coerced to this type before being added to ByteBuffer- Returns:
- ByteBuffer containing all ints coerced into specified valueType
-
createByteBuffer
Creates a ByteBuffer of specified valueType from an array of doubles- Parameters:
doubles- an array of doublesvalueType- doubles are coerced to this type before being added to ByteBuffer- Returns:
- ByteBuffer containing all doubles coerced into specified valueType
-
createByteBuffer
-
varintLength
public static int varintLength(int value) Based on VarintLength in TensorFlow: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/lib/core/coding.cc#L127 Note that Java int is 32 bit, so this code is not fully identical. -
encodeVarint
Based on EncodeVarint64 in TensorFlow: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/lib/core/coding.cc#L110 Note that Java int is 32 bit, so this code is not fully identical.- Returns:
- the length of the encoding.
-
decodeVarint
-