Class DenseTensor<T>
Represents a multi-dimensional collection of objects of type T that can be accessed by indices.
DenseTensor stores values in a contiguous sequential block of memory where all values are represented.
Implements
Inherited Members
Namespace: Microsoft.ML.OnnxRuntime.Tensors
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public class DenseTensor<T> : Tensor<T>
Type Parameters
Name | Description |
---|---|
T | Type contained within the Tensor. Typically a value type such as int, double, float, etc. |
Constructors
| Improve this Doc View SourceDenseTensor(Memory<T>, ReadOnlySpan<Int32>, Boolean)
Constructs a new DenseTensor of the specified dimensions, wrapping existing backing memory for the contents.
Declaration
public DenseTensor(Memory<T> memory, ReadOnlySpan<int> dimensions, bool reverseStride = false)
Parameters
Type | Name | Description |
---|---|---|
Memory<><T> | memory | |
ReadOnlySpan<><System.Int32> | dimensions | An span of integers that represent the size of each dimension of the DenseTensor to create. |
System.Boolean | reverseStride | False (default) to indicate that the first dimension is most major (farthest apart) and the last dimension
is most minor (closest together): akin to row-major in a rank-2 tensor. |
DenseTensor(ReadOnlySpan<Int32>, Boolean)
Initializes a rank-n Tensor using the dimensions specified in dimensions
.
Declaration
public DenseTensor(ReadOnlySpan<int> dimensions, bool reverseStride = false)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<><System.Int32> | dimensions | An span of integers that represent the size of each dimension of the DenseTensor to create. |
System.Boolean | reverseStride | False (default) to indicate that the first dimension is most major (farthest apart) and the last dimension
is most minor (closest together): akin to row-major in a rank-2 tensor. |
DenseTensor(Int32)
Initializes a rank-1 Tensor using the specified length
.
Declaration
public DenseTensor(int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | length | Size of the 1-dimensional tensor |
Properties
| Improve this Doc View SourceBuffer
Memory storing backing values of this tensor.
Declaration
public Memory<T> Buffer { get; }
Property Value
Type | Description |
---|---|
Memory<><T> |
Methods
| Improve this Doc View SourceClone()
Creates a shallow copy of this tensor, with new backing storage.
Declaration
public override Tensor<T> Clone()
Returns
Type | Description |
---|---|
Tensor<T> | A shallow copy of this tensor. |
Overrides
CloneEmpty<TResult>(ReadOnlySpan<Int32>)
Creates a new Tensor of a different type with the specified dimensions and the same layout as this tensor with elements initialized to their default value.
Declaration
public override Tensor<TResult> CloneEmpty<TResult>(ReadOnlySpan<int> dimensions)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<><System.Int32> | dimensions | An span of integers that represent the size of each dimension of the DenseTensor to create. |
Returns
Type | Description |
---|---|
Tensor<TResult> | A new tensor with the same layout as this tensor but different type and dimensions. |
Type Parameters
Name | Description |
---|---|
TResult | Type contained in the returned Tensor. |
Overrides
CopyTo(T[], Int32)
Overrides Tensor.CopyTo(). Copies the content of the Tensor to the specified array starting with arrayIndex
Declaration
protected override void CopyTo(T[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | destination array |
System.Int32 | arrayIndex | start index |
Overrides
GetValue(Int32)
Gets the value at the specified index, where index is a linearized version of n-dimension indices using strides. For a scalar, use index = 0
Declaration
public override T GetValue(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | An integer index computed as a dot-product of indices. |
Returns
Type | Description |
---|---|
T | The value at the specified position in this Tensor. |
Overrides
IndexOf(T)
Determines the index of a specific item in the Tensor<T>.
Declaration
protected override int IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Object to locate |
Returns
Type | Description |
---|---|
System.Int32 | The index of item if found in the tensor; otherwise, -1 |
Overrides
Reshape(ReadOnlySpan<Int32>)
Reshapes the current tensor to new dimensions, using the same backing storage.
Declaration
public override Tensor<T> Reshape(ReadOnlySpan<int> dimensions)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<><System.Int32> | dimensions | An span of integers that represent the size of each dimension of the DenseTensor to create. |
Returns
Type | Description |
---|---|
Tensor<T> | A new tensor that reinterprets backing Buffer of this tensor with different dimensions. |
Overrides
SetValue(Int32, T)
Sets the value at the specified index, where index is a linearized version of n-dimension indices using strides. For a scalar, use index = 0
Declaration
public override void SetValue(int index, T value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | An integer index computed as a dot-product of indices. |
T | value | The new value to set at the specified position in this Tensor. |