Struct Tensor
Data structure to hold Tensor values.
Namespace: UnityEngine.Perception.GroundTruth.DataModel
Syntax
public struct Tensor
Constructors
Tensor(Tensor.ElementType, Int32[])
Creates a tensor of passed in type and shape. It will allocated the memory for the byte buffer, but all bytes will be 0.
Declaration
public Tensor(Tensor.ElementType elementType, int[] shape)
Parameters
Type | Name | Description |
---|---|---|
Tensor.ElementType | elementType | The element type of the tensor |
Int32[] | shape | The shape of the tensor |
Tensor(Tensor.ElementType, Int32[], Byte[])
Creates a tensor of the passed in type, shape, and with the passed in buffer
Declaration
public Tensor(Tensor.ElementType elementType, int[] shape, byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Tensor.ElementType | elementType | The type of tensor |
Int32[] | shape | The shape of the tensor |
Byte[] | buffer | The byte buffer |
Properties
buffer
The raw buffer of the tensor. The buffer is the size of shape * element byte size.
Declaration
public byte[] buffer { readonly get; }
Property Value
Type | Description |
---|---|
Byte[] |
count
The total number of elements stored in the tensor. This value is equal to the product of all sizes.
Declaration
public int count { readonly get; }
Property Value
Type | Description |
---|---|
Int32 |
elementType
The element type of the tensor. The tensor class only supports tensors of the enumerated element types.
Declaration
public Tensor.ElementType elementType { readonly get; }
Property Value
Type | Description |
---|---|
Tensor.ElementType |
shape
The shape of the Tensor. Each value is its length in a dimension. For example a single dimension array of 7 values would have a shape of new [] { 7 }. A three dimension array of width 5, height 6, and depth 8, would have a shape of new [] {5, 6, 8}
Declaration
public int[] shape { readonly get; }
Property Value
Type | Description |
---|---|
Int32[] |
size
The total memory size of the tensor buffer. This value is equal to the product of count multiplied by the memory size of the element type.
Declaration
public int size { readonly get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
GetElementAt(Int32[], out Boolean)
Retrieve the casted element at the index in the tensor.
Declaration
public void GetElementAt(int[] index, out bool value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Boolean | value | The retrieved value |
GetElementAt(Int32[], out Byte)
Retrieve the casted element at the index in the tensor.
Declaration
public void GetElementAt(int[] index, out byte value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Byte | value | The retrieved value |
GetElementAt(Int32[], out Char)
Retrieve the casted element at the index in the tensor.
Declaration
public void GetElementAt(int[] index, out char value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Char | value | The retrieved value |
GetElementAt(Int32[], out Double)
Retrieve the casted element at the index in the tensor.
Declaration
public void GetElementAt(int[] index, out double value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Double | value | The retrieved value |
GetElementAt(Int32[], out Int32)
Retrieve the casted element at the index in the tensor.
Declaration
public void GetElementAt(int[] index, out int value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Int32 | value | The retrieved value |
GetElementAt(Int32[], out Int64)
Retrieve the casted element at the index in the tensor.
Declaration
public void GetElementAt(int[] index, out long value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Int64 | value | The retrieved value |
GetElementAt(Int32[], out Single)
Retrieve the casted element at the index in the tensor.
Declaration
public void GetElementAt(int[] index, out float value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Single | value | The retrieved value |
GetElementAt(Int32[], out UInt32)
Retrieve the casted element at the index in the tensor.
Declaration
public void GetElementAt(int[] index, out uint value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
UInt32 | value | The retrieved value |
SetElementAt(Int32[], Boolean)
Sets the value int the tensor to the passed in value.
Declaration
public void SetElementAt(int[] index, bool value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Boolean | value | The value to set |
SetElementAt(Int32[], Byte)
Sets the value int the tensor to the passed in value.
Declaration
public void SetElementAt(int[] index, byte value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Byte | value | The value to set |
SetElementAt(Int32[], Char)
Sets the value int the tensor to the passed in value.
Declaration
public void SetElementAt(int[] index, char value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Char | value | The value to set |
SetElementAt(Int32[], Double)
Sets the value int the tensor to the passed in value.
Declaration
public void SetElementAt(int[] index, double value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Double | value | The value to set |
SetElementAt(Int32[], Int32)
Sets the value int the tensor to the passed in value.
Declaration
public void SetElementAt(int[] index, int value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Int32 | value | The value to set |
SetElementAt(Int32[], Int64)
Sets the value int the tensor to the passed in value.
Declaration
public void SetElementAt(int[] index, long value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Int64 | value | The value to set |
SetElementAt(Int32[], Single)
Sets the value int the tensor to the passed in value.
Declaration
public void SetElementAt(int[] index, float value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
Single | value | The value to set |
SetElementAt(Int32[], UInt32)
Sets the value int the tensor to the passed in value.
Declaration
public void SetElementAt(int[] index, uint value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | index | The index of the element. The index array needs to be the size of the shape, with each element in the range of the shape's dimension |
UInt32 | value | The value to set |