TensorBufferFloat

公開最終課 TensorBufferFloat

以浮點值代表資料緩衝區。

公用方法

DataType
getDataType()
傳回這個緩衝區的資料類型。
float[]
getFloatArray()
傳回儲存在這個緩衝區中的值的浮點陣列。
浮點值
getFloatValue(int absIndex)
傳回指定索引的浮點值。
整數 []
getIntArray()
傳回儲存在這個緩衝區中的值的 int 陣列。
攔截
getIntValue(int absIndex)
傳回指定索引的 int 值。
攔截
getTypeSize()
傳回陣列中單一元素的位元組數。
void
loadArray(int[] src, int[] Shape)
將特定形狀的 int 陣列載入這個緩衝區。
void
loadArray(float[] src, int[] Shape)
將浮點陣列載入特定形狀的緩衝區。

繼承的方法

公用方法

公開 DataType getDataType ()

傳回這個緩衝區的資料類型。

公開 float[] getFloatArray ()

傳回儲存在這個緩衝區中的值的浮點陣列。如果緩衝區屬於不同型別 值就會轉換為浮點值例如,TensorBufferUint8 中的值會從 uint8 轉換為 float。

公開 浮點值 getFloatValue (int absIndex)

傳回指定索引的浮點值。如果緩衝區的型別與浮點值不同, 值會轉換為浮點值。例如,讀取 TensorBufferUint8 中的值時,該值會先顯示為 uint8,然後再從 使用 uint8 來浮動值。

 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 待讀取值的絕對索引。

公開 整數 [] getIntArray ()

傳回儲存在這個緩衝區中的值的 int 陣列。如果緩衝區類型不同 系統會將值轉換為 int,而精確度可能會降低。例如: 從 TensorBufferFloat 取得值為 {400.32f, 23.04f} 的 int 陣列,輸出結果 為 {400, 23}。

公開 攔截 getIntValue (int absIndex)

傳回指定索引的 int 值。如果緩衝區的型別與 int 不同,則值 會轉換為 int例如,在讀取 TensorBufferFloat 中的值時 這些值會先以浮點值的形式呈現,接著再從浮點值轉換為 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 待讀取值的絕對索引。

公開 攔截 getTypeSize ()

傳回陣列中單一元素的位元組數。舉例來說,浮動緩衝區會 會傳回 4,而位元組緩衝區會傳回 1。

公開 void loadArray (int[] src, int[] 形狀)

將特定形狀的 int 陣列載入這個緩衝區。如果緩衝區屬於不同型別 大於 int,值會先轉換為緩衝區的型別,才載入到 但精確度可能會降低舉例來說,載入值為 {400、 -23} 轉換為 TensorBufferUint8,其值會限制為 [0, 255],然後 由 {255, 0} 投放到 uint8。

參數
src 要載入的來源陣列。
形狀 src 代表的張量形狀。

公開 void loadArray (float[] src, int[] 形狀)

將浮點陣列載入特定形狀的緩衝區。如果緩衝區屬於不同型別 的值會先轉換為緩衝區的型別,才載入到 但精確度可能會降低舉例來說,將浮點陣列載入 TensorBufferUint8,並將值設為 {400.32f, -23.04f},並將值限制為 [0, 255], 然後由 {255, 0} 投放到 uint8。

參數
src 要載入的來源陣列。
形狀 src 代表的張量形狀。