docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct TensorShape

    Represents the shape of a tensor.

    Inherited Members
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetType()
    Namespace: Unity.Sentis
    Assembly: solution.dll
    Syntax
    [Serializable]
    public struct TensorShape

    Constructors

    Name Description
    TensorShape(ReadOnlySpan<int>)

    Initializes and returns an instance of TensorShape with a given shape. For example: TensorShape(new [] {3, 4, 5, 6}) returns a tensor with a shape of (3, 4, 5, 6).

    TensorShape(int)

    Initializes and returns an instance of TensorShape with a rank of 1: (d0).

    For example (9).

    TensorShape(int, int)

    Initializes and returns an instance of TensorShape with a rank of 2: (d1, d0).

    For example (8, 9).

    TensorShape(int, int, int)

    Initializes and returns an instance of TensorShape with a rank of 3: (d2, d1, d0).

    For example (7, 8, 9).

    TensorShape(int, int, int, int)

    Initializes and returns an instance of TensorShape with a rank of 4: (d3, d2, d1, d0).

    For example (6, 7, 8, 9).

    TensorShape(int, int, int, int, int)

    Initializes and returns an instance of TensorShape with a rank of 5: (d4, d3, d2, d1, d0).

    For example (5, 6, 7, 8, 9).

    TensorShape(int, int, int, int, int, int)

    Initializes and returns an instance of TensorShape with a rank of 6: (d5, d4, d3, d2, d1, d0).

    For example (4, 5, 6, 7, 8, 9).

    TensorShape(int, int, int, int, int, int, int)

    Initializes and returns an instance of TensorShape with a rank of 7: (d6, d5, d4, d3, d2, d1, d0).

    For example (3, 4, 5, 6, 7, 8, 9).

    TensorShape(int, int, int, int, int, int, int, int)

    Initializes and returns an instance of TensorShape with a rank of 8: (d7, d6, d5, d4, d3, d2, d1, d0).

    For example (2, 3, 4, 5, 6, 7, 8, 9).

    TensorShape(TensorShape)

    Returns a copy of another TensorShape.

    Fields

    Name Description
    maxRank

    The maximum rank a TensorShape can have.

    Properties

    Name Description
    this[int]

    Gets or sets the tensor shape at a given axis. A negative axis counts backwards from the inner dimension.

    length

    The number of elements represented by the TensorShape. For example a shape of (1, 2, 3, 4) represents 24 elements: 1 * 2 * 3 * 4.

    rank

    The rank of a TensorShape. For example, a tensor of shape (5) has a rank of 1. A tensor of shape (7, 3, 5) has a rank of 3.

    Methods

    Name Description
    Axis(int)

    Returns the positive axis corresponding to a given axis. Negative axes counts backwards from the inner dimension.

    Broadcast(TensorShape)

    Creates a TensorShape by applying numpy-style broadcasting between this and other.

    Sentis broadcasts shapes from innermost to outermost dimensions. Two dimensions are compatible when they're equal, or one of the dimensions is 1.

    BroadcastToRank(int)

    Creates a TensorShape of a given rank and with the same inner dimensions by adding outer dimensions of size 1 when needed.

    For example, if the TensorShape is (256, 256, 3), and the value of rank is 5, the method returns (1, 1, 256, 256, 3).

    Concat(TensorShape, int)

    Creates a TensorShape by concatenating this TensorShape with other along a given axis. The dimensions of the shapes must be equal, except at axis.

    For example if this is (2, 3, 4, 5), other is (2, 2, 4, 5), and the value of axis is 1, the method returns (2, 5, 4, 5).

    Equals(object)

    Determines whether the specified object is equal to the current TensorShape.

    Flatten(int)

    Creates a TensorShape by duplicating this and reshaping to a 2D matrix. The dimensions before axis are collapsed into the outer dimension and the remaining axes are collapsed into the inner dimension.

    For example, if this is (2, 3, 4), and the value of axis is 2, the method returns (2 * 3, 4).

    GetHashCode()

    Serves as the default hash function.

    HasZeroDims()

    Calculates whether any axes are length 0. In this case the length is also 0.

    Length(int)

    Returns the number of elements represented by the TensorShape, starting from a given axis. A negative axis counts backwards from the inner dimension.

    Length(int, int)

    Returns the number of elements represented by the TensorShape, between the start and end axes. Negative axes counts backwards from the inner dimension.

    MatMul(TensorShape)

    Creates a TensorShape that results from performing a matrix multiplication between this and other with numpy-style broadcasting. For example, if this is (5, 2, 3), and other is (1, 3, 4), the method returns (5, 2, 4).

    Ones(int)

    Creates a TensorShape with a given rank where all of the dimensions are 1. For example if rank is 3, the method returns (1, 1, 1).

    Pad(ReadOnlySpan<int>)

    Creates a TensorShape by padding axes. For example, if this is (1, 2, 3), and pads is {0, 0, 1, 0, 2, 2}, the method returns (1, 3, 7).

    RavelIndex(int, int)

    Converts the indexes of the TensorShape into a flat index.

    shape: (6,7) => 1 * (7) + 5 = 12

    index: (1,5)

    RavelIndex(int, int, int)

    Converts the indexes of the TensorShape into a flat index.

    shape: (5,6,7) => 2 * (6*7) + 1 * (7) + 5 = 96

    index: (2,1,5)

    RavelIndex(int, int, int, int)

    Converts the indexes of the TensorShape into a flat index.

    shape: (4,5,6,7) => 3 * (567) + 2 * (6*7) + 1 * (7) + 5 = 726

    index: (3,2,1,5)

    RavelIndex(int, int, int, int, int)

    Converts the indexes of the TensorShape into a flat index.

    shape: (3,4,5,6,7) => 0 * (4567) + 3 * (567) + 2 * (67) + 1 * (7) + 5 = 726

    index: (0,3,2,1,5)

    RavelIndex(int, int, int, int, int, int)

    Converts the indexes of the TensorShape into a flat index.

    shape: (2,3,4,5,6,7) => 1 * (34567) + 0 * (4567) + 3 * (567) + 2 * (67) + 1 * (7) + 5 = 3246

    index: (1,0,3,2,1,5)

    RavelIndex(int, int, int, int, int, int, int)

    Converts the indexes of the TensorShape into a flat index.

    shape: (1,2,3,4,5,6,7) => 0 * (234567) + 1 * (34567) + 0 * (4567) + 3 * (567) + 2 * (6*7) + 1 * (7) + 5 = 3246

    index: (0,1,0,3,2,1,5)

    RavelIndex(int, int, int, int, int, int, int, int)

    Converts the indexes of the TensorShape into a flat index.

    shape: (5,1,2,3,4,5,6,7) => 2 * (1234567) + 0 * (234567) + 1 * (34567) + 0 * (4567) + 3 * (567) + 2 * (6*7) + 1 * (7) + 5 = 13326

    index: (2,0,1,0,3,2,1,5)

    Reduce(ReadOnlySpan<int>, bool)

    Creates a TensorShape by removing the dimensions at axes. For example, if this is (2, 3, 4, 5), axis is {1, 2} and the value of keepDim is true, the method returns (2, 1, 1, 5).

    Reduce(int, bool)

    Removes a dimension at axis. For example, if this is (2, 3, 4, 5), the value of axis is 1, and the value of keepDim is true, the method returns (2, 1, 4, 5).

    Reshape(ReadOnlySpan<int>, bool)

    Creates a TensorShape by duplicating this and reshaping the dimensions to those given.

    If a dimension in the shape array is -1, Sentis infers the value from the size of the TensorShape and the remaining dimensions. Only one dimension can be -1.

    Slice(ReadOnlySpan<int>, ReadOnlySpan<int>, ReadOnlySpan<int>, ReadOnlySpan<int>)

    Creates a TensorShape that results from slicing this along given axes with given starts, ends, and steps.

    Squeeze()

    Creates a TensorShape by duplicating this and removing the dimensions of size 1. For example, if this is (5, 1, 3, 1), the method returns (5, 3).

    Squeeze(ReadOnlySpan<int>)

    Creates a TensorShape by duplicating this and removing the given axes of size 1. For example, if this is (5, 1, 3, 1), and axes is {1, -1}, the method returns (5, 3).

    Squeeze(int)

    Creates a TensorShape by duplicating this and removing the given axis of size 1. For example, if this is (5, 1, 3, 1), and axis is 1, the method returns (5, 3, 1).

    Strides(int)

    Returns the product of the dimensions of the tensor shape after a given axis. Negative axes counts backwards from the inner dimension.

    The strides of a tensor tell us how many elements we have to skip in flattened memory to move to the next position along a given index.

    Tile(ReadOnlySpan<int>)

    Creates a TensorShape by repeating this TensorShape a number of times along each axis.

    ToArray()

    Returns the TensorShape as an array of integers. For example if the TensorShape is (5, 2, 3, 4), the method returns new[] {5, 2, 3, 4}.

    ToString()

    Returns a string that represents the TensorShape.

    Transpose()

    Creates a TensorShape by reversing axes. For example, if this is (6, 7, 8, 9), the method returns (9, 8, 7, 6).

    Transpose(int[])

    Creates a TensorShape by permuting axes. For example, if this is (6, 7, 8, 9), and permutations is {3, 0, 1, 2}, the method returns (9, 6, 7, 8).

    Unsqueeze(ReadOnlySpan<int>)

    Creates a TensorShape by duplicating this and inserting a dimension of size one at a given axis. For example if this is (2), and the value of axis is 0, the method returns (1, 2).

    Unsqueeze(int)

    Creates a TensorShape by duplicating this and inserting a dimension of size one at a given axis. For example if this is (2), and the value of axis is 0, the method returns (1, 2).

    Operators

    Name Description
    operator ==(TensorShape, TensorShape)

    Compares two TensorShape objects. Returns true if the two objects have the same rank, and all their dimensions are equal.

    operator !=(TensorShape, TensorShape)

    Compares two TensorShape objects.

    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)