Share via


Tensor<T> Class

Definition

Represents a tensor.

generic <typename T>
public ref class Tensor sealed : System::Collections::Generic::IEnumerable<T>, System::Numerics::Tensors::IReadOnlyTensor<System::Numerics::Tensors::Tensor<T> ^, T>, System::Numerics::Tensors::ITensor<System::Numerics::Tensors::Tensor<T> ^, T>
public sealed class Tensor<T> : System.Collections.Generic.IEnumerable<T>, System.Numerics.Tensors.IReadOnlyTensor<System.Numerics.Tensors.Tensor<T>,T>, System.Numerics.Tensors.ITensor<System.Numerics.Tensors.Tensor<T>,T>
type Tensor<'T> = class
    interface ITensor<Tensor<'T>, 'T>
    interface ITensor
    interface IReadOnlyTensor
    interface IReadOnlyTensor<Tensor<'T>, 'T>
    interface seq<'T>
    interface IEnumerable
Public NotInheritable Class Tensor(Of T)
Implements IEnumerable(Of T), IReadOnlyTensor(Of Tensor(Of T), T), ITensor(Of Tensor(Of T), T)

Type Parameters

T
Inheritance
Tensor<T>
Implements

Properties

Name Description
Empty

Gets an empty tensor.

FlattenedLength

The number of items in the Tensor<T>.

HasAnyDenseDimensions

Gets a value that indicates whether the current tensor has any dimension span where IsDense is true.

IsDense

Gets a value that indicates whether the current tensor is dense.

IsEmpty

Gets a value indicating whether this Tensor<T> is empty.

IsPinned

Gets a value indicating whether the backing memory of the Tensor<T> is pinned."/>

Item[ReadOnlySpan<IntPtr>]

Returns a reference to specified element of the Tensor.

Item[ReadOnlySpan<NIndex>]

Returns a reference to specified element of the Tensor.

Item[ReadOnlySpan<NRange>]

Returns a slice of the Tensor.

Lengths

Gets the length of each dimension in this Tensor<T>.

Rank

Gets a value indicating the rank, or number of dimensions, of this Tensor<T>.

Strides

Gets the strides of each dimension in this Tensor<T>.

Methods

Name Description
AsReadOnlyTensorSpan()

Converts this Tensor<T> to a ReadOnlyTensorSpan<T> pointing to the same backing memory."/>

AsReadOnlyTensorSpan(ReadOnlySpan<IntPtr>)

Converts this Tensor<T> to a ReadOnlyTensorSpan<T> pointing to the same backing memory based on the provided start locations."/>

AsReadOnlyTensorSpan(ReadOnlySpan<NIndex>)

Converts this Tensor<T> to a ReadOnlyTensorSpan<T> pointing to the same backing memory based on the provided start indexes."/>

AsReadOnlyTensorSpan(ReadOnlySpan<NRange>)

Converts this Tensor<T> to a ReadOnlyTensorSpan<T> pointing to the same backing memory based on the provided ranges."/>

AsTensorSpan()

Converts this Tensor<T> to a TensorSpan<T> pointing to the same backing memory."/>

AsTensorSpan(ReadOnlySpan<IntPtr>)

Converts this Tensor<T> to a TensorSpan<T> pointing to the same backing memory based on the provided start locations."/>

AsTensorSpan(ReadOnlySpan<NIndex>)

Converts this Tensor<T> to a TensorSpan<T> pointing to the same backing memory based on the provided start indexes."/>

AsTensorSpan(ReadOnlySpan<NRange>)

Converts this Tensor<T> to a TensorSpan<T> pointing to the same backing memory based on the provided ranges."/>

Clear()

Clears the contents of this tensor.

CopyTo(TensorSpan<T>)
Fill(T)

Fills the contents of this span with the given value.

FlattenTo(Span<T>)

Flattens the contents of this Tensor into the provided Span<T>.

GetDimensionSpan(Int32)

Returns a span that can be used to access the flattened elements for a given dimension.

GetEnumerator()

Gets an enumerator for the readonly tensor.

GetPinnableReference()

Returns a reference to the 0th element of the Tensor. If the Tensor is empty, returns null reference. It can be used for pinning and is required to support the use of Tensor within a fixed statement.

GetPinnedHandle()

Pins and gets a MemoryHandle to the backing memory.

GetSpan(ReadOnlySpan<IntPtr>, Int32)

Return a span that starts at the specified index and contains the specified number of items.

GetSpan(ReadOnlySpan<NIndex>, Int32)

Return a span that starts at the specified index and contains the specified number of items.

Slice(ReadOnlySpan<IntPtr>)

Forms a slice out of the given tensor

Slice(ReadOnlySpan<NIndex>)

Forms a slice out of the given tensor

Slice(ReadOnlySpan<NRange>)

Forms a slice out of the given tensor

ToDenseTensor()

Creates a dense tensor from the elements of the current tensor.

ToString()

Returns the string representation of the tensor.

ToString(ReadOnlySpan<IntPtr>)

Creates a String representation of the TensorSpan<T>."/>

TryCopyTo(TensorSpan<T>)
TryFlattenTo(Span<T>)

Flattens the contents of this Tensor into the provided Span<T>.

TryGetSpan(ReadOnlySpan<IntPtr>, Int32, ReadOnlySpan<T>)

Tries to return a span that starts at the specified index and contains the specified number of items.

TryGetSpan(ReadOnlySpan<IntPtr>, Int32, Span<T>)

Tries to return a span that starts at the specified index and contains the specified number of items.

TryGetSpan(ReadOnlySpan<NIndex>, Int32, ReadOnlySpan<T>)

Tries to return a span that starts at the specified index and contains the specified number of items.

TryGetSpan(ReadOnlySpan<NIndex>, Int32, Span<T>)

Tries to return a span that starts at the specified index and contains the specified number of items.

Operators

Name Description
Implicit(T[] to Tensor<T>)

Defines an implicit conversion of an array to a tensor.

Implicit(Tensor<T> to ReadOnlyTensorSpan<T>) System.Numerics.Tensors.TensorSpan`1.op_Implicit(System.Numerics.Tensors.TensorSpan{`0}@)~System.Numerics.Tensors.ReadOnlyTensorSpan{`0}
Implicit(Tensor<T> to TensorSpan<T>)

Defines an implicit conversion of a tensor to a tensor span.

Explicit Interface Implementations

Name Description
IEnumerable.GetEnumerator()

Gets an IEnumerator for the Tensor<T>."/>

IEnumerable<T>.GetEnumerator()

Gets an IEnumerator<T> for the Tensor<T>.

IReadOnlyTensor.Item[ReadOnlySpan<IntPtr>]
IReadOnlyTensor.Item[ReadOnlySpan<NIndex>]
IReadOnlyTensor<Tensor<T>,T>.CopyTo(TensorSpan<T>)
IReadOnlyTensor<Tensor<T>,T>.GetDimensionSpan(Int32)
IReadOnlyTensor<Tensor<T>,T>.GetPinnableReference()

Returns a reference to the 0th element of the ReadOnlyTensor. If the ReadOnlyTensor is empty, returns null reference. It can be used for pinning and is required to support the use of ReadOnlyTensor within a fixed statement.

IReadOnlyTensor<Tensor<T>,T>.GetSpan(ReadOnlySpan<IntPtr>, Int32)
IReadOnlyTensor<Tensor<T>,T>.GetSpan(ReadOnlySpan<NIndex>, Int32)
IReadOnlyTensor<Tensor<T>,T>.Item[ReadOnlySpan<IntPtr>]

Returns the specified element of the ReadOnlyTensor.

IReadOnlyTensor<Tensor<T>,T>.Item[ReadOnlySpan<NIndex>]

Returns the specified element of the ReadOnlyTensor.

IReadOnlyTensor<Tensor<T>,T>.TryCopyTo(TensorSpan<T>)
ITensor.Fill(Object)
ITensor.IsReadOnly
ITensor.Item[ReadOnlySpan<IntPtr>]
ITensor.Item[ReadOnlySpan<NIndex>]
ITensor<Tensor<T>,T>.CreateFromShape(ReadOnlySpan<IntPtr>, Boolean)
ITensor<Tensor<T>,T>.CreateFromShape(ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>, Boolean)
ITensor<Tensor<T>,T>.CreateFromShapeUninitialized(ReadOnlySpan<IntPtr>, Boolean)
ITensor<Tensor<T>,T>.CreateFromShapeUninitialized(ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>, Boolean)

Extension Methods

Name Description
BroadcastTo<T>(Tensor<T>, TensorSpan<T>)

Broadcast the data from source to destination.

PermuteDimensions<T>(Tensor<T>, ReadOnlySpan<Int32>)

Swaps the dimensions of the tensor tensor according to the dimensions parameter. If tensor is a 1D tensor, it will return tensor. Otherwise it creates a new Tensor<T> with the new axis ordering by allocating new memory.

Reshape<T>(Tensor<T>, ReadOnlySpan<IntPtr>)

Reshapes the tensor tensor to the specified lengths. If one of the lengths is -1, it will be calculated automatically. Does not change the length of the underlying memory nor does it allocate new memory. If the new shape is not compatible with the old shape, an exception is thrown.

SetSlice<T>(Tensor<T>, ReadOnlyTensorSpan<T>, ReadOnlySpan<NRange>)

Sets a slice of the given tensor with the provided values for the given ranges

Squeeze<T>(Tensor<T>)

Removes all dimensions of length one from the tensor.

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

Removes axis of length one from the tensor for the given dimension. If the dimension is not of length one it will throw an exception.

ToAsyncEnumerable<TSource>(IEnumerable<TSource>)

Creates a new IAsyncEnumerable<T> that iterates through source.

ToFrozenDictionary<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

Creates a FrozenDictionary<TKey,TValue> from an IEnumerable<T> according to specified key selector and element selector functions.

ToFrozenDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Creates a FrozenDictionary<TKey,TValue> from an IEnumerable<T> according to specified key selector function.

ToFrozenSet<T>(IEnumerable<T>, IEqualityComparer<T>)

Creates a FrozenSet<T> with the specified values.

ToImmutableArray<TSource>(IEnumerable<TSource>)

Creates an immutable array from the specified collection.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>, IEqualityComparer<TValue>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key and value comparers.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key comparer.

ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents.

ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Constructs an immutable dictionary based on some transformation of a sequence.

ToImmutableDictionary<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)

Constructs an immutable dictionary from an existing collection of elements, applying a transformation function to the source keys.

ToImmutableHashSet<TSource>(IEnumerable<TSource>, IEqualityComparer<TSource>)

Enumerates a sequence, produces an immutable hash set of its contents, and uses the specified equality comparer for the set type.

ToImmutableHashSet<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable hash set of its contents.

ToImmutableList<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable list of its contents.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>, IEqualityComparer<TValue>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key and value comparers.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>, IComparer<TKey>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents by using the specified key comparer.

ToImmutableSortedDictionary<TSource,TKey,TValue>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TValue>)

Enumerates and transforms a sequence, and produces an immutable sorted dictionary of its contents.

ToImmutableSortedSet<TSource>(IEnumerable<TSource>, IComparer<TSource>)

Enumerates a sequence, produces an immutable sorted set of its contents, and uses the specified comparer.

ToImmutableSortedSet<TSource>(IEnumerable<TSource>)

Enumerates a sequence and produces an immutable sorted set of its contents.

TryBroadcastTo<T>(Tensor<T>, TensorSpan<T>)

Broadcast the data from tensor to the smallest broadcastable shape compatible with destination and stores it in destination If the shapes are not compatible, false is returned.

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

Insert a new dimension of length 1 that will appear at the dimension position.

Extension Operators

Name Description
Addition(Tensor<TScalar>, Tensor<TScalar>)

Performs element-wise addition between two tensors.

Addition(Tensor<TScalar>, TScalar)

Performs element-wise addition between a tensor and scalar.

Addition(TScalar, Tensor<TScalar>)

Performs element-wise addition between a tensor and scalar.

AdditionAssignment(ReadOnlyTensorSpan<TScalar>)

Performs in-place element-wise addition between two tensors.

AdditionAssignment(TScalar)

Performs in-place element-wise addition between a tensor and scalar.

BitwiseAnd(Tensor<TScalar>, Tensor<TScalar>)

Performs bitwise-and between two tensors.

BitwiseAnd(Tensor<TScalar>, TScalar)

Performs bitwise-and between a tensor and scalar.

BitwiseAnd(TScalar, Tensor<TScalar>)

Performs bitwise-and between a tensor and scalar.

BitwiseAndAssignment(ReadOnlyTensorSpan<TScalar>)

Performs in-place bitwise-and between two tensors.

BitwiseAndAssignment(TScalar)

Performs in-place bitwise-and between a tensor and scalar.

BitwiseOr(Tensor<TScalar>, Tensor<TScalar>)

Performs bitwise-or between two tensors.

BitwiseOr(Tensor<TScalar>, TScalar)

Performs bitwise-or between a tensor and scalar.

BitwiseOr(TScalar, Tensor<TScalar>)

Performs bitwise-or between a tensor and scalar.

BitwiseOrAssignment(ReadOnlyTensorSpan<TScalar>)

Performs in-place bitwise-or between two tensors.

BitwiseOrAssignment(TScalar)

Performs in-place bitwise-or between a tensor and scalar.

DecrementAssignment

Performs in-place decrement on a tensor.

Division(Tensor<TScalar>, Tensor<TScalar>)

Performs element-wise division between two tensors.

Division(Tensor<TScalar>, TScalar)

Performs element-wise division between a tensor and scalar.

Division(TScalar, Tensor<TScalar>)

Performs element-wise division between a tensor and scalar.

DivisionAssignment(ReadOnlyTensorSpan<TScalar>)

Performs in-place element-wise division between two tensors.

DivisionAssignment(TScalar)

Performs in-place element-wise division between a tensor and scalar.

ExclusiveOr(Tensor<TScalar>, Tensor<TScalar>)

Performs exclusive-or between two tensors.

ExclusiveOr(Tensor<TScalar>, TScalar)

Performs exclusive-or between a tensor and scalar.

ExclusiveOr(TScalar, Tensor<TScalar>)

Performs exclusive-or between a tensor and scalar.

ExclusiveOrAssignment(ReadOnlyTensorSpan<TScalar>)

Performs in-place exclusive-or between two tensors.

ExclusiveOrAssignment(TScalar)

Performs in-place exclusive-or between a tensor and scalar.

IncrementAssignment

Performs in-place increment on a tensor.

LeftShift(Tensor<TScalar>, Int32)

Performs an element-wise left shift on a tensor.

LeftShiftAssignment(Int32)

Performs in-place element-wise left shift on a tensor.

MultiplicationAssignment(ReadOnlyTensorSpan<TScalar>)

Performs in-place element-wise multiplication between two tensors.

MultiplicationAssignment(TScalar)

Performs in-place element-wise multiplication between a tensor and scalar.

Multiply(Tensor<TScalar>, Tensor<TScalar>)

Performs element-wise multiplication between two tensors.

Multiply(Tensor<TScalar>, TScalar)

Performs element-wise multiplication between a tensor and scalar.

Multiply(TScalar, Tensor<TScalar>)

Performs element-wise multiplication between a tensor and scalar.

OnesComplement(Tensor<TScalar>)

Performs a one's complement on a tensor.

RightShift(Tensor<TScalar>, Int32)

Performs an element-wise left shift on a tensor.

RightShiftAssignment(Int32)

Performs in-place element-wise left shift on a tensor.

Subtraction(Tensor<TScalar>, Tensor<TScalar>)

Performs element-wise subtraction between two tensors.

Subtraction(Tensor<TScalar>, TScalar)

Performs element-wise subtraction between a tensor and scalar.

Subtraction(TScalar, Tensor<TScalar>)

Performs element-wise subtraction between a tensor and scalar.

SubtractionAssignment(ReadOnlyTensorSpan<TScalar>)

Performs in-place element-wise subtraction between two tensors.

SubtractionAssignment(TScalar)

Performs in-place element-wise subtraction between a tensor and scalar.

UnaryNegation(Tensor<TScalar>)

Performs element-wise unary negation on a tensor.

UnaryPlus(Tensor<TScalar>)

Performs element-wise unary plus on a tensor.

UnsignedRightShift(Tensor<TScalar>, Int32)

Performs an element-wise left shift on a tensor.

UnsignedRightShiftAssignment(Int32)

Performs in-place element-wise left shift on a tensor.

Applies to