docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct Tensor

    Data structure to hold Tensor values.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: UnityEngine.Perception.GroundTruth.DataModel
    Assembly: Unity.Perception.Runtime.dll
    Syntax
    public struct Tensor

    Constructors

    Tensor(ElementType, int[])

    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

    int[] shape

    The shape of the tensor

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

    int[] 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 readonly byte[] buffer { 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 readonly int count { get; }
    Property Value
    Type Description
    int

    elementType

    The element type of the tensor. The tensor class only supports tensors of the enumerated element types.

    Declaration
    public readonly Tensor.ElementType elementType { 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 readonly int[] shape { get; }
    Property Value
    Type Description
    int[]

    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 readonly int size { get; }
    Property Value
    Type Description
    int

    Methods

    GetElementAt(int[], out bool)

    Retrieve the casted element at the index in the tensor.

    Declaration
    public void GetElementAt(int[] index, out bool value)
    Parameters
    Type Name Description
    int[] 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

    bool value

    The retrieved value

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the requested element is the wrong type for the tensor

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

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the requested element is the wrong type for the tensor

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

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the requested element is the wrong type for the tensor

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

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the requested element is the wrong type for the tensor

    GetElementAt(int[], out int)

    Retrieve the casted element at the index in the tensor.

    Declaration
    public void GetElementAt(int[] index, out int value)
    Parameters
    Type Name Description
    int[] 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

    int value

    The retrieved value

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the requested element is the wrong type for the tensor

    GetElementAt(int[], out long)

    Retrieve the casted element at the index in the tensor.

    Declaration
    public void GetElementAt(int[] index, out long value)
    Parameters
    Type Name Description
    int[] 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

    long value

    The retrieved value

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the requested element is the wrong type for the tensor

    GetElementAt(int[], out float)

    Retrieve the casted element at the index in the tensor.

    Declaration
    public void GetElementAt(int[] index, out float value)
    Parameters
    Type Name Description
    int[] 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

    float value

    The retrieved value

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the requested element is the wrong type for the tensor

    GetElementAt(int[], out uint)

    Retrieve the casted element at the index in the tensor.

    Declaration
    public void GetElementAt(int[] index, out uint value)
    Parameters
    Type Name Description
    int[] 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

    uint value

    The retrieved value

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the requested element is the wrong type for the tensor

    SetElementAt(int[], bool)

    Sets the value int the tensor to the passed in value.

    Declaration
    public void SetElementAt(int[] index, bool value)
    Parameters
    Type Name Description
    int[] 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

    bool value

    The value to set

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the passed in element is the wrong type for the tensor

    SetElementAt(int[], byte)

    Sets the value int the tensor to the passed in value.

    Declaration
    public void SetElementAt(int[] index, byte value)
    Parameters
    Type Name Description
    int[] 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

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the passed in element is the wrong type for the tensor

    SetElementAt(int[], char)

    Sets the value int the tensor to the passed in value.

    Declaration
    public void SetElementAt(int[] index, char value)
    Parameters
    Type Name Description
    int[] 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

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the passed in element is the wrong type for the tensor

    SetElementAt(int[], double)

    Sets the value int the tensor to the passed in value.

    Declaration
    public void SetElementAt(int[] index, double value)
    Parameters
    Type Name Description
    int[] 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

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the passed in element is the wrong type for the tensor

    SetElementAt(int[], int)

    Sets the value int the tensor to the passed in value.

    Declaration
    public void SetElementAt(int[] index, int value)
    Parameters
    Type Name Description
    int[] 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

    int value

    The value to set

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the passed in element is the wrong type for the tensor

    SetElementAt(int[], long)

    Sets the value int the tensor to the passed in value.

    Declaration
    public void SetElementAt(int[] index, long value)
    Parameters
    Type Name Description
    int[] 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

    long value

    The value to set

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the passed in element is the wrong type for the tensor

    SetElementAt(int[], float)

    Sets the value int the tensor to the passed in value.

    Declaration
    public void SetElementAt(int[] index, float value)
    Parameters
    Type Name Description
    int[] 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

    float value

    The value to set

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the passed in element is the wrong type for the tensor

    SetElementAt(int[], uint)

    Sets the value int the tensor to the passed in value.

    Declaration
    public void SetElementAt(int[] index, uint value)
    Parameters
    Type Name Description
    int[] 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

    uint value

    The value to set

    Exceptions
    Type Condition
    ArgumentException

    Thrown if either the index is not the proper size or the passed in element is the wrong type for the tensor

    In This Article
    Back to top
    Copyright © 2024 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)