Class ArrayTensorData
Represents internal Tensor
data backed by a managed array.
Inheritance
ArrayTensorData
Syntax
public class ArrayTensorData : ITensorData, IDisposable, IConvertibleToBurstTensorData, IConvertibleToComputeTensorData, IReadableTensorData
Constructors
ArrayTensorData(TensorShape, Array, Boolean)
Initializes and returns an instance of ArrayTensorData
with a given array of data.
Declaration
public ArrayTensorData(TensorShape shape, Array data, bool clearOnInit = true)
Parameters
Type |
Name |
Description |
TensorShape |
shape |
The shape of the tensor data.
|
Array |
data |
The data to use as backing data.
|
Boolean |
clearOnInit |
|
ArrayTensorData(TensorShape, Boolean)
Initializes and returns an instance of ArrayTensorData
, and allocates storage for a tensor with the shape of shape
.
Declaration
public ArrayTensorData(TensorShape shape, bool clearOnInit = true)
Parameters
Type |
Name |
Description |
TensorShape |
shape |
The shape of the tensor data to allocate.
|
Boolean |
clearOnInit |
Whether to zero the data on allocation. The default value is true .
|
ArrayTensorData(TensorShape, NativeTensorArray, Int32, Boolean)
Initializes and returns an instance of ArrayTensorData
with given storage and offset.
Declaration
public ArrayTensorData(TensorShape shape, NativeTensorArray data, int offset = 0, bool clearOnInit = true)
Parameters
Type |
Name |
Description |
TensorShape |
shape |
The shape of the tensor data.
|
NativeTensorArray |
data |
|
Int32 |
offset |
The integer offset from the start of the backing array. The default value is 0.
|
Boolean |
clearOnInit |
Whether to zero the data on instantiation. The default value is true .
|
Properties
array
The NativeTensorArray
managed array containing the Tensor
data.
Declaration
public NativeTensorArray array { get; }
Property Value
deviceType
On what device backend are the data elements stored.
Declaration
public DeviceType deviceType { get; }
Property Value
Implements
maxCapacity
The maximum count of the stored data elements.
Declaration
public int maxCapacity { get; }
Property Value
Implements
shape
The shape of the tensor using this data as a TensorShape
.
Declaration
public TensorShape shape { get; }
Property Value
Methods
AsyncReadbackRequest(Action<Boolean>)
Schedules asynchronous readback of the internal data.
Invokes callback when async readback is finished.
Boolean indicates if async readback is successful.
Declaration
public void AsyncReadbackRequest(Action<bool> callback = null)
Parameters
Implements
Clone()
Returns a deep copy of the internal storage.
Declaration
public ITensorData Clone()
Returns
Implements
CompleteAllPendingOperations()
Blocking call to make sure that internal data is correctly written to and available for CPU read back.
Declaration
public void CompleteAllPendingOperations()
Implements
ConvertToBurstTensorData(TensorShape)
Implement this method to convert to BurstTensorData
.
Declaration
public BurstTensorData ConvertToBurstTensorData(TensorShape shape)
Parameters
Returns
Implements
ConvertToComputeTensorData(TensorShape)
Implement this method to convert to ComputeTensorData
.
Declaration
public ComputeTensorData ConvertToComputeTensorData(TensorShape shape)
Parameters
Returns
Implements
Dispose()
Disposes of the ArrayTensorData
and any associated memory.
Declaration
Implements
Download<T>(Int32, Int32)
Returns data from internal storage.
Declaration
public NativeArray<T> Download<T>(int dstCount, int srcOffset = 0)
where T : struct
Parameters
Type |
Name |
Description |
Int32 |
dstCount |
|
Int32 |
srcOffset |
|
Returns
Type Parameters
Implements
Get<T>(Int32)
Returns a data element at index
.
Declaration
public T Get<T>(int index)
where T : struct
Parameters
Type |
Name |
Description |
Int32 |
index |
|
Returns
Type Parameters
Implements
GetReadOnlyNativeArrayHandle<T>(Int32, Int32)
Returns a ReadOnlyNativeArray handle on the linear memory data.
Declaration
public NativeArray<T>.ReadOnly GetReadOnlyNativeArrayHandle<T>(int dstCount, int srcOffset = 0)
where T : struct
Parameters
Type |
Name |
Description |
Int32 |
dstCount |
|
Int32 |
srcOffset |
|
Returns
Type Parameters
Implements
IsAsyncReadbackRequestDone()
Checks if asynchronous readback request it done.
Returns true if async readback is successful.
Declaration
public bool IsAsyncReadbackRequestDone()
Returns
Implements
Pin(Tensor, Boolean)
Moves the tensor into memory on the CPU backend device.
The Tensor
to move to the CPU.
Whether to initialize the backend data. The default value is true
.
Declaration
public static ArrayTensorData Pin(Tensor X, bool clearOnInit = true)
Parameters
Returns
Reserve(Int32)
Reserves memory for count
elements.
Declaration
public void Reserve(int count)
Parameters
Type |
Name |
Description |
Int32 |
count |
|
Implements
Set<T>(Int32, T)
Sets value
data element at index
.
Declaration
public void Set<T>(int index, T value)
where T : struct
Parameters
Type |
Name |
Description |
Int32 |
index |
|
T |
value |
|
Type Parameters
Implements
ToArray<T>(Int32, Int32)
Returns a array that is a copy of the linear memory data.
Declaration
public T[] ToArray<T>(int dstCount, int srcOffset = 0)
where T : struct
Parameters
Type |
Name |
Description |
Int32 |
dstCount |
|
Int32 |
srcOffset |
|
Returns
Type Parameters
Implements
ToReadOnlySpan<T>(Int32, Int32)
Returns a ReadOnlySpan on the linear memory data.
Declaration
public ReadOnlySpan<T> ToReadOnlySpan<T>(int dstCount, int srcOffset = 0)
where T : struct
Parameters
Type |
Name |
Description |
Int32 |
dstCount |
|
Int32 |
srcOffset |
|
Returns
Type |
Description |
ReadOnlySpan<T> |
|
Type Parameters
Implements
ToString()
Returns a summary of the storage used by the tensor array, as a string.
Declaration
public override string ToString()
Returns
Overrides
Upload<T>(NativeArray<T>, Int32, Int32)
Uploads the tensor data to internal storage.
Declaration
public void Upload<T>(NativeArray<T> data, int srCount, int srcOffset = 0)
where T : struct
Parameters
Type Parameters
Implements