docs.unity3d.com
    Show / Hide Table of Contents

    Class ArrayTensorData

    Represents internal Tensor data backed by a managed array.

    Inheritance
    Object
    ArrayTensorData
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Sentis
    Syntax
    public class ArrayTensorData : ITensorData, IDisposable, IConvertibleToBurstTensorData, IConvertibleToComputeTensorData, IReadableTensorData

    Constructors

    ArrayTensorData(TensorShape, Array, Boolean)

    Initializes and returns an instance of ArrayTensorData with a given array of data.

    Declaration
    public ArrayTensorData(TensorShape shape, Array data, bool clearOnInit = true)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor data.

    Array data

    The data to use as backing data.

    Boolean clearOnInit

    ArrayTensorData(TensorShape, Boolean)

    Initializes and returns an instance of ArrayTensorData, and allocates storage for a tensor with the shape of shape.

    Declaration
    public ArrayTensorData(TensorShape shape, bool clearOnInit = true)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor data to allocate.

    Boolean clearOnInit

    Whether to zero the data on allocation. The default value is true.

    ArrayTensorData(TensorShape, NativeTensorArray, Int32, Boolean)

    Initializes and returns an instance of ArrayTensorData with given storage and offset.

    Declaration
    public ArrayTensorData(TensorShape shape, NativeTensorArray data, int offset = 0, bool clearOnInit = true)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor data.

    NativeTensorArray data
    Int32 offset

    The integer offset from the start of the backing array. The default value is 0.

    Boolean clearOnInit

    Whether to zero the data on instantiation. The default value is true.

    Properties

    array

    The NativeTensorArray managed array containing the Tensor data.

    Declaration
    public NativeTensorArray array { get; }
    Property Value
    Type Description
    NativeTensorArray

    deviceType

    On what device backend are the data elements stored.

    Declaration
    public DeviceType deviceType { get; }
    Property Value
    Type Description
    DeviceType
    Implements
    ITensorData.deviceType

    maxCapacity

    The maximum count of the stored data elements.

    Declaration
    public int maxCapacity { get; }
    Property Value
    Type Description
    Int32
    Implements
    ITensorData.maxCapacity

    shape

    The shape of the tensor using this data as a TensorShape.

    Declaration
    public TensorShape shape { get; }
    Property Value
    Type Description
    TensorShape

    Methods

    AsyncReadbackRequest(Action<Boolean>)

    Schedules asynchronous readback of the internal data.

    Invokes callback when async readback is finished.

    Boolean indicates if async readback is successful.

    Declaration
    public void AsyncReadbackRequest(Action<bool> callback = null)
    Parameters
    Type Name Description
    Action<Boolean> callback
    Implements
    ITensorData.AsyncReadbackRequest(Action<Boolean>)

    Clone()

    Returns a deep copy of the internal storage.

    Declaration
    public ITensorData Clone()
    Returns
    Type Description
    ITensorData
    Implements
    ITensorData.Clone()

    CompleteAllPendingOperations()

    Blocking call to make sure that internal data is correctly written to and available for CPU read back.

    Declaration
    public void CompleteAllPendingOperations()
    Implements
    ITensorData.CompleteAllPendingOperations()

    ConvertToBurstTensorData(TensorShape)

    Implement this method to convert to BurstTensorData.

    Declaration
    public BurstTensorData ConvertToBurstTensorData(TensorShape shape)
    Parameters
    Type Name Description
    TensorShape shape
    Returns
    Type Description
    BurstTensorData
    Implements
    IConvertibleToBurstTensorData.ConvertToBurstTensorData(TensorShape)

    ConvertToComputeTensorData(TensorShape)

    Implement this method to convert to ComputeTensorData.

    Declaration
    public ComputeTensorData ConvertToComputeTensorData(TensorShape shape)
    Parameters
    Type Name Description
    TensorShape shape
    Returns
    Type Description
    ComputeTensorData
    Implements
    IConvertibleToComputeTensorData.ConvertToComputeTensorData(TensorShape)

    Dispose()

    Disposes of the ArrayTensorData and any associated memory.

    Declaration
    public void Dispose()
    Implements
    IDisposable.Dispose()

    Download<T>(Int32, Int32)

    Returns data from internal storage.

    Declaration
    public NativeArray<T> Download<T>(int dstCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    Int32 dstCount
    Int32 srcOffset
    Returns
    Type Description
    NativeArray<T>
    Type Parameters
    Name Description
    T
    Implements
    ITensorData.Download<T>(Int32, Int32)

    Get<T>(Int32)

    Returns a data element at index.

    Declaration
    public T Get<T>(int index)
        where T : struct
    Parameters
    Type Name Description
    Int32 index
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    Implements
    IReadableTensorData.Get<T>(Int32)

    GetReadOnlyNativeArrayHandle<T>(Int32, Int32)

    Returns a ReadOnlyNativeArray handle on the linear memory data.

    Declaration
    public NativeArray<T>.ReadOnly GetReadOnlyNativeArrayHandle<T>(int dstCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    Int32 dstCount
    Int32 srcOffset
    Returns
    Type Description
    NativeArray.ReadOnly<>
    Type Parameters
    Name Description
    T
    Implements
    IReadableTensorData.GetReadOnlyNativeArrayHandle<T>(Int32, Int32)

    IsAsyncReadbackRequestDone()

    Checks if asynchronous readback request it done.

    Returns true if async readback is successful.

    Declaration
    public bool IsAsyncReadbackRequestDone()
    Returns
    Type Description
    Boolean
    Implements
    ITensorData.IsAsyncReadbackRequestDone()

    Pin(Tensor, Boolean)

    Moves the tensor into memory on the CPU backend device. The Tensor to move to the CPU. Whether to initialize the backend data. The default value is true.

    Declaration
    public static ArrayTensorData Pin(Tensor X, bool clearOnInit = true)
    Parameters
    Type Name Description
    Tensor X
    Boolean clearOnInit
    Returns
    Type Description
    ArrayTensorData

    Reserve(Int32)

    Reserves memory for count elements.

    Declaration
    public void Reserve(int count)
    Parameters
    Type Name Description
    Int32 count
    Implements
    ITensorData.Reserve(Int32)

    Set<T>(Int32, T)

    Sets value data element at index.

    Declaration
    public void Set<T>(int index, T value)
        where T : struct
    Parameters
    Type Name Description
    Int32 index
    T value
    Type Parameters
    Name Description
    T
    Implements
    IReadableTensorData.Set<T>(Int32, T)

    ToArray<T>(Int32, Int32)

    Returns a array that is a copy of the linear memory data.

    Declaration
    public T[] ToArray<T>(int dstCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    Int32 dstCount
    Int32 srcOffset
    Returns
    Type Description
    T[]
    Type Parameters
    Name Description
    T
    Implements
    IReadableTensorData.ToArray<T>(Int32, Int32)

    ToReadOnlySpan<T>(Int32, Int32)

    Returns a ReadOnlySpan on the linear memory data.

    Declaration
    public ReadOnlySpan<T> ToReadOnlySpan<T>(int dstCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    Int32 dstCount
    Int32 srcOffset
    Returns
    Type Description
    ReadOnlySpan<T>
    Type Parameters
    Name Description
    T
    Implements
    IReadableTensorData.ToReadOnlySpan<T>(Int32, Int32)

    ToString()

    Returns a summary of the storage used by the tensor array, as a string.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    Object.ToString()

    Upload<T>(NativeArray<T>, Int32, Int32)

    Uploads the tensor data to internal storage.

    Declaration
    public void Upload<T>(NativeArray<T> data, int srCount, int srcOffset = 0)
        where T : struct
    Parameters
    Type Name Description
    NativeArray<T> data
    Int32 srCount
    Int32 srcOffset
    Type Parameters
    Name Description
    T
    Implements
    ITensorData.Upload<T>(NativeArray<T>, Int32, Int32)

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
      • ArrayTensorData(TensorShape, Array, Boolean)
      • ArrayTensorData(TensorShape, Boolean)
      • ArrayTensorData(TensorShape, NativeTensorArray, Int32, Boolean)
    • Properties
      • array
      • deviceType
      • maxCapacity
      • shape
    • Methods
      • AsyncReadbackRequest(Action<Boolean>)
      • Clone()
      • CompleteAllPendingOperations()
      • ConvertToBurstTensorData(TensorShape)
      • ConvertToComputeTensorData(TensorShape)
      • Dispose()
      • Download<T>(Int32, Int32)
      • Get<T>(Int32)
      • GetReadOnlyNativeArrayHandle<T>(Int32, Int32)
      • IsAsyncReadbackRequestDone()
      • Pin(Tensor, Boolean)
      • Reserve(Int32)
      • Set<T>(Int32, T)
      • ToArray<T>(Int32, Int32)
      • ToReadOnlySpan<T>(Int32, Int32)
      • ToString()
      • Upload<T>(NativeArray<T>, Int32, Int32)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023