docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class TensorExtensions

    Tensor extension methods

    Inheritance
    object
    TensorExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Barracuda
    Assembly: Unity.Barracuda.dll
    Syntax
    public static class TensorExtensions

    Methods

    ApplyBorder(TensorShape, int[])

    Calculate new shape after applying border to current TensorShape

    Declaration
    public static TensorShape ApplyBorder(this TensorShape shape, int[] border)
    Parameters
    Type Name Description
    TensorShape shape

    TensorShape

    int[] border

    border

    Returns
    Type Description
    TensorShape

    new TensorShape

    Approximately(Tensor, Tensor, float, int)

    Compare Tensor contents approximately

    Declaration
    public static bool Approximately(this Tensor X, Tensor Y, float epsilon = 0.0001, int count = -1)
    Parameters
    Type Name Description
    Tensor X

    left Tensor

    Tensor Y

    right Tensor

    float epsilon

    comparison threshold

    int count

    limit number of elements to compare

    Returns
    Type Description
    bool

    true if shape match and while data content matches approximately

    AreAllTensorsConvertibleTo4D(Tensor[])

    Check if all tensors are convertible to 4D tensors

    Declaration
    public static bool AreAllTensorsConvertibleTo4D(Tensor[] tensors)
    Parameters
    Type Name Description
    Tensor[] tensors

    tensors

    Returns
    Type Description
    bool

    true if all tensors are 4D (or less)

    ArgMax(Tensor)

    Calculate max value index

    Declaration
    public static int[] ArgMax(this Tensor X)
    Parameters
    Type Name Description
    Tensor X

    Tensor

    Returns
    Type Description
    int[]

    max value index

    ArgSort(Tensor)

    Return indices in order that would produce sorted Tensor values

    Declaration
    public static int[][] ArgSort(this Tensor X)
    Parameters
    Type Name Description
    Tensor X

    Tensor

    Returns
    Type Description
    int[][]

    indices in order that would produce sorted Tensor values

    AsFloats(Tensor)

    Return Tensor data as float array, this will create a blocking read operation

    Declaration
    public static float[] AsFloats(this Tensor x)
    Parameters
    Type Name Description
    Tensor x

    Tensor

    Returns
    Type Description
    float[]

    Tensor data as float array

    AsInts(Tensor)

    Return Tensor data as int array (slow operation), this will create a blocking read operation

    Declaration
    public static int[] AsInts(this Tensor x)
    Parameters
    Type Name Description
    Tensor x

    Tensor

    Returns
    Type Description
    int[]

    Tensor data as int array

    Concat(TensorShape[], int)

    Calculate concatenation output shape

    Declaration
    public static TensorShape Concat(TensorShape[] shapes, int axis)
    Parameters
    Type Name Description
    TensorShape[] shapes

    input shapes

    int axis

    concatenation axis

    Returns
    Type Description
    TensorShape

    output shape

    Exceptions
    Type Condition
    ArgumentException

    Off-axis dimension mismatch

    Concat(Tensor[], int)

    Concatenate Tensor array along axis and calculate output shape

    Declaration
    public static TensorShape Concat(Tensor[] tensors, int axis)
    Parameters
    Type Name Description
    Tensor[] tensors

    Tensor array

    int axis

    axis

    Returns
    Type Description
    TensorShape

    new TensorShape

    Exceptions
    Type Condition
    ArgumentException

    Off-axis dimension mismatch

    CreateFromTexture(Texture, TensorShape)

    Create ITensorData from Texture

    Declaration
    public static ITensorData CreateFromTexture(Texture tex, TensorShape shape)
    Parameters
    Type Name Description
    Texture tex

    Texture

    TensorShape shape

    shape

    Returns
    Type Description
    ITensorData

    created ITensorData

    Exceptions
    Type Condition
    NotImplementedException

    thrown if unsupported texture type is supplied

    DataToString(Tensor, int)

    Return Tensor data as string, limits number of elements to size

    Declaration
    public static string DataToString(this Tensor X, int size = 32)
    Parameters
    Type Name Description
    Tensor X

    Tensor

    int size

    element number limit

    Returns
    Type Description
    string

    Returns Tensor data as string

    Equals(Tensor, Tensor)

    Compare Tensor contents

    Declaration
    public static bool Equals(this Tensor X, Tensor Y)
    Parameters
    Type Name Description
    Tensor X

    left Tensor

    Tensor Y

    right Tensor

    Returns
    Type Description
    bool

    true if shape and data content matches

    Fill(Tensor, float)

    Fill Tensor with value

    Declaration
    public static void Fill(this Tensor X, float value)
    Parameters
    Type Name Description
    Tensor X

    Tensor

    float value

    value

    Gather(TensorShape[], int)

    Calculate output shape for Gather operation

    Declaration
    public static TensorShape Gather(TensorShape[] shapes, int axis)
    Parameters
    Type Name Description
    TensorShape[] shapes

    input shapes

    int axis

    axis

    Returns
    Type Description
    TensorShape

    output shape

    Get8DPermutationsForNHWCPermutationsAndShape(TensorShape, int[])

    Calculate 8D permutations from 4D

    Declaration
    public static int[] Get8DPermutationsForNHWCPermutationsAndShape(this TensorShape shape, int[] permutations)
    Parameters
    Type Name Description
    TensorShape shape

    shape

    int[] permutations

    permutations

    Returns
    Type Description
    int[]

    8D permutations

    Max(TensorShape[])

    Calculate maximum shape that would cover all input shapes

    Declaration
    public static TensorShape Max(TensorShape[] shapes)
    Parameters
    Type Name Description
    TensorShape[] shapes

    input shapes

    Returns
    Type Description
    TensorShape

    output shape

    MaxDifference(Tensor, Tensor)

    Calculate max difference between two tensors

    Declaration
    public static float MaxDifference(this Tensor X, Tensor Y)
    Parameters
    Type Name Description
    Tensor X

    first Tensor

    Tensor Y

    second Tensor

    Returns
    Type Description
    float

    MaxShape(Tensor[])

    Calculate maximum shape that would cover all input tensors

    Declaration
    public static TensorShape MaxShape(Tensor[] tensors)
    Parameters
    Type Name Description
    Tensor[] tensors

    input tensors

    Returns
    Type Description
    TensorShape

    output shape

    Permute(int[], int[])

    Calculate shape after applying permutations

    Declaration
    public static int[] Permute(int[] shape, int[] permutations)
    Parameters
    Type Name Description
    int[] shape

    shape

    int[] permutations

    permutations

    Returns
    Type Description
    int[]

    new shape

    Permute(TensorShape, int[])

    Calculate TensorShape after applying permutations

    Declaration
    public static TensorShape Permute(this TensorShape shape, int[] permutations)
    Parameters
    Type Name Description
    TensorShape shape

    shape

    int[] permutations

    permutations

    Returns
    Type Description
    TensorShape

    new TensorShape

    Print(Tensor, string)

    Print Tensor metadata to console

    Declaration
    public static void Print(this Tensor X, string msg = "")
    Parameters
    Type Name Description
    Tensor X

    Tensor

    string msg

    message prefix

    PrintDataPart(Tensor, int, string)

    Print Tensor data to console

    Declaration
    public static void PrintDataPart(this Tensor X, int size, string msg = "")
    Parameters
    Type Name Description
    Tensor X

    Tensor

    int size

    element number limit

    string msg

    message prefix

    Reduce(TensorShape, int)

    Reduce TensorShape across specified axis

    Declaration
    public static TensorShape Reduce(this TensorShape shape, int axis)
    Parameters
    Type Name Description
    TensorShape shape

    TensorShape

    int axis

    axis

    Returns
    Type Description
    TensorShape

    output shape

    Reshape(Tensor, int[])

    Reshape Tensor

    Declaration
    public static Tensor Reshape(this Tensor X, int[] size)
    Parameters
    Type Name Description
    Tensor X

    Tensor

    int[] size

    new shape as array of int (expected as size 4 for NHWC or size 8 for SRNTDHWC)

    Returns
    Type Description
    Tensor

    reshaped Tensor

    Reshape(TensorShape, int[])

    Reshape TensorShape into new shape specified by size. At most one dimension of the new shape can be -1. See: https://github.com/onnx/onnx/blob/master/docs/Operators.md#Reshape

    Declaration
    public static TensorShape Reshape(this TensorShape shape, int[] size4Dor8D)
    Parameters
    Type Name Description
    TensorShape shape

    TensorShape

    int[] size4Dor8D

    new shape

    Returns
    Type Description
    TensorShape

    output shape

    Exceptions
    Type Condition
    ArgumentException

    more than one dimension is unspecified

    Scale(TensorShape, int[])

    Scale TensorShape by the scale factor

    Declaration
    public static TensorShape Scale(this TensorShape shape, int[] scale)
    Parameters
    Type Name Description
    TensorShape shape

    TensorShape

    int[] scale

    scale

    Returns
    Type Description
    TensorShape

    output shape

    Scale(TensorShape, TensorShape)

    Scale TensorShape by the scale factor

    Declaration
    public static TensorShape Scale(this TensorShape shape, TensorShape scale)
    Parameters
    Type Name Description
    TensorShape shape

    TensorShape

    TensorShape scale

    scale

    Returns
    Type Description
    TensorShape

    output shape

    WrapIndex(int, int)

    Wrap index (emulate Python array index behavior)

    Declaration
    public static int WrapIndex(int i, int length)
    Parameters
    Type Name Description
    int i

    index

    int length

    array length

    Returns
    Type Description
    int

    wrapped around index

    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)