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
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
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
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
channels
Return the number of channels.
Declaration
public readonly int channels
Field Value
height
Return the spatial height.
Declaration
public readonly int height
Field Value
width
Return the spatial width.
Declaration
public readonly int width
Field Value
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
flatHeight
Return the number of batch.
Declaration
public int flatHeight { get; }
Property Value
flatWidth
Declaration
public int flatWidth { get; }
Property Value
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
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
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
kernelHeight
Kernel dimension ordering is [H,W,C,K] for efficiency purpose.
Return kernel height.
Declaration
public int kernelHeight { get; }
Property Value
kernelWidth
Kernel dimension ordering is [H,W,C,K] for efficiency purpose.
Return kernel width.
Declaration
public int kernelWidth { get; }
Property Value
length
Return the total number of elements represented by this shape.
Declaration
public int length { get; }
Property Value
rank
Always 4, look also at the dimensions
property.
Declaration
Property Value
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
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
|
Returns
Overrides
Flatten()
Return a TensorShape of dimensions [N,1,1,HWC]
Declaration
public TensorShape Flatten()
Returns
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Overrides
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
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
Returns
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
Returns
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
Returns
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
Returns
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
ToArray()
Return an array representation of this tensorShape as [N,H,W,C]
Prefer tensorShape[x] to avoid GC allocation/collection.
Declaration
Returns
ToString()
Declaration
public override string ToString()
Returns
Overrides
Operators
Equality(TensorShape, TensorShape)
Declaration
public static bool operator ==(TensorShape a, TensorShape b)
Parameters
Returns
Inequality(TensorShape, TensorShape)
Declaration
public static bool operator !=(TensorShape a, TensorShape b)
Parameters
Returns
Extension Methods