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

    Namespace: Unity.Barracuda
    Syntax
    public struct TensorShape

    Constructors

    TensorShape(Int32)

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

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

    batch

    TensorShape(Int32, Int32)

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

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

    batch

    Int32 c

    channels

    TensorShape(Int32, Int32, Int32)

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

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

    batch

    Int32 w

    width

    Int32 c

    channels

    TensorShape(Int32, Int32, Int32, Int32)

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

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

    batch

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    TensorShape(Int32, Int32, Int32, Int32, Int32)

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

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

    batch

    Int32 d

    depth

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    TensorShape(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

    Create a TensorShape of shape [S,R,N,T,D,H,W,C]. Currently seqLen must be 1.

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

    sequence

    Int32 r

    direction

    Int32 n

    batch

    Int32 t

    time

    Int32 d

    depth

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    TensorShape(Int32[])

    Create a TensorShape of arbitrary shape. shape must be of length 4 [N,H,W,C] or 8 [S,R,N,T,D,H,W,C]. If shape.length is 4 then the dimensions S,R,T and D will be defaulted to 1.

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

    shape as int array

    Fields

    batch

    Return the number of batch.

    Declaration
    public readonly int batch
    Field Value
    Type Description
    Int32

    C

    Channels dimension index number

    Declaration
    public const int C = null
    Field Value
    Type Description
    Int32

    channels

    Return the number of channels.

    Declaration
    public readonly int channels
    Field Value
    Type Description
    Int32

    D

    Depth dimension index number

    Declaration
    public const int D = null
    Field Value
    Type Description
    Int32

    DataBatch

    Batch dimension index number

    Declaration
    public const int DataBatch = null
    Field Value
    Type Description
    Int32

    DataChannel

    Data channel dimension index number

    Declaration
    public const int DataChannel = null
    Field Value
    Type Description
    Int32

    DataFeature0

    Data feature 0 dimension index number

    Declaration
    public const int DataFeature0 = null
    Field Value
    Type Description
    Int32

    DataFeature1

    Data feature 1 dimension index number

    Declaration
    public const int DataFeature1 = null
    Field Value
    Type Description
    Int32

    DataFeature2

    Data feature 2 dimension index number

    Declaration
    public const int DataFeature2 = null
    Field Value
    Type Description
    Int32

    DataFeature3

    Data feature 3 dimension index number

    Declaration
    public const int DataFeature3 = null
    Field Value
    Type Description
    Int32

    DataFeatures

    Data features

    Declaration
    public static readonly int[] DataFeatures
    Field Value
    Type Description
    Int32[]

    depth

    Return the spatial depth (axis is DataFeature2).

    Declaration
    public readonly int depth
    Field Value
    Type Description
    Int32

    H

    Height dimension index number

    Declaration
    public const int H = null
    Field Value
    Type Description
    Int32

    height

    Return the spatial height (axis is DataFeature1).

    Declaration
    public readonly int height
    Field Value
    Type Description
    Int32

    KernelInChannel

    Kernel input channel dimension

    Declaration
    public const int KernelInChannel = null
    Field Value
    Type Description
    Int32

    KernelOutChannel

    Kernel output channel dimension

    Declaration
    public const int KernelOutChannel = null
    Field Value
    Type Description
    Int32

    KernelSpatial0

    Kernel spatial dimension 0

    Declaration
    public const int KernelSpatial0 = null
    Field Value
    Type Description
    Int32

    KernelSpatial1

    Kernel spatial dimension 1

    Declaration
    public const int KernelSpatial1 = null
    Field Value
    Type Description
    Int32

    KernelSpatial2

    Kernel spatial dimension 2

    Declaration
    public const int KernelSpatial2 = null
    Field Value
    Type Description
    Int32

    KernelSpatial3

    Kernel spatial dimension 3

    Declaration
    public const int KernelSpatial3 = null
    Field Value
    Type Description
    Int32

    KernelSpatials

    Kernel spatial dimensions

    Declaration
    public static readonly int[] KernelSpatials
    Field Value
    Type Description
    Int32[]

    MaxRank

    Max rank

    Declaration
    public const int MaxRank = null
    Field Value
    Type Description
    Int32

    numberOfDirections

    Return the number of direction.

    Declaration
    public readonly int numberOfDirections
    Field Value
    Type Description
    Int32

    NumberOfDirections

    Sequence length dimension index number

    Declaration
    public const int NumberOfDirections = null
    Field Value
    Type Description
    Int32

    sequenceLength

    Return the number of sequence.

    Declaration
    public readonly int sequenceLength
    Field Value
    Type Description
    Int32

    SequenceLength

    Sequence length dimension index number

    Declaration
    public const int SequenceLength = null
    Field Value
    Type Description
    Int32

    W

    Width dimension index number

    Declaration
    public const int W = null
    Field Value
    Type Description
    Int32

    width

    Return the spatial width (axis is DataFeature0).

    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 TDHWC.

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

    Item[Int32]

    Indexer to return a dimension of this tensorShape as [S,R,N,T,D,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

    axis

    Property Value
    Type Description
    Int32

    kernelCount

    Kernel dimension ordering is [D,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 [D,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 [D,H,W,C,K] for efficiency purpose. Return kernel height.

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

    kernelSpatialDepth

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

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

    kernelWidth

    Kernel dimension ordering is [D,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 8, 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

    axis

    Returns
    Type Description
    Int32

    adjusted axis

    Equals(System.Object)

    Compares this object to other object

    Declaration
    public override bool Equals(System.Object obj)
    Parameters
    Type Name Description
    System.Object obj

    other object

    Returns
    Type Description
    Boolean

    true if contents of the objects a and b are equal

    Flatten()

    Return a TensorShape of dimensions [S,R,N,1,1,1,1,TDHWC]

    Declaration
    public TensorShape Flatten()
    Returns
    Type Description
    TensorShape

    new TensorShape

    GetHashCode()

    Object hash code

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    object hash code

    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

    one dimensional index (offset) in the memory

    Int32 n

    batch

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

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

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

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

    one dimensional index (offset) in the memory

    Int32 s

    sequence

    Int32 r

    direction

    Int32 n

    batch

    Int32 t

    time

    Int32 d

    depth

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Index(Int32, Int32)

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

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

    batch

    Int32 c

    channels

    Returns
    Type Description
    Int32

    one dimensional index (offset in the flat memory region)

    Index(Int32, Int32, Int32, Int32)

    Given an element dimensions indices [0,0,N,0,0,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

    batch

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Returns
    Type Description
    Int32

    one dimensional index (offset in the flat memory region)

    Index(Int32, Int32, Int32, Int32, Int32)

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

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

    batch

    Int32 d

    depth

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Returns
    Type Description
    Int32

    one dimensional index (offset in the flat memory region)

    Index(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

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

    Declaration
    public int Index(int s, int r, int n, int t, int d, int h, int w, int c)
    Parameters
    Type Name Description
    Int32 s

    sequence

    Int32 r

    direction

    Int32 n

    batch

    Int32 t

    time

    Int32 d

    depth

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Returns
    Type Description
    Int32

    one dimensional index (offset in the flat memory region)

    IndexWithBroadcast(Int32, Int32, Int32, Int32)

    Given an element dimensions indices [0,0,N,0,0,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

    batch

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Returns
    Type Description
    Int32

    IndexWithBroadcast(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

    Given an element dimensions indices [S,R,N,T,D,H,W,C] with broadcast support, return this element offset in memory.

    Declaration
    public int IndexWithBroadcast(int s, int r, int n, int t, int d, int h, int w, int c)
    Parameters
    Type Name Description
    Int32 s

    sequence

    Int32 r

    direction

    Int32 n

    batch

    Int32 t

    time

    Int32 d

    depth

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Returns
    Type Description
    Int32

    one dimensional index (offset in the flat memory region)

    IndexWithClamp(Int32, Int32, Int32, Int32)

    Given an element dimensions indices [1,N,1,1,1,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

    batch

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Returns
    Type Description
    Int32

    one dimensional index (offset in the flat memory region)

    IndexWithClamp(Int32, Int32, Int32, Int32, Int32)

    Given an element dimensions indices [1,N,1,1,D,H,W,C] return this element offset in memory, clamping indices to tensor dimensions.

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

    batch

    Int32 d

    depth

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Returns
    Type Description
    Int32

    one dimensional index (offset in the flat memory region)

    IndexWithClamp(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

    Given an element dimensions indices [S,R,N,T,D,H,W,C] return this element offset in memory, clamping indices to tensor dimensions.

    Declaration
    public int IndexWithClamp(int s, int r, int n, int t, int d, int h, int w, int c)
    Parameters
    Type Name Description
    Int32 s

    sequence

    Int32 r

    direction

    Int32 n

    batch

    Int32 t

    time

    Int32 d

    depth

    Int32 h

    height

    Int32 w

    width

    Int32 c

    channels

    Returns
    Type Description
    Int32

    one dimensional index (offset in the flat memory region)

    Squeeze()

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

    Declaration
    public TensorShape Squeeze()
    Returns
    Type Description
    TensorShape

    new TensorShape

    ToArray()

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

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

    shape as int array

    ToString()

    Object summary

    Declaration
    public override string ToString()
    Returns
    Type Description
    String

    object summary as a string

    Operators

    Equality(TensorShape, TensorShape)

    Compares two TensorShape objects

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

    left object

    TensorShape b

    right object

    Returns
    Type Description
    Boolean

    true if contents of the objects a and b are equal

    Inequality(TensorShape, TensorShape)

    Compares two TensorShape objects

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

    left object

    TensorShape b

    right object

    Returns
    Type Description
    Boolean

    true if contents of the objects a and b are not equal

    Extension Methods

    DeprecatedTensorExtensions.AdjustPadToPool(TensorShape, ValueTuple<Int32, Int32>, Int32[], Int32[])
    TensorExtensions.Scale(TensorShape, TensorShape)
    TensorExtensions.Scale(TensorShape, Int32[])
    TensorExtensions.Reduce(TensorShape, Int32)
    TensorExtensions.Reshape(TensorShape, Int32[])
    TensorExtensions.ApplyBorder(TensorShape, Int32[])
    TensorExtensions.Get8DPermutationsForNHWCPermutationsAndShape(TensorShape, Int32[])
    TensorExtensions.Permute(TensorShape, 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