表示具有浮点值的数据缓冲区。
公共方法
| DataType |
getDataType()
返回此缓冲区的数据类型。
|
| float[] |
getFloatArray()
返回存储在此缓冲区中的值的浮点数组。
|
| 浮点数 |
getFloatValue(int absIndex)
返回指定索引处的浮点值。
|
| 整数 [] |
getIntArray()
返回存储在此缓冲区中的值的整型数组。
|
| 整数 |
getIntValue(int absIndex)
返回指定索引处的整数值。
|
| 整数 |
getTypeSize()
返回数组中单个元素的字节数。
|
| 无效 |
loadArray(int[] src, int[] 形状)
将一个整数数组加载到具有特定形状的该缓冲区。
|
| 无效 |
loadArray(float[] src, int[] 形状)
将一个具有特定形状的浮点数数组加载到此缓冲区。
|
继承的方法
公共方法
<ph type="x-smartling-placeholder"></ph> 公开 float[] getFloatArray ()
返回存储在此缓冲区中的值的浮点数组。如果缓冲区的类型不同
而不是浮点数,这些值将转换为浮点数。例如,TensorBufferUint8 中的值将从 uint8 转换为 float。
<ph type="x-smartling-placeholder"></ph> 公开 浮点数 getFloatValue (int absIndex)
返回指定索引处的浮点值。如果缓冲区的类型与浮点数不同,则
值将转换为浮点数。例如,从 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);
参数
| absIndex | 要读取的值的绝对索引。 |
|---|
<ph type="x-smartling-placeholder"></ph> 公开 整数 [] getIntArray ()
返回存储在此缓冲区中的值的整型数组。如果缓冲区的类型
而不是 int,这些值将转换为 int,并且可能会损失精度。例如:
从 TensorBufferFloat 获取值为 {400.32f, 23.04f} 的 int 数组,输出
为 {400, 23}。
<ph type="x-smartling-placeholder"></ph> 公开 整数 getIntValue (int absIndex)
返回指定索引处的整数值。如果缓冲区的类型与 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.
参数
| absIndex | 要读取的值的绝对索引。 |
|---|
<ph type="x-smartling-placeholder"></ph> 公开 整数 getTypeSize ()
返回数组中单个元素的字节数。例如,浮动缓冲区将 返回 4,而字节缓冲区会返回 1。
<ph type="x-smartling-placeholder"></ph> 公开 无效 loadArray (int[] src, int[] 形状)
将一个整数数组加载到具有特定形状的该缓冲区。如果缓冲区的类型不同
比 int 多,这些值将转换为缓冲区的类型,然后再加载到
缓冲区,还可能会损失精度。例如,加载值为 {400,
-23} 转换为 TensorBufferUint8,则这些值将被限制为 [0, 255],然后被限制为
已由 {255, 0} 转换为 uint8。
参数
| src | 要加载的源数组。 |
|---|---|
| 形状 | src 表示的张量的形状。 |
<ph type="x-smartling-placeholder"></ph> 公开 无效 loadArray (float[] src, int[] 形状)
将一个具有特定形状的浮点数数组加载到此缓冲区。如果缓冲区的类型不同
而不是浮点数,这些值会在加载到
缓冲区,还可能会损失精度。例如,将浮点数组加载到值为 {400.32f, -23.04f} 的 TensorBufferUint8 中,这些值将被限制为 [0, 255],
然后由 {255, 0} 转换为 uint8。
参数
| src | 要加载的源数组。 |
|---|---|
| 形状 | src 表示的张量的形状。 |