Movatterモバイル変換


[0]ホーム

URL:


Skip to main contentSkip to in-page navigation

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

Tensor<T> Class

Definition

Namespace:
System.Numerics.Tensors
Assembly:
System.Numerics.Tensors.dll
Package:
System.Numerics.Tensors v10.0.0-preview.6.25358.103
Source:
Tensor_1.cs
Source:
Tensor.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

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>
[System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]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>
[<System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]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>
Attributes
Implements

Properties

Empty

Gets an empty tensor.

FlattenedLength

The number of items in theTensor<T>.

HasAnyDenseDimensions

Determines if the current tensor has any dimension whereGetDimensionSpan(int) will iterate through tensors that would haveIsDense betrue.

IsDense

Determines if the current tensor is dense.

IsEmpty

Gets a value indicating whether thisTensor<T> is empty.

IsPinned

Gets a value indicating whether the backing memory of theTensor<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 thisTensor<T>.

Rank

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

Strides

Gets the strides of each dimension in thisTensor<T>.

Methods

AsReadOnlyTensorSpan()

Converts thisTensor<T> to aReadOnlyTensorSpan<T> pointing to the same backing memory."/>

AsReadOnlyTensorSpan(ReadOnlySpan<IntPtr>)

Converts thisTensor<T> to aReadOnlyTensorSpan<T> pointing to the same backing memory based on the provided start locations."/>

AsReadOnlyTensorSpan(ReadOnlySpan<NIndex>)

Converts thisTensor<T> to aReadOnlyTensorSpan<T> pointing to the same backing memory based on the provided start indexes."/>

AsReadOnlyTensorSpan(ReadOnlySpan<NRange>)

Converts thisTensor<T> to aReadOnlyTensorSpan<T> pointing to the same backing memory based on the provided ranges."/>

AsTensorSpan()

Converts thisTensor<T> to aTensorSpan<T> pointing to the same backing memory."/>

AsTensorSpan(ReadOnlySpan<IntPtr>)

Converts thisTensor<T> to aTensorSpan<T> pointing to the same backing memory based on the provided start locations."/>

AsTensorSpan(ReadOnlySpan<NIndex>)

Converts thisTensor<T> to aTensorSpan<T> pointing to the same backing memory based on the provided start indexes."/>

AsTensorSpan(ReadOnlySpan<NRange>)

Converts thisTensor<T> to aTensorSpan<T> pointing to the same backing memory based on the provided ranges."/>

Clear()

Clears the contents of this tensor.

CopyTo(TensorSpan<T>)

Copies the contents of the tensor into a destination tensor span.

Fill(T)

Fills the contents of this span with the given value.

FlattenTo(Span<T>)

Flattens the contents of this Tensor into the providedSpan<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 aMemoryHandle to the backing memory.

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(ReadOnlySpan<IntPtr>)

Creates aString representation of theTensorSpan<T>."/>

TryCopyTo(TensorSpan<T>)

Attempts to copy the contents of this tensor into a destination tensor span and returns a value to indicate whether or not the operation succeeded.

TryFlattenTo(Span<T>)

Flattens the contents of this Tensor into the providedSpan<T>.

Operators

Implicit(T[] to Tensor<T>)
Implicit(Tensor<T> to ReadOnlyTensorSpan<T>)
Implicit(Tensor<T> to TensorSpan<T>)

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Gets anIEnumerator for theTensor<T>."/>

IEnumerable<T>.GetEnumerator()

Gets anIEnumerator<T> for theTensor<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>.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>.Create(ReadOnlySpan<IntPtr>, Boolean)

Creates aTensor<T> and initializes it with the default value of T. Ifpinned is true, the memory will be pinned.

ITensor<Tensor<T>,T>.Create(ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>, Boolean)

Creates aTensor<T> and initializes it with the default value of T. Ifpinned is true, the memory will be pinned.

ITensor<Tensor<T>,T>.CreateUninitialized(ReadOnlySpan<IntPtr>, Boolean)

Creates aTensor<T> and does not initialize it. Ifpinned is true, the memory will be pinned.

ITensor<Tensor<T>,T>.CreateUninitialized(ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>, Boolean)

Creates aTensor<T> and does not initialize it. Ifpinned is true, the memory will be pinned.

Extension Methods

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

Creates aFrozenDictionary<TKey,TValue> from anIEnumerable<T> according to specified key selector function.

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

Creates aFrozenDictionary<TKey,TValue> from anIEnumerable<T> according to specified key selector and element selector functions.

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

Creates aFrozenSet<T> with the specified values.

ToImmutableArray<TSource>(IEnumerable<TSource>)

Creates an immutable array from the specified collection.

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.

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.

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.

ToAsyncEnumerable<TSource>(IEnumerable<TSource>)

Creates a newIAsyncEnumerable<T> that iterates throughsource.

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

Broadcast the data fromsource todestination.

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

Swaps the dimensions of thetensor tensor according to thedimensions parameter.Iftensor is a 1D tensor, it will returntensor. Otherwise it creates a newTensor<T>with the new axis ordering by allocating new memory.

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

Reshapes thetensor tensor to the specifiedlengths. 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 giventensor with the providedvalues for the givenranges

Squeeze<T>(Tensor<T>)

Removes all dimensions of length one from thetensor.

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

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

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

Creates aString representation of theTensor<T>."/>

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

Broadcast the data fromtensor to the smallest broadcastable shape compatible withdestination and stores it indestinationIf 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.

Applies to

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo