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
Object
TensorBase
Tensor<T>
DenseTensor<T>
Implements
IList
ICollection
IList<T>
ICollection<T>
IReadOnlyList<T>
IReadOnlyCollection<T>
IEnumerable<T>
IEnumerable
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>.IEnumerable.GetEnumerator()
Tensor<T>.ICollection.Count
Tensor<T>.ICollection.IsSynchronized
Tensor<T>.ICollection.SyncRoot
Tensor<T>.ICollection.CopyTo(Array, Int32)
Tensor<T>.IList.Item[Int32]
Tensor<T>.IsFixedSize
Tensor<T>.IsReadOnly
Tensor<T>.IList.Add(Object)
Tensor<T>.IList.Clear()
Tensor<T>.IList.Contains(Object)
Tensor<T>.IList.IndexOf(Object)
Tensor<T>.IList.Insert(Int32, Object)
Tensor<T>.IList.Remove(Object)
Tensor<T>.IList.RemoveAt(Int32)
Tensor<T>.IEnumerable<T>.GetEnumerator()
Tensor<T>.ICollection<T>.Count
Tensor<T>.ICollection<T>.Add(T)
Tensor<T>.ICollection<T>.Clear()
Tensor<T>.ICollection<T>.Contains(T)
Tensor<T>.Contains(T)
Tensor<T>.ICollection<T>.CopyTo(T[], Int32)
Tensor<T>.ICollection<T>.Remove(T)
Tensor<T>.IReadOnlyCollection<T>.Count
Tensor<T>.IList<T>.Item[Int32]
Tensor<T>.IList<T>.IndexOf(T)
Tensor<T>.IList<T>.Insert(Int32, T)
Tensor<T>.IList<T>.RemoveAt(Int32)
Tensor<T>.IReadOnlyList<T>.Item[Int32]
Tensor<T>.IStructuralComparable.CompareTo(Object, IComparer)
Tensor<T>.IStructuralEquatable.Equals(Object, IEqualityComparer)
Tensor<T>.IStructuralEquatable.GetHashCode(IEqualityComparer)
Tensor<T>.ToDenseTensor()
Tensor<T>.GetArrayString(Boolean)
TensorBase.GetTypeInfo(Type)
TensorBase.GetElementTypeInfo(TensorElementType)
TensorBase.GetTypeInfo()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Microsoft.ML.OnnxRuntime.Tensors
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public class DenseTensor<T> : Tensor<T>, IList, ICollection, IList<T>, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IStructuralComparable, IStructuralEquatable
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 Source

DenseTensor(Int32)

Initializes a rank-1 Tensor using the specified length.

Declaration
public DenseTensor(int length)
Parameters
Type Name Description
Int32 length

Size of the 1-dimensional tensor

| Improve this Doc View Source

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<Int32> dimensions

An span of integers that represent the size of each dimension of the DenseTensor to create.

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.

| Improve this Doc View Source

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<Int32> dimensions

An span of integers that represent the size of each dimension of the DenseTensor to create.

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.

Properties

| Improve this Doc View Source

Buffer

Memory storing backing values of this tensor.

Declaration
public Memory<T> Buffer { get; }
Property Value
Type Description
Memory<T>

Methods

| Improve this Doc View Source

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()
| Improve this Doc View Source

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<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>(System.ReadOnlySpan<System.Int32>)
| Improve this Doc View Source

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

Int32 arrayIndex

start index

Overrides
Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.CopyTo(T[], System.Int32)
| Improve this Doc View Source

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
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)
| Improve this Doc View Source

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
Int32

The index of item if found in the tensor; otherwise, -1

Overrides
Microsoft.ML.OnnxRuntime.Tensors.Tensor<T>.IndexOf(T)
| Improve this Doc View Source

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<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(System.ReadOnlySpan<System.Int32>)
| Improve this Doc View Source

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

System.Collections.IList
System.Collections.ICollection
System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IReadOnlyList<T>
System.Collections.Generic.IReadOnlyCollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
System.Collections.IStructuralComparable
System.Collections.IStructuralEquatable
  • Improve this Doc
  • View Source
In This Article
Back to top