docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class TensorFloat

    Represents data in a multidimensional array-like structure.

    Ownership and lifetime:

    • Disposed needs to be called on the main thread.
    • Ownership is always to the owner of the object.

    Data Representation:

    • TensorShape represents the data layout of the tensor
    • Data is held by a tensorData (ITensorData) which can be on a given backend
    • Data is stored in a flattened row major format
    • Data can be pending (ie computation is being done in parallel)
      • call CompleteAllPendingOperations for a blocking call to finish computing the tensor's data
      • call CompleteOperationsAndDownloadAsync/ReadbackRequest for a non blocking call to finish computing the tensor's data Data can be in a non readable type (GPU/NPU)
      • Call CompleteOperationsAndDownload to make the tensor readable (this will fetch the data on the backend and convert it to a readable format)
      • CompleteOperationsAndDownload is a blocking call if called on its own. for a non blocking call, make sure that CompleteOperationsAndDownloadAsync/ReadbackRequest have been called previously you can check that with IsReadbackRequestDone

    Data manipulation

    • ToReadOnlyArray returns a copy of the tensor's data
    • dataOnBackend can be manipulated directly to avoid a unnecessary copy see ComputeTensorData/BurstTensorData for info
    Inheritance
    object
    Tensor
    TensorFloat
    Implements
    IDisposable
    Inherited Members
    Tensor.shape
    Tensor.dataOnBackend
    Tensor.backendType
    Tensor.Reshape(TensorShape)
    Tensor.AttachToDevice(ITensorData)
    Tensor.DetachFromDevice(bool)
    Tensor.CompleteOperationsAndDownload()
    Tensor.CompleteOperationsAndDownloadAsync()
    Tensor.IsReadbackRequestDone()
    Tensor.ReadbackRequest(Action<bool>)
    Tensor.ReadbackRequestAsync()
    Tensor.CompleteAllPendingOperations()
    Tensor.Dispose()
    Tensor.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Sentis
    Assembly: Unity.Sentis.dll
    Syntax
    public class TensorFloat : Tensor, IDisposable

    Constructors

    TensorFloat(float)

    Initializes and returns a scalar tensor with the value of srcData.

    Declaration
    public TensorFloat(float srcData)
    Parameters
    Type Name Description
    float srcData

    The data element of the tensor.

    TensorFloat(TensorShape, float[], int)

    Initializes and returns a tensor with specified shape and a float[] array of srcData data. Sentis reads srcData from dataStartIndex.

    srcData.Length - dataStartIndex must be bigger than or equal to shape.length.

    Declaration
    public TensorFloat(TensorShape shape, float[] srcData, int dataStartIndex = 0)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor.

    float[] srcData

    The data elements of the tensor.

    int dataStartIndex

    The index of the first tensor element in the srcData array.

    TensorFloat(TensorShape, NativeArray<float>, int)

    Initializes and returns a tensor with specified shape and a native float array of srcData data. Sentis reads srcData from dataStartIndex.

    srcData.Length - dataStartIndex must be bigger than or equal to shape.length.

    Declaration
    public TensorFloat(TensorShape shape, NativeArray<float> srcData, int dataStartIndex)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor.

    NativeArray<float> srcData

    The data elements of the tensor.

    int dataStartIndex

    The index of the first tensor element in the srcData native array.

    TensorFloat(TensorShape, ITensorData)

    Instantiates and returns a Tensor with the specified shape, an ITensorData data.

    Declaration
    public TensorFloat(TensorShape shape, ITensorData data)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor.

    ITensorData data

    The optional tensor data.

    Properties

    this[int]

    Returns the tensor element at offset d0.

    Declaration
    public float this[int d0] { get; set; }
    Parameters
    Type Name Description
    int d0

    Axis 0.

    Property Value
    Type Description
    float

    this[int, int]

    Returns the tensor element at offset (d1, d0), which is position d1 * stride0 + d0.

    Declaration
    public float this[int d1, int d0] { get; set; }
    Parameters
    Type Name Description
    int d1

    Axis 1.

    int d0

    Axis 0.

    Property Value
    Type Description
    float

    this[int, int, int]

    Returns the tensor element at offset (d2, d1, d0), which is position d2 * stride1 + d1 * stride0 + d0.

    Declaration
    public float this[int d2, int d1, int d0] { get; set; }
    Parameters
    Type Name Description
    int d2

    Axis 2.

    int d1

    Axis 1.

    int d0

    Axis 0.

    Property Value
    Type Description
    float

    this[int, int, int, int]

    Returns the tensor element at offset (d3, d2, d1, d0), which is position d3 * stride2 + d2 * stride1 + d1 * stride0 + d0 in this tensor.

    Declaration
    public float this[int d3, int d2, int d1, int d0] { get; set; }
    Parameters
    Type Name Description
    int d3

    Axis 3.

    int d2

    Axis 2.

    int d1

    Axis 1.

    int d0

    Axis 0.

    Property Value
    Type Description
    float

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

    Returns the tensor element at offset (d4, d3, d2, d1, d0), which is position d4 * stride3 + d3 * stride2 + d2 * stride1 + d1 * stride0 + d0.

    Declaration
    public float this[int d4, int d3, int d2, int d1, int d0] { get; set; }
    Parameters
    Type Name Description
    int d4

    Axis 4.

    int d3

    Axis 3.

    int d2

    Axis 2.

    int d1

    Axis 1.

    int d0

    Axis 0.

    Property Value
    Type Description
    float

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

    Returns the tensor element at offset (d5, d4, d3, d2, d1, d0), which is position d5 * stride4 + d4 * stride3 + d3 * stride2 + d2 * stride1 + d1 * stride0 + d0.

    Declaration
    public float this[int d5, int d4, int d3, int d2, int d1, int d0] { get; set; }
    Parameters
    Type Name Description
    int d5

    Axis 5.

    int d4

    Axis 4.

    int d3

    Axis 3.

    int d2

    Axis 2.

    int d1

    Axis 1.

    int d0

    Axis 0.

    Property Value
    Type Description
    float

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

    Returns the tensor element at offset (d6, d5, d4, d3, d2, d1, d0), which is position d6 * stride5 + d5 * stride4 + d4 * stride3 + d3 * stride2 + d2 * stride1 + d1 * stride0 + d0.

    Declaration
    public float this[int d6, int d5, int d4, int d3, int d2, int d1, int d0] { get; set; }
    Parameters
    Type Name Description
    int d6

    Axis 6.

    int d5

    Axis 5.

    int d4

    Axis 4.

    int d3

    Axis 3.

    int d2

    Axis 2.

    int d1

    Axis 1.

    int d0

    Axis 0.

    Property Value
    Type Description
    float

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

    Returns the tensor element at offset (d7, d6, d5, d4, d3, d2, d1, d0), which is position d7 * stride6 + d6 * stride5 + d5 * stride4 + d4 * stride3 + d3 * stride2 + d2 * stride1 + d1 * stride0 + d0.

    Declaration
    public float this[int d7, int d6, int d5, int d4, int d3, int d2, int d1, int d0] { get; set; }
    Parameters
    Type Name Description
    int d7

    Axis 7.

    int d6

    Axis 6.

    int d5

    Axis 5.

    int d4

    Axis 4.

    int d3

    Axis 3.

    int d2

    Axis 2.

    int d1

    Axis 1.

    int d0

    Axis 0.

    Property Value
    Type Description
    float

    count

    The length of the tensor.

    Declaration
    public override int count { get; }
    Property Value
    Type Description
    int
    Overrides
    Tensor.count

    dataType

    The data type of the elements of the tensor.

    Declaration
    public override DataType dataType { get; }
    Property Value
    Type Description
    DataType
    Overrides
    Tensor.dataType

    Methods

    AllocNoData(TensorShape)

    Initializes and returns a tensor with the specified shape and with no data.

    Declaration
    public static TensorFloat AllocNoData(TensorShape shape)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor.

    Returns
    Type Description
    TensorFloat

    The instantiated empty tensor.

    AllocZeros(TensorShape)

    Initializes and returns a tensor with the specified shape and filled with 0.

    Declaration
    public static TensorFloat AllocZeros(TensorShape shape)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor.

    Returns
    Type Description
    TensorFloat

    The instantiated zero tensor.

    ToReadOnlyArray()

    Returns a copy of linear memory representation of the data in this tensor.

    the returned array is a deepcopy of the tensor, the caller of this methods is now responsible for it. If you modify the contents of the returned array, it will not modify the underlying tensor

    Declaration
    public float[] ToReadOnlyArray()
    Returns
    Type Description
    float[]

    Float array copy of tensor data.

    ToReadOnlyNativeArray()

    Returns a NativeArray on the linear memory representation of the data in this tensor.

    Declaration
    public NativeArray<float>.ReadOnly ToReadOnlyNativeArray()
    Returns
    Type Description
    NativeArray<float>.ReadOnly

    NativeArray of tensor data.

    ToReadOnlySpan()

    Returns a ReadOnlySpan on the linear memory representation of the data in this tensor.

    Declaration
    public ReadOnlySpan<float> ToReadOnlySpan()
    Returns
    Type Description
    ReadOnlySpan<float>

    Span of tensor data.

    UploadToDevice(ITensorData)

    Uploads the tensor data to the destination data location on device.

    Declaration
    public override void UploadToDevice(ITensorData destination)
    Parameters
    Type Name Description
    ITensorData destination

    The data on device to upload the tensor data to.

    Overrides
    Tensor.UploadToDevice(ITensorData)

    Implements

    IDisposable

    Extension Methods

    TensorExtensions.PrintDataPart(Tensor, int, string)
    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)