Show / Hide Table of Contents

Class Tensor

Various methods for creating and manipulating Tensor<T>

Inheritance
Object
Tensor
Inherited Members
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 static class Tensor

Methods

| Improve this Doc View Source

CreateFromDiagonal<T>(Tensor<T>)

Creates a n+1-rank tensor using the specified n-rank diagonal. Values not on the diagonal will be filled with zeros.

Declaration
public static Tensor<T> CreateFromDiagonal<T>(Tensor<T> diagonal)
Parameters
Type Name Description
Tensor<T> diagonal

Tensor representing the diagonal to build the new tensor from.

Returns
Type Description
Tensor<T>

A new tensor of the same layout and order as diagonal of one higher rank, with the values of diagonal along the diagonal and zeros elsewhere.

Type Parameters
Name Description
T

type contained within the Tensor. Typically a value type such as int, double, float, etc.

| Improve this Doc View Source

CreateFromDiagonal<T>(Tensor<T>, Int32)

Creates a n+1-dimension tensor using the specified n-dimension diagonal at the specified offset from the center. Values not on the diagonal will be filled with zeros.

Declaration
public static Tensor<T> CreateFromDiagonal<T>(Tensor<T> diagonal, int offset)
Parameters
Type Name Description
Tensor<T> diagonal

Tensor representing the diagonal to build the new tensor from.

Int32 offset

Offset of diagonal to set in returned tensor. 0 for the main diagonal, less than zero for diagonals below, greater than zero from diagonals above.

Returns
Type Description
Tensor<T>

A new tensor of the same layout and order as diagonal of one higher rank, with the values of diagonal along the specified diagonal and zeros elsewhere.

Type Parameters
Name Description
T

type contained within the Tensor. Typically a value type such as int, double, float, etc.

| Improve this Doc View Source

CreateIdentity<T>(Int32)

Creates an identity tensor of the specified size. An identity tensor is a two dimensional tensor with 1s in the diagonal.

Declaration
public static Tensor<T> CreateIdentity<T>(int size)
Parameters
Type Name Description
Int32 size

Width and height of the identity tensor to create.

Returns
Type Description
Tensor<T>

a size by size with 1s along the diagonal and zeros elsewhere.

Type Parameters
Name Description
T

type contained within the Tensor. Typically a value type such as int, double, float, etc.

| Improve this Doc View Source

CreateIdentity<T>(Int32, Boolean)

Creates an identity tensor of the specified size and layout (row vs column major). An identity tensor is a two dimensional tensor with 1s in the diagonal.

Declaration
public static Tensor<T> CreateIdentity<T>(int size, bool columMajor)
Parameters
Type Name Description
Int32 size

Width and height of the identity tensor to create.

Boolean columMajor

False to indicate that the first dimension is most minor (closest) and the last dimension is most major (farthest): row-major. True to indicate that the last dimension is most minor (closest together) and the first dimension is most major (farthest apart): column-major.

Returns
Type Description
Tensor<T>

a size by size with 1s along the diagonal and zeros elsewhere.

Type Parameters
Name Description
T

type contained within the Tensor. Typically a value type such as int, double, float, etc.

| Improve this Doc View Source

CreateIdentity<T>(Int32, Boolean, T)

Creates an identity tensor of the specified size and layout (row vs column major) using the specified one value. An identity tensor is a two dimensional tensor with 1s in the diagonal. This may be used in case T is a type that doesn't have a known 1 value.

Declaration
public static Tensor<T> CreateIdentity<T>(int size, bool columMajor, T oneValue)
Parameters
Type Name Description
Int32 size

Width and height of the identity tensor to create.

Boolean columMajor

False to indicate that the first dimension is most minor (closest) and the last dimension is most major (farthest): row-major. True to indicate that the last dimension is most minor (closest together) and the first dimension is most major (farthest apart): column-major.

T oneValue

Value of T that is used along the diagonal.

Returns
Type Description
Tensor<T>

a size by size with 1s along the diagonal and zeros elsewhere.

Type Parameters
Name Description
T

type contained within the Tensor. Typically a value type such as int, double, float, etc.

  • Improve this Doc
  • View Source
In This Article
Back to top