TensorContent

@RequiresApi(value = 27)
class TensorContent : AutoCloseable

Content read back from a GlobalTensor.

Parameters

shMem

The Shared memory carrying the content read back from the tensor.

tensor

The global tensor being read back from.

Types

Link copied to clipboard
class Slice(content: TensorContent, range: IntRange)

A handy class to easily read a range of the tensor's content.

Properties

Link copied to clipboard
val buffer: ByteBuffer

The ByteBuffer containing the global tensor's content.

Functions

Link copied to clipboard

Writes the content back to reset the tensor. This method uses the data currently held by this TensorContent to overwrite the tensor's content.

Link copied to clipboard
suspend fun applyChangeSuspend()

The suspend version of applyChange.

Link copied to clipboard
open override fun close()

Unmaps the buffer and closes the shared memory. Do not call any methods after closing it.

Link copied to clipboard
operator fun get(index: Int): Number

Gets a value from the tensor's content by index. The tensor must be of Tensor.DataType.FLOAT64, Tensor.DataType.FLOAT32, Tensor.DataType.INT32, Tensor.DataType.INT16 or Tensor.DataType.INT8 datatypes. Otherwise, you may consider to directly use buffer to read the content byte-by-byte.

operator fun get(range: IntRange): TensorContent.Slice

Gets a range of values from the tensor's content. The tensor must be of Tensor.DataType.FLOAT64, Tensor.DataType.FLOAT32, Tensor.DataType.INT32, Tensor.DataType.INT16 or Tensor.DataType.INT8 datatypes. Otherwise, you may consider to directly use buffer to read the content byte-by-byte.

Link copied to clipboard
fun setData(doubleArray: DoubleArray, offset: Int = 0)

If the tensor from which the content is read back is of Tensor.DataType.FLOAT64 datatype, you can use this method to update the content to a double array. Then, you can call applyChange to apply the update to the tensor.

fun setData(floatArray: FloatArray, offset: Int = 0)

If the tensor from which the content is read back is of Tensor.DataType.FLOAT32 datatype, you can use this method to update the content to a float array. Then, you can call applyChange to apply the update to the tensor.

fun setData(intArray: IntArray, offset: Int = 0)

If the tensor from which the content is read back is of Tensor.DataType.INT32 datatype, you can use this method to update the content to an integer array. Then, you can call applyChange to apply the update to the tensor.

fun setData(shortArray: ShortArray, offset: Int = 0)

If the tensor from which the content is read back is of Tensor.DataType.INT16 datatype, you can use this method to update the content to a short array. Then, you can call applyChange to apply the update to the tensor.

Link copied to clipboard
fun update()

Updates to the tensor's up-to-date's content. If you have changed the content, but have not called the applyChange or applyChangeSuspend to write the updated content back to the tensor, the change will be discarded.

Link copied to clipboard
suspend fun updateSuspend()

Suspended version of update.