Struct TensorShape | Barracuda | 1.0.4
docs.unity3d.com
    Show / Hide Table of Contents

    Struct TensorShape

    TensorShape are immutable representation of a Tensor dimensions and rank. At the moment a TensorShape is always of rank 4 and channels last ie NHWC. However an axis can be of size 1. For example a tensor without spatial information will be N,1,1,C

    Inherited Members
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Namespace: Unity.Barracuda
    Syntax
    [Serializable]
    public struct TensorShape

    Constructors

    TensorShape(Int32, Int32)

    Create a TensorShape of shape [N,1,1,C].

    Declaration
    public TensorShape(int n, int c)
    Parameters
    Type Name Description
    Int32 n
    Int32 c

    TensorShape(Int32, Int32, Int32, Int32)

    Create a TensorShape of shape [N,H,W,C].

    Declaration
    public TensorShape(int n, int h, int w, int c)
    Parameters
    Type Name Description
    Int32 n
    Int32 h
    Int32 w
    Int32 c

    TensorShape(Int32[])

    Create a TensorShape of arbitrary shape. Currently shape can have only up to 4 dimensions.

    Declaration
    public TensorShape(int[] shape)
    Parameters
    Type Name Description
    Int32[] shape

    Fields

    batch

    Return the number of batch.

    Declaration
    public readonly int batch
    Field Value
    Type Description
    Int32

    channels

    Return the number of channels.

    Declaration
    public readonly int channels
    Field Value
    Type Description
    Int32

    height

    Return the spatial height.

    Declaration
    public readonly int height
    Field Value
    Type Description
    Int32

    width

    Return the spatial width.

    Declaration
    public readonly int width
    Field Value
    Type Description
    Int32

    Properties

    dimensions

    Return the count of non-unit dimension of this shape. For example [N,1,1,C] dimensions is 2.

    Declaration
    public int dimensions { get; }
    Property Value
    Type Description
    Int32

    flatHeight

    Return the number of batch.

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

    flatWidth

    Return the HWC.

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

    Item[Int32]

    Indexer to return a dimension of this tensorShape as [N,H,W,C] Prefer this over ToArray() to avoid GC allocation/collection.

    Declaration
    public int this[int axis] { get; }
    Parameters
    Type Name Description
    Int32 axis
    Property Value
    Type Description
    Int32

    kernelCount

    Kernel dimension ordering is [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
    Int32

    kernelDepth

    Kernel dimension ordering is [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
    Int32

    kernelHeight

    Kernel dimension ordering is [H,W,C,K] for efficiency purpose. Return kernel height.

    Declaration
    public int kernelHeight { get; }
    Property Value
    Type Description
    Int32

    kernelWidth

    Kernel dimension ordering is [H,W,C,K] for efficiency purpose. Return kernel width.

    Declaration
    public int kernelWidth { get; }
    Property Value
    Type Description
    Int32

    length

    Return the total number of elements represented by this shape.

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

    rank

    Always 4, look also at the dimensions property.

    Declaration
    public int rank { get; }
    Property Value
    Type Description
    Int32

    Methods

    Axis(Int32)

    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
    Int32 axis
    Returns
    Type Description
    Int32

    Equals(Object)

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj
    Returns
    Type Description
    Boolean
    Overrides
    ValueType.Equals(Object)

    Flatten()

    Return a TensorShape of dimensions [N,1,1,HWC]

    Declaration
    public TensorShape Flatten()
    Returns
    Type Description
    TensorShape

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32
    Overrides
    ValueType.GetHashCode()

    GetPositionsFromIndex(Int32, ref Int32, ref Int32, ref Int32, ref Int32)

    Given an offset in memory return the dimensions indices of the element as [N,H,W,C].

    Declaration
    public void GetPositionsFromIndex(int index, ref int n, ref int h, ref int w, ref int c)
    Parameters
    Type Name Description
    Int32 index
    Int32 n
    Int32 h
    Int32 w
    Int32 c

    Index(Int32, Int32)

    Given an element dimensions indices [N,0,0,C] return this element offset in memory.

    Declaration
    public int Index(int n, int c)
    Parameters
    Type Name Description
    Int32 n
    Int32 c
    Returns
    Type Description
    Int32

    Index(Int32, Int32, Int32, Int32)

    Given an element dimensions indices [N,H,W,C] return this element offset in memory.

    Declaration
    public int Index(int n, int h, int w, int c)
    Parameters
    Type Name Description
    Int32 n
    Int32 h
    Int32 w
    Int32 c
    Returns
    Type Description
    Int32

    IndexWithBroadcast(Int32, Int32, Int32, Int32)

    Given an element dimensions indices [N,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
    Int32 n
    Int32 h
    Int32 w
    Int32 c
    Returns
    Type Description
    Int32

    IndexWithClamp(Int32, Int32, Int32, Int32)

    Given an element dimensions indices [N,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
    Int32 n
    Int32 h
    Int32 w
    Int32 c
    Returns
    Type Description
    Int32

    Squeeze()

    Remove single-dimensional entries from the shape. [b=4,h=1,w=1,c=128] => [b=1,h=1,w=4,c=128]

    Declaration
    public TensorShape Squeeze()
    Returns
    Type Description
    TensorShape

    ToArray()

    Return an array representation of this tensorShape as [N,H,W,C] Prefer tensorShape[x] to avoid GC allocation/collection.

    Declaration
    public int[] ToArray()
    Returns
    Type Description
    Int32[]

    ToString()

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

    Operators

    Equality(TensorShape, TensorShape)

    Declaration
    public static bool operator ==(TensorShape a, TensorShape b)
    Parameters
    Type Name Description
    TensorShape a
    TensorShape b
    Returns
    Type Description
    Boolean

    Inequality(TensorShape, TensorShape)

    Declaration
    public static bool operator !=(TensorShape a, TensorShape b)
    Parameters
    Type Name Description
    TensorShape a
    TensorShape b
    Returns
    Type Description
    Boolean

    Extension Methods

    TensorExtensions.Scale(TensorShape, TensorShape)
    TensorExtensions.Scale(TensorShape, Int32[])
    TensorExtensions.Reduce(TensorShape, Int32)
    TensorExtensions.Reshape(TensorShape, Int32[])
    TensorExtensions.ApplyBorder(TensorShape, Int32[])
    TensorExtensions.AdjustPadToKernel(TensorShape, TensorShape, Int32[], Int32[])
    TensorExtensions.AdjustPadToPool(TensorShape, Int32[], Int32[], Int32[])
    TensorExtensions.AdjustPadToPool(TensorShape, ValueTuple<Int32, Int32>, Int32[], Int32[])
    TensorExtensions.ApplyPool(TensorShape, Int32[], Int32[], Int32[], Boolean)
    TensorExtensions.ApplyPool(TensorShape, ValueTuple<Int32, Int32>, Int32[], Int32[], Boolean)
    TensorExtensions.ApplyKernel(TensorShape, TensorShape, Int32[], Int32[])
    TensorExtensions.ApplyKernelInverse(TensorShape, TensorShape, Int32[], Int32[], Int32[])
    TensorExtensions.ApplyStridedSlice(TensorShape, Int32[], 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