表示具有 8 位无符号整数值的数据缓冲区。
公共方法
DataType |
getDataType()
返回该缓冲区的数据类型。
|
浮点数 [] |
getFloatArray()
返回此缓冲区中存储的值的浮点数组。
|
浮点数 |
getFloatValue(整数索引)
返回指定索引处的浮点值。
|
整型 [] |
getIntArray()
返回此缓冲区中存储的值的 int 数组。
|
整型 |
getIntValue(整数索引)
返回指定索引处的 int 值。
|
整型 |
getTypeSize()
返回数组中单个元素的字节数。
|
void |
loadArray(int[] src, int[] shape)
将一个 int 数组加载到具有特定形状的缓冲区中。
|
void |
loadArray(float[] src, int[] shape)
将一个具有特定形状的浮点数数组加载到此缓冲区中。
|
继承的方法
公共方法
public float[] getFloatArray ()
返回此缓冲区中存储的值的浮点数组。如果缓冲区的类型与浮点数不同,这些值将转换为浮点数。例如,TensorBufferUint8
中的值将从 uint8 转换为 float。
public float getFloatValue (整数索引)
返回指定索引处的浮点值。如果缓冲区的类型与浮点数不同,则该值将转换为浮点数。例如,从 TensorBufferUint8
读取值时,该值将首先被读取为 uint8,然后将从 uint8 转换为 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);
参数
索引 | 要读取的值的绝对索引。 |
---|
public int[] getIntArray ()
返回此缓冲区中存储的值的 int 数组。如果缓冲区的类型与 int 不同,值将被转换为 int,并且可能会失去精度。例如,从值为 {400.32f, 23.04f} 的 TensorBufferFloat
获取 int 数组,输出结果为 {400, 23}。
public int getIntValue (int 索引)
返回指定索引处的 int 值。如果缓冲区的类型与 int 的类型不同,该值将转换为 int。例如,从 TensorBufferFloat
读取值时,系统会先将该值读取为 float,然后再从 float 转换为 int。可能会造成精度损失。
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.
参数
索引 | 要读取的值的绝对索引。 |
---|
public int getTypeSize ()
返回数组中单个元素的字节数。例如,浮点缓冲区将返回 4,字节缓冲区将返回 1。
public void loadArray (int[] src, int[] shape)
将一个 int 数组加载到具有特定形状的缓冲区中。如果缓冲区的类型与 int 不同,这些值会先转换为缓冲区的类型,然后再加载到缓冲区中,并且可能会丢失精度。例如,将值为 {400, -23} 的 int 数组加载到 TensorBufferUint8
中时,值将被限制为 [0, 255],然后由 {255, 0} 转换为 uint8。
参数
src | 要加载的源数组。 |
---|---|
shape | src 表示的张量的形状。 |
public void loadArray (float[] src, int[] shape)
将一个具有特定形状的浮点数数组加载到此缓冲区中。如果缓冲区的类型与浮点数不同,则值会在加载到缓冲区之前转换为缓冲区的类型,并且可能会丢失精度。例如,将一个浮点型数组加载到值为 {400.32f, -23.04f} 的 TensorBufferUint8
中,值将被限制为 [0, 255],然后由 {255, 0} 转换为 uint8。
参数
src | 要加载的源数组。 |
---|---|
shape | src 表示的张量的形状。 |