Class Tensor
Multidimensional array-like data storage
Namespace: Unity.Barracuda
Syntax
public class Tensor : UniqueResourceId, IDisposable, ITensorStatistics, IUniqueResource
Constructors
Tensor(Int32, Int32, ComputeBuffer, String)
Create a Tensor of shape [1,1,N,1,1,1,1,C], associated ComputeBuffer srcBuffer filled with tensor values, and an optional debug name.
srcBuffer must be larger than n*c.
Declaration
public Tensor(int n, int c, ComputeBuffer srcBuffer, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | c | channels  | 
| ComputeBuffer | srcBuffer | source buffer  | 
| String | name | name  | 
Tensor(Int32, Int32, Int32, Int32, ComputeBuffer, String)
Create a Tensor of shape [1,1,N,1,1,H,W,C], associated ComputeBuffer srcBuffer filled with tensor values, and an optional debug name.
srcBuffer must be larger than n*h*w*c.
Declaration
public Tensor(int n, int h, int w, int c, ComputeBuffer srcBuffer, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
| ComputeBuffer | srcBuffer | source buffer  | 
| String | name | name  | 
Tensor(Int32, Int32, Int32, Int32, Single[], String)
Create a Tensor of shape [N,H,W,C], an array of data srcData and an optional debug name.
srcData must be of size n*h*w*c.
Declaration
public Tensor(int n, int h, int w, int c, float[] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
| Single[] | srcData | source data  | 
| String | name | name  | 
Tensor(Int32, Int32, Int32, Int32, Single[][], String)
Create a Tensor of shape [1,1,N,1,1,H,W,C], an array of data srcData and an optional debug name.
srcData must be of size n*h*w*c.
Declaration
public Tensor(int n, int h, int w, int c, float[][] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
| Single[][] | srcData | source data  | 
| String | name | name  | 
Tensor(Int32, Int32, Int32, Int32, Single[,,,], String)
Create a Tensor of shape [1,1,N,1,1,H,W,C], an array of data srcData and an optional debug name.
srcData must be of size n*h*w*c.
Declaration
public Tensor(int n, int h, int w, int c, float[,,, ] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
| Single[,,,] | srcData | source data  | 
| String | name | name  | 
Tensor(Int32, Int32, Int32, Int32, String)
Create an uninitialized Tensor of shape [1,1,N,1,1,H,W,C] and an optional debug name.
Declaration
public Tensor(int n, int h, int w, int c, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
| String | name | name  | 
Tensor(Int32, Int32, Int32, Int32, ITensorAllocator)
Create an uninitialized Tensor of shape [1,1,N,1,1,H,W,C] and an ITensorAllocator allocator.
Declaration
public Tensor(int n, int h, int w, int c, ITensorAllocator allocator)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
| ITensorAllocator | allocator | allocator  | 
Tensor(Int32, Int32, Int32, Int32, ITensorData, String)
Create a Tensor of shape [1,1,N,1,1,H,W,C], an ITensorData data and an optional debug name.
srcData must be of size n*h*w*c.
Declaration
public Tensor(int n, int h, int w, int c, ITensorData data, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
| ITensorData | data | data  | 
| String | name | name  | 
Tensor(Int32, Int32, Int32, Int32, ITensorData, ITensorAllocator)
Create a Tensor of shape [1,1,N,1,1,H,W,C], an ITensorData data and an ITensorAllocator allocator.
data must be of size n*h*w*c.
Declaration
public Tensor(int n, int h, int w, int c, ITensorData data, ITensorAllocator allocator)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
| ITensorData | data | data  | 
| ITensorAllocator | allocator | allocator  | 
Tensor(Int32, Int32, Single[], String)
Create a Tensor of shape [N,1,1,C], an array of data srcData and an optional debug name.
srcData must be of size n*c.
Declaration
public Tensor(int n, int c, float[] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | c | channels  | 
| Single[] | srcData | source data  | 
| String | name | name  | 
Tensor(Int32, Int32, Single[][], String)
Create a Tensor of shape [1,1,N,1,1,1,1,C], an array of data srcData and an optional debug name.
srcData must be of size n*c.
Declaration
public Tensor(int n, int c, float[][] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | c | channels  | 
| Single[][] | srcData | source data  | 
| String | name | name  | 
Tensor(Int32, Int32, Single[,], String)
Create a Tensor of shape [1,1,N,1,1,1,1,C], an array of data srcData and an optional debug name.
srcData must be of size n*c.
Declaration
public Tensor(int n, int c, float[, ] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | c | channels  | 
| Single[,] | srcData | source data  | 
| String | name | name  | 
Tensor(Int32, Int32, String)
Create an uninitialized Tensor of shape [1,1,N,1,1,1,1,C] and an optional debug name.
Declaration
public Tensor(int n, int c, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | c | channels  | 
| String | name | name  | 
Tensor(Int32, Int32, ITensorAllocator)
Create an uninitialized Tensor of shape [1,1,N,1,1,1,1,C] and an ITensorAllocator allocator.
Declaration
public Tensor(int n, int c, ITensorAllocator allocator)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | c | channels  | 
| ITensorAllocator | allocator | allocator  | 
Tensor(Int32, Int32, ITensorData, String)
Create a Tensor of shape [1,1,N,1,1,1,1,C], an ITensorData data and an optional debug name.
srcData must be of size n*c.
Declaration
public Tensor(int n, int c, ITensorData data, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | c | channels  | 
| ITensorData | data | data  | 
| String | name | name  | 
Tensor(Int32, Int32, ITensorData, ITensorAllocator)
Create a Tensor of shape [1,1,N,1,1,1,1,C], an ITensorData data and an ITensorAllocator allocator.
srcData must be of size n*c.
Declaration
public Tensor(int n, int c, ITensorData data, ITensorAllocator allocator)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | c | channels  | 
| ITensorData | data | data  | 
| ITensorAllocator | allocator | allocator  | 
Tensor(Int32[], ComputeBuffer, String, Boolean)
Create a Tensor from a shape, associated ComputeBuffer srcBuffer filled with tensor values, and an optional debug name.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C].
S and R must be 1.
srcBuffer must be larger than s[0]*s[1]*s[2]*s[3]*s[4]*s[5]*s[6]*s[7].
Declaration
public Tensor(int[] shape, ComputeBuffer srcBuffer, string name = "", bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| ComputeBuffer | srcBuffer | source buffer  | 
| String | name | name  | 
| Boolean | unnamedDimensions | 
Tensor(Int32[], Single[], String, Boolean)
Create a Tensor from a shape, an array of data srcData and an optional debug name.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C].
S and R must be 1.
srcData must be of size s[0]*s[1]*s[2]*s[3]*s[4]*s[5]*s[6]*s[7].
Declaration
public Tensor(int[] shape, float[] srcData, string name = "", bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| Single[] | srcData | source data  | 
| String | name | name  | 
| Boolean | unnamedDimensions | 
Tensor(Int32[], Single[][], String, Boolean)
Create a Tensor from a shape, an array of data srcData and an optional name debug name.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C].
S and R must be 1.
srcData must be of size s[0]*s[1]*s[2]*s[3]*s[4]*s[5]*s[6]*s[7].
Declaration
public Tensor(int[] shape, float[][] srcData, string name = "", bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| Single[][] | srcData | source data  | 
| String | name | name  | 
| Boolean | unnamedDimensions | 
Tensor(Int32[], Single[,,,], String, Boolean)
Create a Tensor from a shape, an array of data srcData and an optional name debug name.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C].
S and R must be 1.
srcData must be of size s[0]*s[1]*s[2]*s[3]*s[4]*s[5]*s[6]*s[7].
Declaration
public Tensor(int[] shape, float[,,, ] srcData, string name = "", bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| Single[,,,] | srcData | source data  | 
| String | name | name  | 
| Boolean | unnamedDimensions | 
Tensor(Int32[], Single[,], String, Boolean)
Create a Tensor from a shape, an array of data srcData and an optional name debug name.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C].
S and R must be 1.
srcData must be of size s[0]*s[1]*s[2]*s[3]*s[4]*s[5]*s[6]*s[7].
Declaration
public Tensor(int[] shape, float[, ] srcData, string name = "", bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| Single[,] | srcData | source data  | 
| String | name | name  | 
| Boolean | unnamedDimensions | 
Tensor(Int32[], String, Boolean)
Create an uninitialized Tensor from a shape and an optional debug name.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C]
S and R must be 1.
Declaration
public Tensor(int[] shape, string name = "", bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| String | name | name  | 
| Boolean | unnamedDimensions | 
Tensor(Int32[], ITensorAllocator, Boolean)
Create an uninitialized Tensor from a shape and an ITensorAllocator allocator.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C].
S and R must be 1.
Declaration
public Tensor(int[] shape, ITensorAllocator allocator, bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| ITensorAllocator | allocator | allocator  | 
| Boolean | unnamedDimensions | 
Tensor(Int32[], ITensorData, String, Boolean)
Create a Tensor from a shape, an ITensorData data and an optional debug name.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C].
S and R must be 1.
Declaration
public Tensor(int[] shape, ITensorData data, string name = "", bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| ITensorData | data | data  | 
| String | name | name  | 
| Boolean | unnamedDimensions | 
Tensor(Int32[], ITensorData, ITensorAllocator, Boolean)
Create a Tensor from a shape, an ITensorData data and an ITensorAllocator allocator.
shape must be of size 8, the order is [S,R,N,T,D,H,W,C].
S and R must be 1.
Declaration
public Tensor(int[] shape, ITensorData data, ITensorAllocator allocator, bool unnamedDimensions = false)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32[] | shape | shape  | 
| ITensorData | data | data  | 
| ITensorAllocator | allocator | allocator  | 
| Boolean | unnamedDimensions | 
Tensor(String)
Create an uninitialized Tensor with a shape of [1,1,1,1,1,1,1,1] and an optional debug name.
Declaration
public Tensor(string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| String | name | name  | 
Tensor(Texture, Boolean, Vector4, Vector4, Int32, String)
Create a Tensor from multiple texture, shape is [1,1, srcTextures.length,1,1, texture.height, texture.width, channels].
If channels is set to -1 (default value), then number of channels in the new Tensor will match the number of channels in the texture.
Just like Texture2D.GetPixels when reading from LDR texture (RGBA32, ARGB32, RGB24, Alpha8, RG16, R8, etc) this function will remap pixel values from byte values to the range of [0.0 .. 1.0]. Pixel values from HDR textures (such as ARGBFloat or ARGBHalf) will be left unchanged.
flipY flips the texture along the Y direction
scale and bias respectively scale and bias the input texture as so: scale*v+bias
Declaration
public Tensor(Texture srcTexture, bool flipY, Vector4 scale, Vector4 bias, int channels = null, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Texture | srcTexture | |
| Boolean | flipY | flipY  | 
| Vector4 | scale | scale  | 
| Vector4 | bias | bias  | 
| Int32 | channels | channels  | 
| String | name | name  | 
Tensor(Texture, Int32, String)
Create a Tensor from a texture, shape is [1,1,1,1,1, texture.height, texture.width, channels].
If channels is set to -1 (default value), then number of channels in the new Tensor will match the number of channels in the texture.
Just like Texture2D.GetPixels when reading from LDR texture (RGBA32, ARGB32, RGB24, Alpha8, RG16, R8, etc) this function will remap pixel values from byte values to the range of [0.0 .. 1.0]. Pixel values from HDR textures (such as ARGBFloat or ARGBHalf) will be left unchanged.
Declaration
public Tensor(Texture srcTexture, int channels = null, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Texture | srcTexture | source texture  | 
| Int32 | channels | channels  | 
| String | name | name  | 
Tensor(Texture[], Boolean, Boolean, Vector4, Vector4, Int32, String)
Create a Tensor from multiple texture, shape is [1,1, srcTextures.length,1,1, texture.height, texture.width, channels].
If channels is set to -1 (default value), then number of channels in the new Tensor will match the number of channels in the texture.
All textures must be of the same size and dimension.
Just like Texture2D.GetPixels when reading from LDR texture (RGBA32, ARGB32, RGB24, Alpha8, RG16, R8, etc) this function will remap pixel values from byte values to the range of [0.0 .. 1.0]. Pixel values from HDR textures (such as ARGBFloat or ARGBHalf) will be left unchanged.
flipY flips the texture along the Y direction
If concatOnBatch is True then the textures are concatenated on the batch dimension : resulting srcTextures.length, texture.height, texture.width, texture.channels
scale and bias respectively scale and bias the input texture as so: scale*v+bias
Declaration
public Tensor(Texture[] srcTextures, bool flipY, bool concatOnBatch, Vector4 scale, Vector4 bias, int channels = null, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Texture[] | srcTextures | source textures  | 
| Boolean | flipY | flipY  | 
| Boolean | concatOnBatch | concatOnBatch  | 
| Vector4 | scale | scale  | 
| Vector4 | bias | bias  | 
| Int32 | channels | channels  | 
| String | name | name  | 
Tensor(Texture[], Int32, String)
Create a Tensor from multiple texture, shape is [1,1, srcTextures.length,1,1, texture.height, texture.width, channels].
If channels is set to -1 (default value), then number of channels in the new Tensor will match the number of channels in the texture.
All textures must be of the same size and dimension.
Just like Texture2D.GetPixels when reading from LDR texture (RGBA32, ARGB32, RGB24, Alpha8, RG16, R8, etc) this function will remap pixel values from byte values to the range of [0.0 .. 1.0]. Pixel values from HDR textures (such as ARGBFloat or ARGBHalf) will be left unchanged.
Declaration
public Tensor(Texture[] srcTextures, int channels = null, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| Texture[] | srcTextures | source textures  | 
| Int32 | channels | channels  | 
| String | name | name  | 
Tensor(ITensorAllocator)
Create an uninitialized Tensor with a shape of [1,1,1,1,1,1,1,1] and an ITensorAllocator allocator.
Declaration
public Tensor(ITensorAllocator allocator)
Parameters
| Type | Name | Description | 
|---|---|---|
| ITensorAllocator | allocator | allocator  | 
Tensor(TensorShape, ComputeBuffer, String)
Create a Tensor with specified shape, associated ComputeBuffer srcBuffer filled with tensor values, and an optional debug name.
srcBuffer must be larger than shape.length.
Declaration
public Tensor(TensorShape shape, ComputeBuffer srcBuffer, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| ComputeBuffer | srcBuffer | source buffer  | 
| String | name | name  | 
Tensor(TensorShape, Single[], String)
Create a Tensor with specified shape, an array of data srcData and an optional debug name.
srcData must be of size shape.length.
Declaration
public Tensor(TensorShape shape, float[] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| Single[] | srcData | source data  | 
| String | name | name  | 
Tensor(TensorShape, Single[][], String)
Create a Tensor with specified shape, an array of data srcData and an optional debug name.
srcData must be of size shape.length.
Declaration
public Tensor(TensorShape shape, float[][] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| Single[][] | srcData | source data  | 
| String | name | name  | 
Tensor(TensorShape, Single[,,,], String)
Create a Tensor with specified shape, an array of data srcData and an optional debug name.
srcData must be of size shape.length.
Declaration
public Tensor(TensorShape shape, float[,,, ] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| Single[,,,] | srcData | source data  | 
| String | name | name  | 
Tensor(TensorShape, Single[,], String)
Create a Tensor with specified shape, an array of data srcData and an optional debug name.
srcData must be of size shape.length.
Declaration
public Tensor(TensorShape shape, float[, ] srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| Single[,] | srcData | source data  | 
| String | name | name  | 
Tensor(TensorShape, String, DataType)
Create an uninitialized Tensor with specified shape and an optional debug name.
Declaration
public Tensor(TensorShape shape, string name = "", DataType dataType = DataType.Float)
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| String | name | name  | 
| DataType | dataType | 
Tensor(TensorShape, BarracudaArray, String)
Create a Tensor with specified shape, a BarracudaArray of data srcData and an optional debug name.
srcData must be of size shape.length.
Declaration
public Tensor(TensorShape shape, BarracudaArray srcData, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| BarracudaArray | srcData | source data  | 
| String | name | name  | 
Tensor(TensorShape, ITensorAllocator)
Create an uninitialized Tensor with specified shape and ITensorAllocator allocator.
Declaration
public Tensor(TensorShape shape, ITensorAllocator allocator)
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| ITensorAllocator | allocator | allocator  | 
Tensor(TensorShape, ITensorData, String)
Create a Tensor with specified shape, an ITensorData data and an optional debug name.
Declaration
public Tensor(TensorShape shape, ITensorData data, string name = "")
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| ITensorData | data | data  | 
| String | name | name  | 
Tensor(TensorShape, ITensorData, ITensorAllocator, DataType)
Create a Tensor with specified shape, an ITensorData data and an ITensorAllocator allocator
Declaration
public Tensor(TensorShape shape, ITensorData data, ITensorAllocator allocator, DataType dataType = DataType.Float)
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | shape | shape  | 
| ITensorData | data | data  | 
| ITensorAllocator | allocator | allocator  | 
| DataType | dataType | 
Properties
allocator
Return this tensor allocator, see interface ITensorAllocator.
Declaration
public ITensorAllocator allocator { get; }
Property Value
| Type | Description | 
|---|---|
| ITensorAllocator | 
batch
Return the number of batches.
Declaration
public int batch { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
cacheBytes
Return amount of internal tensor cache in bytes.
Declaration
public int cacheBytes { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
Implements
channels
Return the number of channels.
Declaration
public int channels { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
data
Upload data to device and return its instance
Declaration
public ITensorData data { get; }
Property Value
| Type | Description | 
|---|---|
| ITensorData | 
dataType
Return the data type of this tensor.
Declaration
public DataType dataType { get; }
Property Value
| Type | Description | 
|---|---|
| DataType | 
Implements
depth
Return the spatial depth.
Declaration
public int depth { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
dimensions
Return the count of non-unit dimension of this tensor shape. For example [1,1,N,1,1,1,1,C] dimensions is 2.
Declaration
public int dimensions { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
flatHeight
Return the number of batch.
Declaration
public int flatHeight { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
flatWidth
Return TDHWC.
Declaration
public int flatWidth { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
height
Return the spatial height.
Declaration
public int height { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
Item[Int32]
Access element at offset index in this Tensor.
This will create a blocking read, if this Tensor is a result of a computation on a different device (GPU).
Declaration
public float this[int index] { get; set; }
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | index | flat index  | 
Property Value
| Type | Description | 
|---|---|
| Single | 
Item[Int32, Int32]
Access element at index [0,0,N,0,0,0,0,C] in this Tensor. This will create a blocking read, if this Tensor is a result of a computation on a different device (GPU).
Declaration
public float this[int b, int ch] { get; set; }
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | b | batch  | 
| Int32 | ch | channels  | 
Property Value
| Type | Description | 
|---|---|
| Single | 
Item[Int32, Int32, Int32, Int32]
Access element at index [0,0,N,0,0,H,W,C] in this Tensor. This will create a blocking read, if this Tensor is a result of a computation on a different device (GPU).
Declaration
public float this[int b, int h, int w, int ch] { get; set; }
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | b | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | ch | channels  | 
Property Value
| Type | Description | 
|---|---|
| Single | 
Item[Int32, Int32, Int32, Int32, Int32]
Access element at index [0,0,N,0,D,H,W,C] in this Tensor. This will create a blocking read, if this Tensor is a result of a computation on a different device (GPU).
Declaration
public float this[int b, int d, int h, int w, int ch] { get; set; }
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | b | |
| Int32 | d | |
| Int32 | h | |
| Int32 | w | |
| Int32 | ch | 
Property Value
| Type | Description | 
|---|---|
| Single | 
Item[Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32]
Access element at index [S,R,N,T,D,H,W,C] in this Tensor. This will create a blocking read, if this Tensor is a result of a computation on a different device (GPU).
Declaration
public float this[int s, int r, int n, int t, int d, int h, int w, int c] { get; set; }
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | s | sequence  | 
| Int32 | r | direction  | 
| Int32 | n | batch  | 
| Int32 | t | time  | 
| Int32 | d | depth  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
Property Value
| Type | Description | 
|---|---|
| Single | 
kernelCount
Kernel dimension ordering is [D,H,W,C,K] for efficiency purpose. Return kernel count (aka the number of output channels of the associated operator).
Declaration
public int kernelCount { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
kernelDepth
Kernel dimension ordering is [D,H,W,C,K] for efficiency purpose. Return kernel depth (aka the number of input channels of the associated operator).
Declaration
public int kernelDepth { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
kernelHeight
Kernel dimension ordering is [D,H,W,C,K] for efficiency purpose. Return kernel spatial height.
Declaration
public int kernelHeight { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
kernelSpatialDepth
Kernel dimension ordering is [D,H,W,C,K] for efficiency purpose. Return kernel spatial depth.
Declaration
public int kernelSpatialDepth { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
kernelWidth
Kernel dimension ordering is [D,H,W,C,K] for efficiency purpose. Return kernel spatial width.
Declaration
public int kernelWidth { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
length
Return the total number of elements in this tensor.
Declaration
public int length { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
name
Return this tensor name.
Declaration
public string name { get; set; }
Property Value
| Type | Description | 
|---|---|
| String | 
Implements
numberOfDirections
Return the number of directions.
Declaration
public int numberOfDirections { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
readonlyArray
Read-only array of Tensor data
Declaration
public float[] readonlyArray { get; }
Property Value
| Type | Description | 
|---|---|
| Single[] | 
readonlyArrayOffset
Offset into read-only array of Tensor data
Declaration
public int readonlyArrayOffset { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
sequenceLength
Return the number of sequences.
Declaration
public int sequenceLength { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
shape
Return the shape of this tensor.
Declaration
public TensorShape shape { get; }
Property Value
| Type | Description | 
|---|---|
| TensorShape | 
Implements
tensorOnDevice
Device specific internal representation of Tensor data
Declaration
public ITensorData tensorOnDevice { get; }
Property Value
| Type | Description | 
|---|---|
| ITensorData | 
width
Return the spatial width.
Declaration
public int width { get; }
Property Value
| Type | Description | 
|---|---|
| Int32 | 
Methods
AllocateOnDevice(ITensorData)
Upload tensor values to the device.
This call allocates destination tensor on a target device. Previous contents of destination will be overwritten after this call.
No content will be copied/initialized from the tensor regardless of the current cache/data on device
Declaration
public void AllocateOnDevice(ITensorData destination)
Parameters
| Type | Name | Description | 
|---|---|---|
| ITensorData | destination | destination  | 
AttachToDevice(ITensorData)
Associates tensor with the block of data residing on a device.
Tensor values will be downloaded from the source upon the first access.
source should contain initialized and valid data representing tensor values.
See also PrepareCacheForAccess() to schedule download as soon as possible.
Declaration
public void AttachToDevice(ITensorData source)
Parameters
| Type | Name | Description | 
|---|---|---|
| ITensorData | source | source  | 
Axis(Int32)
Allow to use negative axis to access tensorShape backward.
axis should be from -rank to rank (exclusive).
Declaration
public int Axis(int axis)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | axis | axis  | 
Returns
| Type | Description | 
|---|---|
| Int32 | remapped axis  | 
DeepCopy()
Create a copy of the current Tensor.
Declaration
public Tensor DeepCopy()
Returns
| Type | Description | 
|---|---|
| Tensor | new copy of the Tensor  | 
DetachFromDevice(Boolean)
Remove tensor from device, will first sync the cache with device data.
Declaration
public ITensorData DetachFromDevice(bool disposeDeviceData = true)
Parameters
| Type | Name | Description | 
|---|---|---|
| Boolean | disposeDeviceData | dispose device data  | 
Returns
| Type | Description | 
|---|---|
| ITensorData | Tensor data  | 
Dispose()
Dispose Tensor and associated memories.
Declaration
public virtual void Dispose()
Finalize()
Destructor will also dispose associated memories.
Declaration
protected void Finalize()
Flatten(String)
Create a flattened copy of the current Tensor ie of shape [1,1,N,1,1,1,1,TDHWC]
Declaration
public Tensor Flatten(string newName = null)
Parameters
| Type | Name | Description | 
|---|---|---|
| String | newName | new name  | 
Returns
| Type | Description | 
|---|---|
| Tensor | shallow copy of the Tensor with new shape  | 
FlushCache(Boolean)
Upload cache to device memory and delete it.
Declaration
public void FlushCache(bool uploadCache)
Parameters
| Type | Name | Description | 
|---|---|---|
| Boolean | uploadCache | 
GetTensorDataStatistics()
Return this tensor tensor data statistics if any or null.
Declaration
public ITensorDataStatistics GetTensorDataStatistics()
Returns
| Type | Description | 
|---|---|
| ITensorDataStatistics | 
Implements
Index(Int32, Int32)
Given an element dimensions indices [0,0,N,0,0,0,0,C] return this element offset in memory.
Declaration
public int Index(int y, int x)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | y | y  | 
| Int32 | x | x  | 
Returns
| Type | Description | 
|---|---|
| Int32 | flat index (offset in memory)  | 
Index(Int32, Int32, Int32, Int32)
Given an element dimensions indices [0,0,N,0,0,H,W,C] return this element offset in memory.
Declaration
public int Index(int b, int h, int w, int ch)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | b | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | ch | channels  | 
Returns
| Type | Description | 
|---|---|
| Int32 | flat index (offset in memory)  | 
Index(Int32, Int32, Int32, Int32, Int32)
Given an element dimensions indices [0,0,N,0,D,H,W,C] return this element offset in memory.
Declaration
public int Index(int b, int d, int h, int w, int ch)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | b | batch  | 
| Int32 | d | depth  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | ch | channels  | 
Returns
| Type | Description | 
|---|---|
| Int32 | 
Index(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)
Given an element dimensions indices [S,R,N,T,D,H,W,C] return this element offset in memory.
Declaration
public int Index(int s, int r, int n, int t, int d, int h, int w, int c)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | s | sequence  | 
| Int32 | r | direction  | 
| Int32 | n | batch  | 
| Int32 | t | time  | 
| Int32 | d | depth  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
Returns
| Type | Description | 
|---|---|
| Int32 | flat index (offset in memory)  | 
IndexWithBroadcast(Int32, Int32, Int32, Int32)
Given an element dimensions indices[0,0,N,0,0,H,W,C] with broadcast support, return this element offset in memory.
Declaration
public int IndexWithBroadcast(int n, int h, int w, int c)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
Returns
| Type | Description | 
|---|---|
| Int32 | flat index (offset in memory)  | 
IndexWithBroadcast(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)
Given an element dimensions indices [S,R,N,T,D,H,W,C] with broadcast support, return this element offset in memory.
Declaration
public int IndexWithBroadcast(int s, int r, int n, int t, int d, int h, int w, int c)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | s | sequence  | 
| Int32 | r | direction  | 
| Int32 | n | batch  | 
| Int32 | t | time  | 
| Int32 | d | depth  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
Returns
| Type | Description | 
|---|---|
| Int32 | flat index (offset in memory)  | 
IndexWithClamp(Int32, Int32, Int32, Int32)
Given an element dimensions indices [0,0,N,0,0,H,W,C] return this element offset in memory, clamping indices to tensor dimensions.
Declaration
public int IndexWithClamp(int n, int h, int w, int c)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
Returns
| Type | Description | 
|---|---|
| Int32 | flat index (offset in memory)  | 
IndexWithClamp(Int32, Int32, Int32, Int32, Int32)
Given an element dimensions indices [0,0,N,0,D,H,W,C] return this element offset in memory, clamping indices to tensor dimensions.
Declaration
public int IndexWithClamp(int n, int d, int h, int w, int c)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | n | batch  | 
| Int32 | d | depth  | 
| Int32 | h | height  | 
| Int32 | w | width  | 
| Int32 | c | channels  | 
Returns
| Type | Description | 
|---|---|
| Int32 | flat index (offset in memory)  | 
InvalidateCache()
Declaration
public void InvalidateCache()
PrepareCacheForAccess(Boolean)
Populate the cache with on device data.
Blocking read if blocking is true (default)
Declaration
public bool PrepareCacheForAccess(bool blocking = true)
Parameters
| Type | Name | Description | 
|---|---|---|
| Boolean | blocking | blocking read if   | 
Returns
| Type | Description | 
|---|---|
| Boolean | 
  | 
Reshape(TensorShape, String)
Create a reshaped copy of the current Tensor.
newShape.length must be equal to this.shape.length.
Declaration
public Tensor Reshape(TensorShape newShape, string newName = null)
Parameters
| Type | Name | Description | 
|---|---|---|
| TensorShape | newShape | new shape  | 
| String | newName | new name  | 
Returns
| Type | Description | 
|---|---|
| Tensor | shallow copy of the Tensor with new shape and name  | 
ShallowCopy(String)
Create a copy of the current Tensor, sharing data storage with original tensor.
Declaration
public Tensor ShallowCopy(string newName = null)
Parameters
| Type | Name | Description | 
|---|---|---|
| String | newName | new name  | 
Returns
| Type | Description | 
|---|---|
| Tensor | shallow copy of the Tensor  | 
TakeOwnership()
Remove system reference to this tensor, caller assume ownership.
Declaration
public void TakeOwnership()
ToReadOnlyArray()
Return the cached linear memory representation of this tensor data. This will create a blocking read, if this Tensor is a result of a computation on a different device (GPU). IMPORTANT: Modifying contents of the returned array will have undefined behavior.
Declaration
public float[] ToReadOnlyArray()
Returns
| Type | Description | 
|---|---|
| Single[] | cached linear memory representation of this tensor data  | 
ToRenderTexture(RenderTexture, Int32, Int32, Single, Single, Texture3D)
Fill a target RenderTexture with a portion of the tensor applying scale and bias. Portion of the target is specified by batch and fromChannel.
batch specifies the tensor batch to read values from.
fromChannel specifies the first tensor channel to start reading values from.
Number of channels in the target texture specifies how many channels to read from the tensor, starting from index fromChannel.
Resolution of the target must match the spatial dimensions of the tensor.
scale multiplier and bias addition is applied to the values read from the tensor and, if target is LDR texture (RGBA32, ARGB32, RGB24, Alpha8, RG16, R8, etc), clamped to the range from 0.0 to 1.0.
Declaration
public void ToRenderTexture(RenderTexture target, int batch = 0, int fromChannel = 0, float scale = 1F, float bias = 0F, Texture3D lut = null)
Parameters
| Type | Name | Description | 
|---|---|---|
| RenderTexture | target | target RenderTexture  | 
| Int32 | batch | batch  | 
| Int32 | fromChannel | from channel  | 
| Single | scale | scale  | 
| Single | bias | bias  | 
| Texture3D | lut | lut table  | 
ToRenderTexture(RenderTexture, Int32, Int32, Vector4, Vector4, Texture3D)
Fill a target RenderTexture with a portion of the tensor applying scale and bias. Portion of the target is specified by batch and fromChannel.
batch specifies the tensor batch to read values from.
fromChannel specifies the first tensor channel to start reading values from.
Number of channels in the target texture specifies how many channels to read from the tensor, starting from index fromChannel.
Resolution of the target must match the spatial dimensions of the tensor.
scale multiplier and bias addition is applied to the values read from the tensor and, if target is LDR texture (RGBA32, ARGB32, RGB24, Alpha8, RG16, R8, etc), clamped to the range from 0.0 to 1.0.
Declaration
public void ToRenderTexture(RenderTexture target, int batch, int fromChannel, Vector4 scale, Vector4 bias, Texture3D lut = null)
Parameters
| Type | Name | Description | 
|---|---|---|
| RenderTexture | target | target RenderTexture  | 
| Int32 | batch | batch  | 
| Int32 | fromChannel | from channel  | 
| Vector4 | scale | scale  | 
| Vector4 | bias | bias  | 
| Texture3D | lut | lut table  | 
ToRenderTexture(RenderTextureFormat, Int32, Int32, Single, Single, Texture3D)
Create new RenderTexture and fill it with a portion of the tensor applying scale and bias. Portion of the target is specified by batch and fromChannel.
format specifies the type of the new RenderTexture.
batch specifies the tensor batch to read values from.
fromChannel specifies the first tensor channel to start reading values from.
Number of channels in the target texture specifies how many channels to read from the tensor, starting from index fromChannel.
scale multiplier and bias addition is applied to the values read from the tensor and, if format is LDR (RGBA32, ARGB32, RGB24, Alpha8, RG16, R8, etc), clamped to the range from 0.0 to 1.0.
Declaration
public RenderTexture ToRenderTexture(RenderTextureFormat format, int batch = 0, int fromChannel = 0, float scale = 1F, float bias = 0F, Texture3D lut = null)
Parameters
| Type | Name | Description | 
|---|---|---|
| RenderTextureFormat | format | RenderTexture format  | 
| Int32 | batch | batch  | 
| Int32 | fromChannel | from channel  | 
| Single | scale | scale  | 
| Single | bias | bias  | 
| Texture3D | lut | lut table  | 
Returns
| Type | Description | 
|---|---|
| RenderTexture | created RenderTexture  | 
ToRenderTexture(Int32, Int32, Single, Single, Texture3D)
Create new RenderTexture and fill it with a portion of the tensor applying scale and bias. Portion of the target is specified by batch and fromChannel.
batch specifies the tensor batch to read values from.
fromChannel specifies the first tensor channel to start reading values from.
Number of channels in the target texture specifies how many channels to read from the tensor, starting from index fromChannel.
Resolution of the target must match the spatial dimensions of the tensor.
scale multiplier and bias addition is applied to the values read from the tensor and clamped to the range from 0.0 to 1.0.
Declaration
public RenderTexture ToRenderTexture(int batch = 0, int fromChannel = 0, float scale = 1F, float bias = 0F, Texture3D lut = null)
Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | batch | batch  | 
| Int32 | fromChannel | from channel  | 
| Single | scale | scale  | 
| Single | bias | bias  | 
| Texture3D | lut | lut table  | 
Returns
| Type | Description | 
|---|---|
| RenderTexture | 
ToString()
Tensor metadata summary
Declaration
public override string ToString()
Returns
| Type | Description | 
|---|---|
| String | Tensor metadata summary  | 
UnpinAndDisposeTensor()
Unload tensor data from device and dispose this Tensor
Declaration
public ITensorData UnpinAndDisposeTensor()
Returns
| Type | Description | 
|---|---|
| ITensorData | device specific Tensor data  | 
UploadToDevice(ITensorData, Boolean)
Upload tensor values to the device.
This call associates tensor with the uninitialized block of data residing on a device.
destination should be allocated on a target device. Previous contents of destination will be overwritten after this call.
By default local cache will be discarded after this call, set invalidateCacheAfterUpload to false to keep the cache.
Declaration
public void UploadToDevice(ITensorData destination, bool invalidateCacheAfterUpload = true)
Parameters
| Type | Name | Description | 
|---|---|---|
| ITensorData | destination | destination  | 
| Boolean | invalidateCacheAfterUpload | invalidate cache after upload  | 
Events
tensorDisposed
Declaration
public static event Action<Tensor> tensorDisposed
Event Type
| Type | Description | 
|---|---|
| Action<Tensor> |