Show / Hide Table of Contents

# 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.

##### Inheritance

System.Object
TensorBase
Tensor<T>
DenseTensor<T>

##### Implements

IList
IList<T>
IReadOnlyList<T>
IStructuralComparable
IStructuralEquatable

##### Inherited Members

Tensor<T>.Length
Tensor<T>.Rank
Tensor<T>.IsReversedStride
Tensor<T>.Dimensions
Tensor<T>.Strides
Tensor<T>.Fill(T)
Tensor<T>.CloneEmpty()
Tensor<T>.CloneEmpty(ReadOnlySpan<Int32>)
Tensor<T>.CloneEmpty<TResult>()
Tensor<T>.GetDiagonal()
Tensor<T>.GetDiagonal(Int32)
Tensor<T>.GetTriangle()
Tensor<T>.GetTriangle(Int32)
Tensor<T>.GetUpperTriangle()
Tensor<T>.GetUpperTriangle(Int32)
Tensor<T>.GetTriangle(Int32, Boolean)
Tensor<T>.Item[Int32[]]
Tensor<T>.Item[ReadOnlySpan<Int32>]
Tensor<T>.Compare(Tensor<T>, Tensor<T>)
Tensor<T>.Equals(Tensor<T>, Tensor<T>)
Tensor<T>.IsFixedSize
Tensor<T>.IsReadOnly
Tensor<T>.Contains(T)
Tensor<T>.ToDenseTensor()
Tensor<T>.GetArrayString(Boolean)
TensorBase.GetTypeInfo(Type)
TensorBase.GetElementTypeInfo(TensorElementType)
TensorBase.GetTypeInfo()
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()

###### Namespace: Microsoft.ML.OnnxRuntime.Tensors

###### Assembly: cs.temp.dll.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

#### DenseTensor(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. True to indicate that the last dimension is most major (farthest apart) and the first dimension is most minor (closest together): akin to column-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. True to indicate that the last dimension is most major (farthest apart) and the first dimension is most minor (closest together): akin to column-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

#### Buffer

Memory storing backing values of this tensor.

##### Declaration

    public Memory<T> Buffer { get; }

##### Property Value

Type | Description
--- | ---
Memory<T> |

### Methods

#### Clone()

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

Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.Clone()

#### 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

Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.CloneEmpty<TResult>(ReadOnlySpan<System.Int32>)

#### 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

Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.CopyTo(T[], System.Int32)

#### 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

Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.GetValue(System.Int32)

#### 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

Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.IndexOf(T)

#### 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

Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.Reshape(ReadOnlySpan<System.Int32>)

#### 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.

##### Overrides

Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.SetValue(System.Int32, T)

### Implements

IList
IList<>
IReadOnlyList<>
IStructuralComparable
IStructuralEquatable