Class TensorInt
Represents data in a multidimensional array-like structure.
Ownership and lifetime:
- Disposed needs to be called on the main thread.
- Ownership is always to the owner of the object.
Data Representation:
- TensorShape represents the data layout of the tensor
- Data is held by a tensorData (ITensorData) which can be on a given backend
- Data is stored in a flattened row major format
- Data can be pending (ie computation is being done in parallel)
- call CompleteAllPendingOperations for a blocking call to finish computing the tensor's data Data can be in a non readable type (GPU/NPU)
- Call CompleteAllPendingOperations to finish computing the tensor's data
- Call ReadbackAndClone or ReadBackAndCloneAsync to allow reading the tensor's data
Data manipulation
- ToReadOnlyArray returns a copy of the tensor's data
- dataOnBackend can be manipulated directly to avoid a unnecessary copy see ComputeTensorData/BurstTensorData for info
Implements
Inherited Members
Namespace: Unity.Sentis
Assembly: Unity.Sentis.dll
Syntax
public class TensorInt : Tensor, IDisposable
Constructors
TensorInt(int)
Initializes and returns a scalar tensor with the value of srcData.
Declaration
public TensorInt(int srcData)
Parameters
| Type | Name | Description |
|---|---|---|
| int | srcData | The data element of the tensor. |
TensorInt(TensorShape, int[], int)
Initializes and returns a tensor with specified shape and an int[] array of srcData data. Sentis reads srcData from dataStartIndex.
srcData.Length - dataStartIndex must be bigger than or equal to shape.length.
Declaration
public TensorInt(TensorShape shape, int[] srcData, int dataStartIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TensorShape | shape | The shape of the tensor. |
| int[] | srcData | The data elements of the tensor. |
| int | dataStartIndex | The index of the first tensor element in the srcData array. |
TensorInt(TensorShape, NativeArray<int>, int)
Initializes and returns a tensor with specified shape and a native int array of srcData data. Sentis reads srcData from dataStartIndex.
srcData.Length - dataStartIndex must be bigger than or equal to shape.length.
Declaration
public TensorInt(TensorShape shape, NativeArray<int> srcData, int dataStartIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| TensorShape | shape | The shape of the tensor. |
| NativeArray<int> | srcData | The data elements of the tensor. |
| int | dataStartIndex | The index of the first tensor element in the srcData native array. |
Properties
this[int]
Returns the tensor element at offset d0.
Declaration
public int this[int d0] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | d0 | Axis 0. |
Property Value
| Type | Description |
|---|---|
| int |
this[int, int]
Returns the tensor element at offset (d1, d0), which is position d1 * stride0 + d0.
Declaration
public int this[int d1, int d0] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | d1 | Axis 1. |
| int | d0 | Axis 0. |
Property Value
| Type | Description |
|---|---|
| int |
this[int, int, int]
Returns the tensor element at offset (d2, d1, d0), which is position d2 * stride1 + d1 * stride0 + d0.
Declaration
public int this[int d2, int d1, int d0] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | d2 | Axis 2. |
| int | d1 | Axis 1. |
| int | d0 | Axis 0. |
Property Value
| Type | Description |
|---|---|
| int |
this[int, int, int, int]
Returns the tensor element at offset (d3, d2, d1, d0), which is position d3 * stride2 + d2 * stride1 + d1 * stride0 + d0 in this tensor.
Declaration
public int this[int d3, int d2, int d1, int d0] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | d3 | Axis 3. |
| int | d2 | Axis 2. |
| int | d1 | Axis 1. |
| int | d0 | Axis 0. |
Property Value
| Type | Description |
|---|---|
| int |
this[int, int, int, int, int]
Returns the tensor element at offset (d4, d3, d2, d1, d0), which is position d4 * stride3 + d3 * stride2 + d2 * stride1 + d1 * stride0 + d0.
Declaration
public int this[int d4, int d3, int d2, int d1, int d0] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | d4 | Axis 4. |
| int | d3 | Axis 3. |
| int | d2 | Axis 2. |
| int | d1 | Axis 1. |
| int | d0 | Axis 0. |
Property Value
| Type | Description |
|---|---|
| int |
this[int, int, int, int, int, int]
Returns the tensor element at offset (d5, d4, d3, d2, d1, d0), which is position d5 * stride4 + d4 * stride3 + d3 * stride2 + d2 * stride1 + d1 * stride0 + d0.
Declaration
public int this[int d5, int d4, int d3, int d2, int d1, int d0] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | d5 | Axis 5. |
| int | d4 | Axis 4. |
| int | d3 | Axis 3. |
| int | d2 | Axis 2. |
| int | d1 | Axis 1. |
| int | d0 | Axis 0. |
Property Value
| Type | Description |
|---|---|
| int |
this[int, int, int, int, int, int, int]
Returns the tensor element at offset (d6, d5, d4, d3, d2, d1, d0), which is position d6 * stride5 + d5 * stride4 + d4 * stride3 + d3 * stride2 + d2 * stride1 + d1 * stride0 + d0.
Declaration
public int this[int d6, int d5, int d4, int d3, int d2, int d1, int d0] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | d6 | Axis 6. |
| int | d5 | Axis 5. |
| int | d4 | Axis 4. |
| int | d3 | Axis 3. |
| int | d2 | Axis 2. |
| int | d1 | Axis 1. |
| int | d0 | Axis 0. |
Property Value
| Type | Description |
|---|---|
| int |
this[int, int, int, int, int, int, int, int]
Returns the tensor element at offset (d7, d6, d5, d4, d3, d2, d1, d0), which is position d7 * stride6 + d6 * stride5 + d5 * stride4 + d4 * stride3 + d3 * stride2 + d2 * stride1 + d1 * stride0 + d0.
Declaration
public int this[int d7, int d6, int d5, int d4, int d3, int d2, int d1, int d0] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | d7 | Axis 7. |
| int | d6 | Axis 6. |
| int | d5 | Axis 5. |
| int | d4 | Axis 4. |
| int | d3 | Axis 3. |
| int | d2 | Axis 2. |
| int | d1 | Axis 1. |
| int | d0 | Axis 0. |
Property Value
| Type | Description |
|---|---|
| int |
count
The length of the tensor.
Declaration
public override int count { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
dataType
The data type of the elements of the tensor.
Declaration
public override DataType dataType { get; }
Property Value
| Type | Description |
|---|---|
| DataType |
Overrides
Methods
AllocNoData(TensorShape)
Initializes and returns a tensor with the specified shape and with no data.
Declaration
public static TensorInt AllocNoData(TensorShape shape)
Parameters
| Type | Name | Description |
|---|---|---|
| TensorShape | shape | The shape of the tensor. |
Returns
| Type | Description |
|---|---|
| TensorInt | The instantiated empty tensor. |
AllocZeros(TensorShape)
Initializes and returns a tensor with the specified shape and filled with 0.
Declaration
public static TensorInt AllocZeros(TensorShape shape)
Parameters
| Type | Name | Description |
|---|---|---|
| TensorShape | shape | The shape of the tensor. |
Returns
| Type | Description |
|---|---|
| TensorInt | The instantiated zero tensor. |
ReadbackAndClone()
Completes all scheduled tensor operations on device.
Declaration
public TensorInt ReadbackAndClone()
Returns
| Type | Description |
|---|---|
| TensorInt | returns cpu copy of the tensor. |
ReadbackAndCloneAsync()
Schedules asynchronous download task of the internal data.
Declaration
public Awaitable<TensorInt> ReadbackAndCloneAsync()
Returns
| Type | Description |
|---|---|
| Awaitable<TensorInt> | awaitable tensor on the cpu. |
ToReadOnlyArray()
Returns a copy of linear memory representation of the data in this tensor.
the returned array is a deepcopy of the tensor, the caller of this methods is now responsible for it. If you modify the contents of the returned array, it will not modify the underlying tensor
Declaration
public int[] ToReadOnlyArray()
Returns
| Type | Description |
|---|---|
| int[] | Int array copy of tensor data. |
ToReadOnlyNativeArray()
Returns a NativeArray on the linear memory representation of the data in this tensor.
Declaration
public NativeArray<int>.ReadOnly ToReadOnlyNativeArray()
Returns
| Type | Description |
|---|---|
| NativeArray<int>.ReadOnly | NativeArray of tensor data. |
ToReadOnlySpan()
Returns a ReadOnlySpan on the linear memory representation of the data in this tensor.
Declaration
public ReadOnlySpan<int> ToReadOnlySpan()
Returns
| Type | Description |
|---|---|
| ReadOnlySpan<int> | Span of tensor data. |