ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

TensorBufferUint8

public final class TensorBufferUint8

Represents data buffer with 8-bit unsigned integer values.

Public Methods

DataType
getDataType()
Returns the data type of this buffer.
float[]
getFloatArray()
Returns a float array of the values stored in this buffer.
float
getFloatValue(int index)
Returns a float value at a given index.
int[]
getIntArray()
Returns an int array of the values stored in this buffer.
int
getIntValue(int index)
Returns an int value at a given index.
int
getTypeSize()
Returns the number of bytes of a single element in the array.
void
loadArray(int[] src, int[] shape)
Loads an int array into this buffer with specific shape.
void
loadArray(float[] src, int[] shape)
Loads a float array into this buffer with specific shape.

Inherited Methods

Public Methods

public DataType getDataType ()

Returns the data type of this buffer.

public float[] getFloatArray ()

Returns a float array of the values stored in this buffer. If the buffer is of different types than float, the values will be converted into float. For example, values in TensorBufferUint8 will be converted from uint8 to float.

public float getFloatValue (int index)

Returns a float value at a given index. If the buffer is of different types than float, the value will be converted into float. For example, when reading a value from TensorBufferUint8, the value will be first read out as uint8, and then will be converted from uint8 to float.

 For example, a TensorBuffer with shape {2, 3} that represents the following array,
 [[0.0f, 1.0f, 2.0f], [3.0f, 4.0f, 5.0f]].

 The fourth element (whose value is 3.0f) in the TensorBuffer can be retrieved by:
 float v = tensorBuffer.getFloatValue(3);
 

Parameters
index The absolute index of the value to be read.

public int[] getIntArray ()

Returns an int array of the values stored in this buffer. If the buffer is of different type than int, the values will be converted into int, and loss of precision may apply. For example, getting an int array from a TensorBufferFloat with values {400.32f, 23.04f}, the output is {400, 23}.

public int getIntValue (int index)

Returns an int value at a given index. If the buffer is of different types than int, the value will be converted into int. For example, when reading a value from TensorBufferFloat, the value will be first read out as float, and then will be converted from float to int. Loss of precision may apply.

 For example, a TensorBuffer with shape {2, 3} that represents the following array,
 [[0.0f, 1.0f, 2.0f], [3.0f, 4.0f, 5.0f]].

 The fourth element (whose value is 3.0f) in the TensorBuffer can be retrieved by:
 int v = tensorBuffer.getIntValue(3);
 Note that v is converted from 3.0f to 3 as a result of type conversion.
 

Parameters
index The absolute index of the value to be read.

public int getTypeSize ()

Returns the number of bytes of a single element in the array. For example, a float buffer will return 4, and a byte buffer will return 1.

public void loadArray (int[] src, int[] shape)

Loads an int array into this buffer with specific shape. If the buffer is of different types than int, the values will be converted into the buffer's type before being loaded into the buffer, and loss of precision may apply. For example, loading an int array with values {400, -23} into a TensorBufferUint8 , the values will be clamped to [0, 255] and then be casted to uint8 by {255, 0}.

Parameters
src The source array to be loaded.
shape Shape of the tensor that src represents.

public void loadArray (float[] src, int[] shape)

Loads a float array into this buffer with specific shape. If the buffer is of different types than float, the values will be converted into the buffer's type before being loaded into the buffer, and loss of precision may apply. For example, loading a float array into a TensorBufferUint8 with values {400.32f, -23.04f}, the values will be clamped to [0, 255] and then be casted to uint8 by {255, 0}.

Parameters
src The source array to be loaded.
shape Shape of the tensor that src represents.