Class ShapeUtils
This class contains utilities for useful calculations with shape.
Inherited Members
Namespace: Microsoft.ML.OnnxRuntime.Tensors
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public static class ShapeUtils
Methods
| Improve this Doc View SourceGetIndex(ReadOnlySpan<long>, ReadOnlySpan<long>, int)
Calculates the 1-d index for n-d indices in layout specified by strides.
Declaration
public static long GetIndex(ReadOnlySpan<long> strides, ReadOnlySpan<long> indices, int startFromDimension = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<long> | strides | pre-calculated strides |
| ReadOnlySpan<long> | indices | Indices. Must have the same length as strides |
| int | startFromDimension |
Returns
| Type | Description |
|---|---|
| long | A 1-d index into the tensor buffer |
GetSizeForShape(ReadOnlySpan<long>)
Returns a number of elements in the tensor from the given shape
Declaration
public static long GetSizeForShape(ReadOnlySpan<long> shape)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<long> | shape |
Returns
| Type | Description |
|---|---|
| long | size |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
GetStrides(ReadOnlySpan<long>)
Gets the set of strides that can be used to calculate the offset of n-dimensions in a 1-dimensional layout
Declaration
public static long[] GetStrides(ReadOnlySpan<long> dimensions)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<long> | dimensions |
Returns
| Type | Description |
|---|---|
| long[] | an array of strides |