docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Tensor

    Multidimensional array-like data storage

    Inheritance
    object
    Tensor
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Barracuda
    Assembly: Unity.Barracuda.dll
    Syntax
    public class Tensor : IDisposable

    Constructors

    Tensor(int, int, int, int, float[,,,], 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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    float[,,,] srcData

    source data

    string name

    name

    Tensor(int, int, int, int, float[], 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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    float[] srcData

    source data

    string name

    name

    Tensor(int, int, int, int, float[][], 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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    float[][] srcData

    source data

    string name

    name

    Tensor(int, int, int, int, 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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    string name

    name

    Tensor(int, int, int, int, 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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    ITensorAllocator allocator

    allocator

    Tensor(int, int, int, int, 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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    ITensorData data

    data

    string name

    name

    Tensor(int, int, int, int, 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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    ITensorData data

    data

    ITensorAllocator allocator

    allocator

    Tensor(int, int, int, int, 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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    ComputeBuffer srcBuffer

    source buffer

    string name

    name

    Tensor(int, int, float[,], 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
    int n

    batch

    int c

    channels

    float[,] srcData

    source data

    string name

    name

    Tensor(int, int, float[], 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
    int n

    batch

    int c

    channels

    float[] srcData

    source data

    string name

    name

    Tensor(int, int, float[][], 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
    int n

    batch

    int c

    channels

    float[][] srcData

    source data

    string name

    name

    Tensor(int, int, 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
    int n

    batch

    int c

    channels

    string name

    name

    Tensor(int, int, 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
    int n

    batch

    int c

    channels

    ITensorAllocator allocator

    allocator

    Tensor(int, int, 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
    int n

    batch

    int c

    channels

    ITensorData data

    data

    string name

    name

    Tensor(int, int, 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
    int n

    batch

    int c

    channels

    ITensorData data

    data

    ITensorAllocator allocator

    allocator

    Tensor(int, int, 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
    int n

    batch

    int c

    channels

    ComputeBuffer srcBuffer

    source buffer

    string name

    name

    Tensor(int[], float[,,,], string)

    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 = "")
    Parameters
    Type Name Description
    int[] shape

    shape

    float[,,,] srcData

    source data

    string name

    name

    Tensor(int[], float[,], string)

    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 = "")
    Parameters
    Type Name Description
    int[] shape

    shape

    float[,] srcData

    source data

    string name

    name

    Tensor(int[], float[], string)

    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 = "")
    Parameters
    Type Name Description
    int[] shape

    shape

    float[] srcData

    source data

    string name

    name

    Tensor(int[], float[][], string)

    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 = "")
    Parameters
    Type Name Description
    int[] shape

    shape

    float[][] srcData

    source data

    string name

    name

    Tensor(int[], string)

    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 = "")
    Parameters
    Type Name Description
    int[] shape

    shape

    string name

    name

    Tensor(int[], ITensorAllocator)

    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)
    Parameters
    Type Name Description
    int[] shape

    shape

    ITensorAllocator allocator

    allocator

    Tensor(int[], ITensorData, string)

    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 = "")
    Parameters
    Type Name Description
    int[] shape

    shape

    ITensorData data

    data

    string name

    name

    Tensor(int[], ITensorData, ITensorAllocator)

    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)
    Parameters
    Type Name Description
    int[] shape

    shape

    ITensorData data

    data

    ITensorAllocator allocator

    allocator

    Tensor(int[], ComputeBuffer, string)

    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 = "")
    Parameters
    Type Name Description
    int[] shape

    shape

    ComputeBuffer srcBuffer

    source buffer

    string name

    name

    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(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, float[,,,], 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

    float[,,,] srcData

    source data

    string name

    name

    Tensor(TensorShape, float[,], 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

    float[,] srcData

    source data

    string name

    name

    Tensor(TensorShape, float[], 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

    float[] srcData

    source data

    string name

    name

    Tensor(TensorShape, float[][], 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

    float[][] srcData

    source data

    string name

    name

    Tensor(TensorShape, string)

    Create an uninitialized Tensor with specified shape and an optional debug name.

    Declaration
    public Tensor(TensorShape shape, string name = "")
    Parameters
    Type Name Description
    TensorShape shape

    shape

    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)

    Create a Tensor with specified shape, an ITensorData data and an ITensorAllocator allocator

    Declaration
    public Tensor(TensorShape shape, ITensorData data, ITensorAllocator allocator)
    Parameters
    Type Name Description
    TensorShape shape

    shape

    ITensorData data

    data

    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

    Exceptions
    Type Condition
    ArgumentException

    thrown if specified buffer is too small or stride is mismatched

    Tensor(Texture, int, 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 = -1, string name = "")
    Parameters
    Type Name Description
    Texture srcTexture

    source texture

    int channels

    channels

    string name

    name

    Tensor(Texture[], int, string)

    Create a Tensor from multiple texture, shape is [1,1,1,1, srcTextures.length, 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 = -1, string name = "")
    Parameters
    Type Name Description
    Texture[] srcTextures

    source textures

    int channels

    channels

    string name

    name

    Fields

    name

    Return this tensor name.

    Declaration
    public string name
    Field Value
    Type Description
    string

    shape

    Return this tensor shape as [S,R,N,T,D,H,W,C].

    Declaration
    public readonly TensorShape shape
    Field Value
    Type Description
    TensorShape

    Properties

    this[int]

    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
    int index

    flat index

    Property Value
    Type Description
    float

    this[int, int]

    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
    int b

    batch

    int ch

    channels

    Property Value
    Type Description
    float

    this[int, int, int, int]

    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
    int b

    batch

    int h

    height

    int w

    width

    int ch

    channels

    Property Value
    Type Description
    float

    this[int, int, int, int, int]

    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
    int b
    int d
    int h
    int w
    int ch
    Property Value
    Type Description
    float

    this[int, int, int, int, int, int, int, int]

    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
    int s

    sequence

    int r

    direction

    int n

    batch

    int t

    time

    int d

    depth

    int h

    height

    int w

    width

    int c

    channels

    Property Value
    Type Description
    float

    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
    int

    channels

    Return the number of channels.

    Declaration
    public int channels { get; }
    Property Value
    Type Description
    int

    data

    Upload data to device and return its instance

    Declaration
    public ITensorData data { get; }
    Property Value
    Type Description
    ITensorData

    depth

    Return the spatial depth.

    Declaration
    public int depth { get; }
    Property Value
    Type Description
    int

    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
    int

    flatHeight

    Return the number of batch.

    Declaration
    public int flatHeight { get; }
    Property Value
    Type Description
    int

    flatWidth

    Return TDHWC.

    Declaration
    public int flatWidth { get; }
    Property Value
    Type Description
    int

    height

    Return the spatial height.

    Declaration
    public int height { get; }
    Property Value
    Type Description
    int

    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
    int

    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
    int

    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
    int

    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
    int

    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
    int

    length

    Return the total number of elements in this tensor.

    Declaration
    public int length { get; }
    Property Value
    Type Description
    int

    numberOfDirections

    Return the number of directions.

    Declaration
    public int numberOfDirections { get; }
    Property Value
    Type Description
    int

    readonlyArray

    Read-only array of Tensor data

    Declaration
    [Obsolete("Use ToReadOnlyArray instead.", false)]
    public float[] readonlyArray { get; }
    Property Value
    Type Description
    float[]

    readonlyArrayOffset

    Offset into read-only array of Tensor data

    Declaration
    [Obsolete("Use ToReadOnlyArray instead.", false)]
    public int readonlyArrayOffset { get; }
    Property Value
    Type Description
    int

    sequenceLength

    Return the number of sequences.

    Declaration
    public int sequenceLength { get; }
    Property Value
    Type Description
    int

    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
    int

    Methods

    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(int)

    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
    int axis

    axis

    Returns
    Type Description
    int

    remapped axis

    DeepCopy()

    Create a copy of the current Tensor.

    Declaration
    public Tensor DeepCopy()
    Returns
    Type Description
    Tensor

    new copy of the Tensor

    DetachFromDevice(bool)

    Remove tensor from device, will first sync the cache with device data.

    Declaration
    public ITensorData DetachFromDevice(bool disposeDeviceData = true)
    Parameters
    Type Name Description
    bool disposeDeviceData

    dispose device data

    Returns
    Type Description
    ITensorData

    Tensor data

    Dispose()

    Dispose Tensor and associated memories.

    Declaration
    public virtual void Dispose()

    ~Tensor()

    Destructor will also dispose associated memories.

    Declaration
    protected ~Tensor()

    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()

    Upload cache to device memory and delete it.

    Declaration
    public void FlushCache()

    Index(int, int)

    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
    int y

    y

    int x

    x

    Returns
    Type Description
    int

    flat index (offset in memory)

    Index(int, int, int, int)

    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
    int b

    batch

    int h

    height

    int w

    width

    int ch

    channels

    Returns
    Type Description
    int

    flat index (offset in memory)

    Index(int, int, int, int, int)

    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
    int b

    batch

    int d

    depth

    int h

    height

    int w

    width

    int ch

    channels

    Returns
    Type Description
    int

    Index(int, int, int, int, int, int, int, int)

    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
    int s

    sequence

    int r

    direction

    int n

    batch

    int t

    time

    int d

    depth

    int h

    height

    int w

    width

    int c

    channels

    Returns
    Type Description
    int

    flat index (offset in memory)

    IndexWithBroadcast(int, int, int, int)

    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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    Returns
    Type Description
    int

    flat index (offset in memory)

    IndexWithBroadcast(int, int, int, int, int, int, int, int)

    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
    int s

    sequence

    int r

    direction

    int n

    batch

    int t

    time

    int d

    depth

    int h

    height

    int w

    width

    int c

    channels

    Returns
    Type Description
    int

    flat index (offset in memory)

    IndexWithClamp(int, int, int, int)

    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
    int n

    batch

    int h

    height

    int w

    width

    int c

    channels

    Returns
    Type Description
    int

    flat index (offset in memory)

    IndexWithClamp(int, int, int, int, int)

    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
    int n

    batch

    int d

    depth

    int h

    height

    int w

    width

    int c

    channels

    Returns
    Type Description
    int

    flat index (offset in memory)

    PrepareCacheForAccess(bool)

    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
    bool blocking

    blocking read if true

    Returns
    Type Description
    bool

    true if data is ready

    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
    float[]

    cached linear memory representation of this tensor data

    ToRenderTexture(int, int, float, float, 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 = 1, float bias = 0, Texture3D lut = null)
    Parameters
    Type Name Description
    int batch

    batch

    int fromChannel

    from channel

    float scale

    scale

    float bias

    bias

    Texture3D lut

    lut table

    Returns
    Type Description
    RenderTexture

    ToRenderTexture(RenderTexture, int, int, float, float, 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 = 1, float bias = 0, Texture3D lut = null)
    Parameters
    Type Name Description
    RenderTexture target

    target RenderTexture

    int batch

    batch

    int fromChannel

    from channel

    float scale

    scale

    float bias

    bias

    Texture3D lut

    lut table

    ToRenderTexture(RenderTexture, int, int, 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

    int batch

    batch

    int fromChannel

    from channel

    Vector4 scale

    scale

    Vector4 bias

    bias

    Texture3D lut

    lut table

    ToRenderTexture(RenderTextureFormat, int, int, float, float, 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 = 1, float bias = 0, Texture3D lut = null)
    Parameters
    Type Name Description
    RenderTextureFormat format

    RenderTexture format

    int batch

    batch

    int fromChannel

    from channel

    float scale

    scale

    float bias

    bias

    Texture3D lut

    lut table

    Returns
    Type Description
    RenderTexture

    created RenderTexture

    ToString()

    Tensor metadata summary

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    Tensor metadata summary

    Overrides
    object.ToString()

    UnpinAndDisposeTensor()

    Unload tensor data from device and dispose this Tensor

    Declaration
    [Obsolete("Use Dispose instead.", false)]
    public ITensorData UnpinAndDisposeTensor()
    Returns
    Type Description
    ITensorData

    device specific Tensor data

    UploadToDevice(ITensorData, bool)

    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

    bool invalidateCacheAfterUpload

    invalidate cache after upload

    Events

    tensorDisposed

    Declaration
    public static event Action<Tensor> tensorDisposed
    Event Type
    Type Description
    Action<Tensor>

    Implements

    IDisposable

    Extension Methods

    DeprecatedTensorExtensions.AdjustPadToPool(Tensor, (int, int), int[], int[])
    DeprecatedTensorExtensions.CastOnDevice(Tensor, ITensorData)
    DeprecatedTensorExtensions.PinToDeviceAndDownloadFromIt(Tensor, ITensorData)
    DeprecatedTensorExtensions.PinToDeviceAndUploadToIt(Tensor, ITensorData, bool)
    DeprecatedTensorExtensions.Unpin(Tensor, bool)
    TensorExtensions.Approximately(Tensor, Tensor, float, int)
    TensorExtensions.ArgMax(Tensor)
    TensorExtensions.ArgSort(Tensor)
    TensorExtensions.AsFloats(Tensor)
    TensorExtensions.AsInts(Tensor)
    TensorExtensions.DataToString(Tensor, int)
    TensorExtensions.Equals(Tensor, Tensor)
    TensorExtensions.Fill(Tensor, float)
    TensorExtensions.MaxDifference(Tensor, Tensor)
    TensorExtensions.Print(Tensor, string)
    TensorExtensions.PrintDataPart(Tensor, int, string)
    TensorExtensions.Reshape(Tensor, int[])
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)