Struct TensorShape
Represents the shape of a tensor.
Inherited Members
Namespace: Unity.Sentis
Syntax
[Serializable]
public struct TensorShape
Constructors
TensorShape(Int32)
Initializes and returns an instance of TensorShape with a rank of 1: (d0).
For example (9).
Declaration
public TensorShape(int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d0 |
TensorShape(Int32, Int32)
Initializes and returns an instance of TensorShape with a rank of 2: (d1, d0).
For example (8, 9).
Declaration
public TensorShape(int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d1 | |
| Int32 | d0 |
TensorShape(Int32, Int32, Int32)
Initializes and returns an instance of TensorShape with a rank of 3: (d2, d1, d0).
For example (7, 8, 9).
Declaration
public TensorShape(int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
TensorShape(Int32, Int32, Int32, Int32)
Initializes and returns an instance of TensorShape with a rank of 4: (d3, d2, d1, d0).
For example (6, 7, 8, 9).
Declaration
public TensorShape(int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
TensorShape(Int32, Int32, Int32, Int32, Int32)
Initializes and returns an instance of TensorShape with a rank of 5: (d4, d3, d2, d1, d0).
For example (5, 6, 7, 8, 9).
Declaration
public TensorShape(int d4, int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d4 | |
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
TensorShape(Int32, Int32, Int32, Int32, Int32, Int32)
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).
Declaration
public TensorShape(int d5, int d4, int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d5 | |
| Int32 | d4 | |
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
TensorShape(Int32, Int32, Int32, Int32, Int32, Int32, Int32)
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).
Declaration
public TensorShape(int d6, int d5, int d4, int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d6 | |
| Int32 | d5 | |
| Int32 | d4 | |
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
TensorShape(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)
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).
Declaration
public TensorShape(int d7, int d6, int d5, int d4, int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d7 | |
| Int32 | d6 | |
| Int32 | d5 | |
| Int32 | d4 | |
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
TensorShape(Int32[])
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).
Declaration
public TensorShape(int[] shape)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | shape |
TensorShape(TensorShape)
Returns a copy of another TensorShape.
Declaration
public TensorShape(TensorShape shape)
Parameters
| Type | Name | Description |
|---|---|---|
| TensorShape | shape |
Fields
maxRank
The maximum rank a TensorShape can have.
Declaration
public const int maxRank = 8
Field Value
| Type | Description |
|---|---|
| Int32 |
Properties
Item[Int32]
Gets or sets the tensor shape at a given axis. A negative axis counts backwards from the inner dimension.
Declaration
public int this[int axis] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis |
Property Value
| Type | Description |
|---|---|
| Int32 |
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.
Declaration
public readonly int length { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
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.
Declaration
public readonly int rank { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Methods
Axis(Int32)
Returns the positive axis corresponding to a given axis. Negative axes counts backwards from the inner dimension.
Declaration
public int Axis(int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis |
Returns
| Type | Description |
|---|---|
| Int32 |
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.
Declaration
public TensorShape Broadcast(TensorShape other)
Parameters
| Type | Name | Description |
|---|---|---|
| TensorShape | other |
Returns
| Type | Description |
|---|---|
| TensorShape |
BroadcastToRank(Int32)
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).
Declaration
public TensorShape BroadcastToRank(int rank)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | rank |
Returns
| Type | Description |
|---|---|
| TensorShape |
Concat(TensorShape, Int32)
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).
Declaration
public TensorShape Concat(TensorShape other, int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| TensorShape | other | |
| Int32 | axis |
Returns
| Type | Description |
|---|---|
| TensorShape |
Equals(Object)
Determines whether the specified object is equal to the current TensorShape.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj |
Returns
| Type | Description |
|---|---|
| Boolean |
Overrides
Flatten(Int32)
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).
Declaration
public TensorShape Flatten(int axis = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis |
Returns
| Type | Description |
|---|---|
| TensorShape |
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 |
Overrides
HasZeroDims()
Whether any axes are size 0. In this case the length is also 0.
Declaration
public bool HasZeroDims()
Returns
| Type | Description |
|---|---|
| Boolean |
Length(Int32)
Returns the number of elements represented by the TensorShape, starting from a given axis. A negative axis counts backwards from the inner dimension.
Declaration
public int Length(int start)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | start |
Returns
| Type | Description |
|---|---|
| Int32 |
Length(Int32, Int32)
Returns the number of elements represented by the TensorShape, between the start and end axes. Negative axes counts backwards from the inner dimension.
Declaration
public int Length(int start, int end)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | start | |
| Int32 | end |
Returns
| Type | Description |
|---|---|
| Int32 |
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).
Declaration
public TensorShape MatMul(TensorShape other)
Parameters
| Type | Name | Description |
|---|---|---|
| TensorShape | other |
Returns
| Type | Description |
|---|---|
| TensorShape |
Ones(Int32)
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).
Declaration
public static TensorShape Ones(int rank)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | rank |
Returns
| Type | Description |
|---|---|
| TensorShape |
Pad(Int32[])
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).
Declaration
public TensorShape Pad(int[] pads)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | pads | The lower and upper padding values for each dimension. For example [pad_left, pad_right] for 1D, or [pad_top, pad_bottom, pad_left, pad_right] for 2D. |
Returns
| Type | Description |
|---|---|
| TensorShape |
RavelIndex(Int32, Int32)
Converts the indexes of the TensorShape into a flat index.
shape: (6,7) => 1 * (7) + 5 = 12
index: (1,5)
Declaration
public int RavelIndex(int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d1 | |
| Int32 | d0 |
Returns
| Type | Description |
|---|---|
| Int32 |
RavelIndex(Int32, Int32, Int32)
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)
Declaration
public int RavelIndex(int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
Returns
| Type | Description |
|---|---|
| Int32 |
RavelIndex(Int32, Int32, Int32, Int32)
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)
Declaration
public int RavelIndex(int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
Returns
| Type | Description |
|---|---|
| Int32 |
RavelIndex(Int32, Int32, Int32, Int32, Int32)
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)
Declaration
public int RavelIndex(int d4, int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d4 | |
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
Returns
| Type | Description |
|---|---|
| Int32 |
RavelIndex(Int32, Int32, Int32, Int32, Int32, Int32)
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)
Declaration
public int RavelIndex(int d5, int d4, int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d5 | |
| Int32 | d4 | |
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
Returns
| Type | Description |
|---|---|
| Int32 |
RavelIndex(Int32, Int32, Int32, Int32, Int32, Int32, Int32)
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)
Declaration
public int RavelIndex(int d6, int d5, int d4, int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d6 | |
| Int32 | d5 | |
| Int32 | d4 | |
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
Returns
| Type | Description |
|---|---|
| Int32 |
RavelIndex(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)
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)
Declaration
public int RavelIndex(int d7, int d6, int d5, int d4, int d3, int d2, int d1, int d0)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | d7 | |
| Int32 | d6 | |
| Int32 | d5 | |
| Int32 | d4 | |
| Int32 | d3 | |
| Int32 | d2 | |
| Int32 | d1 | |
| Int32 | d0 |
Returns
| Type | Description |
|---|---|
| Int32 |
Reduce(Int32, Boolean)
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).
Declaration
public TensorShape Reduce(int axis, bool keepDim = true)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis | |
| Boolean | keepDim | When the value is |
Returns
| Type | Description |
|---|---|
| TensorShape |
Reduce(Int32[], Boolean)
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).
Declaration
public TensorShape Reduce(int[] axes, bool keepDim = true)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | axes | |
| Boolean | keepDim | When the value is |
Returns
| Type | Description |
|---|---|
| TensorShape |
Reshape(Int32[], Boolean)
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.
Declaration
public TensorShape Reshape(int[] shape, bool allowZero = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | shape | |
| Boolean | allowZero | When the value is |
Returns
| Type | Description |
|---|---|
| TensorShape |
Slice(Int32[], Int32[], Int32[], Int32[])
Creates a TensorShape that results from slicing this along given axes with given starts, ends, and steps.
Declaration
public TensorShape Slice(int[] starts, int[] ends, int[] axes, int[] steps)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | starts | |
| Int32[] | ends | |
| Int32[] | axes | |
| Int32[] | steps |
Returns
| Type | Description |
|---|---|
| TensorShape |
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).
Declaration
public TensorShape Squeeze()
Returns
| Type | Description |
|---|---|
| TensorShape |
Squeeze(Int32)
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).
Declaration
public TensorShape Squeeze(int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis |
Returns
| Type | Description |
|---|---|
| TensorShape |
Squeeze(Int32[])
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).
Declaration
public TensorShape Squeeze(int[] axes)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | axes |
Returns
| Type | Description |
|---|---|
| TensorShape |
Strides(Int32)
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.
Declaration
public int Strides(int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis |
Returns
| Type | Description |
|---|---|
| Int32 |
Tile(Int32[])
Creates a TensorShape by repeating this TensorShape a number of times along each axis.
Declaration
public TensorShape Tile(int[] repeats)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | repeats |
Returns
| Type | Description |
|---|---|
| TensorShape |
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}.
Declaration
public int[] ToArray()
Returns
| Type | Description |
|---|---|
| Int32[] |
ToString()
Returns a string that represents the TensorShape.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String |
Overrides
Transpose()
Creates a TensorShape by reversing axes. For example, if this is (6, 7, 8, 9), the method returns (9, 8, 7, 6).
Declaration
public TensorShape Transpose()
Returns
| Type | Description |
|---|---|
| TensorShape |
Transpose(Int32[])
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).
Declaration
public TensorShape Transpose(int[] permutations)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | permutations |
Returns
| Type | Description |
|---|---|
| TensorShape |
Unsqueeze(Int32)
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).
Declaration
public TensorShape Unsqueeze(int axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | axis |
Returns
| Type | Description |
|---|---|
| TensorShape |
Unsqueeze(Int32[])
Creates a TensorShape by duplicating this and inserting dimensions of size one at the given axes. For example if this is (2), and axes is {0, 1}, the method returns (1, 1, 2).
Declaration
public TensorShape Unsqueeze(int[] axes)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32[] | axes |
Returns
| Type | Description |
|---|---|
| TensorShape |
Operators
Equality(TensorShape, TensorShape)
Compares two TensorShape objects. Returns true if the two objects have the same rank, and all their dimensions are equal.
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 |