Condividi tramite


TensorSpan<T> Struct

Definition

Represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed or native memory, or to memory allocated on the stack. It is type-safe and memory-safe.

generic <typename T>
public value class TensorSpan
[System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public readonly ref struct TensorSpan<T>
[<System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type TensorSpan<'T> = struct
Public Structure TensorSpan(Of T)

Type Parameters

T
Inheritance
TensorSpan<T>
Attributes

Constructors

TensorSpan<T>(Array, ReadOnlySpan<Int32>, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

Creates a new TensorSpan<T> over the provided Array using the specified start offsets, lengths, and strides.

TensorSpan<T>(Array)

Creates a new TensorSpan<T> over the provided Array. The new TensorSpan<T> will have a rank of 1 and a length equal to the length of the provided Array.

TensorSpan<T>(Span<T>, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

Creates a new TensorSpan<T> over the provided Span<T> using the specified lengths and strides.

TensorSpan<T>(Span<T>, ReadOnlySpan<IntPtr>)

Creates a new tensor span over the target span using the specified lengths.

TensorSpan<T>(Span<T>)

Creates a new TensorSpan<T> over the provided Span<T>. The new TensorSpan<T> will have a rank of 1 and a length equal to the length of the provided Span<T>.

TensorSpan<T>(T[], Int32, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

Creates a new span over the portion of the target array beginning at 'start' index and ending at 'end' index (exclusive).

TensorSpan<T>(T[], ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

Creates a new tensor over the portion of the target array beginning at the specified start index and using the specified lengths and strides.

TensorSpan<T>(T[], ReadOnlySpan<IntPtr>)

Creates a new tensor over the portion of the target array using the specified lengths.

TensorSpan<T>(T[])

Creates a new span over the entirety of the target array.

TensorSpan<T>(T*, IntPtr, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

Creates a new span over the target unmanaged buffer.

TensorSpan<T>(T*, IntPtr, ReadOnlySpan<IntPtr>)

Creates a new tensor span over the target unmanaged buffer using the specified lengths.

TensorSpan<T>(T*, IntPtr)

Creates a new span over the target unmanaged buffer.

Properties

Empty

Returns an empty TensorSpan<T>

FlattenedLength

The number of items in the span.

IsEmpty

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

Item[ReadOnlySpan<IntPtr>]

Returns a reference to specified element of the TensorSpan.

Item[ReadOnlySpan<NIndex>]

Returns a reference to specified element of the TensorSpan.

Item[ReadOnlySpan<NRange>]

Returns a slice of the TensorSpan.

Lengths

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

Rank

Gets the rank, aka the number of dimensions, of this TensorSpan<T>.

Strides

Gets the strides of this TensorSpan<T>

Methods

AsReadOnlyTensorSpan()

Creates a new readonly tensor span over the tensor.

AsReadOnlyTensorSpan(ReadOnlySpan<IntPtr>)

Creates a new readonly tensor span over a portion of the tensor starting at a specified position to the end of the tensor.

AsReadOnlyTensorSpan(ReadOnlySpan<NIndex>)

Creates a read-only tensor span for the specified start indexes.

AsReadOnlyTensorSpan(ReadOnlySpan<NRange>)

Creates a new readonly tensor span over a portion of the tensor defined by the specified range.

Clear()

Clears the contents of this span.

CopyTo(TensorSpan<T>)

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

Equals(Object)
Obsolete.

This method is not supported as spans cannot be boxed. To compare two spans, use operator ==.

Fill(T)

Fills the contents of this span with the given value.

FlattenTo(Span<T>)

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

GetEnumerator()

Gets an enumerator for the tensor span.

GetHashCode()
Obsolete.

This method is not supported as spans cannot be boxed.

GetPinnableReference()

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

Slice(ReadOnlySpan<IntPtr>)

Forms a slice out of the current tensor that begins at a specified index.

Slice(ReadOnlySpan<NIndex>)

Returns a reference to specified element of the TensorSpan.

Slice(ReadOnlySpan<NRange>)

Forms a slice out of the given span.

ToString()

For Span<T>, returns a new instance of string that represents the characters pointed to by the span. Otherwise, returns a String with the name of the type and the number of elements.

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 span into the provided Span<T>.

Operators

Equality(TensorSpan<T>, TensorSpan<T>)

Returns a value that indicates whether two tensor spans are equal.

Implicit(T[] to TensorSpan<T>)
Implicit(TensorSpan<T> to ReadOnlyTensorSpan<T>)
Inequality(TensorSpan<T>, TensorSpan<T>)

Returns a value that indicates whether two tensor spans are not equal.

Extension Methods

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

Broadcast the data from source to destination.

FilteredUpdate<T>(TensorSpan<T>, ReadOnlyTensorSpan<Boolean>, T)

Updates the tensor tensor with the value where the filter is true.

FilteredUpdate<T>(TensorSpan<T>, ReadOnlyTensorSpan<Boolean>, ReadOnlyTensorSpan<T>)

Updates the tensor tensor with the values where the filter is true. If dimensions are not the same an exception is thrown.

Reshape<T>(TensorSpan<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.

SequenceEqual<T>(TensorSpan<T>, ReadOnlyTensorSpan<T>)

Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T).

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

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

Squeeze<T>(TensorSpan<T>)

Removes all dimensions of length one from the tensor.

SqueezeDimension<T>(TensorSpan<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.

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

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

TryBroadcastTo<T>(TensorSpan<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>(TensorSpan<T>, Int32)

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

Applies to