ReadOnlyTensorSpan<T> Constructors

Definition

Overloads

ReadOnlyTensorSpan<T>(Array)

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

ReadOnlyTensorSpan<T>(ReadOnlySpan<T>)

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

ReadOnlyTensorSpan<T>(T[])

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

ReadOnlyTensorSpan<T>(T*, IntPtr)

Creates a new span over the target unmanaged buffer.

ReadOnlyTensorSpan<T>(ReadOnlySpan<T>, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

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

ReadOnlyTensorSpan<T>(Array, ReadOnlySpan<NIndex>, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

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

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

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

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

Creates a new span over the target unmanaged buffer.

ReadOnlyTensorSpan<T>(T[], Index, 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).

ReadOnlyTensorSpan<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).

ReadOnlyTensorSpan<T>(Array)

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

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

C#
public ReadOnlyTensorSpan(Array? array);

Parameters

array
Array

The target array.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

ReadOnlyTensorSpan<T>(ReadOnlySpan<T>)

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

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

C#
public ReadOnlyTensorSpan(ReadOnlySpan<T> span);

Parameters

span
ReadOnlySpan<T>

The target span.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

ReadOnlyTensorSpan<T>(T[])

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

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

C#
public ReadOnlyTensorSpan(T[]? array);

Parameters

array
T[]

The target array.

Exceptions

array is covariant and its type is not exactly T[].

Remarks

Returns default when array is null.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

ReadOnlyTensorSpan<T>(T*, IntPtr)

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

Important

This API is not CLS-compliant.

Creates a new span over the target unmanaged buffer.

C#
[System.CLSCompliant(false)]
public ReadOnlyTensorSpan(T* data, IntPtr dataLength);

Parameters

data
T*

An unmanaged data that points to memory.

dataLength
IntPtr

The number of elements the unmanaged memory can hold.

Attributes

Remarks

This constructor is quite dangerous, because the length is not checked. But if this creation is correct, then all subsequent uses are correct.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

ReadOnlyTensorSpan<T>(ReadOnlySpan<T>, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

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

C#
public ReadOnlyTensorSpan(ReadOnlySpan<T> span, scoped ReadOnlySpan<IntPtr> lengths, scoped ReadOnlySpan<IntPtr> strides);

Parameters

span
ReadOnlySpan<T>

The target span.

lengths

ReadOnlySpan<IntPtr>

The lengths of each dimension.

strides

ReadOnlySpan<IntPtr>

The strides for each dimension. The strides will be automatically calculated if not provided.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

ReadOnlyTensorSpan<T>(Array, ReadOnlySpan<NIndex>, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

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

C#
public ReadOnlyTensorSpan(Array? array, scoped ReadOnlySpan<System.Buffers.NIndex> startIndex, scoped ReadOnlySpan<IntPtr> lengths, scoped ReadOnlySpan<IntPtr> strides);

Parameters

array
Array

The target array.

startIndex
ReadOnlySpan<NIndex>

The starting offset for each dimension.

lengths

ReadOnlySpan<IntPtr>

The lengths of each dimension.

strides

ReadOnlySpan<IntPtr>

The strides for each dimension. The strides will be automatically calculated if not provided.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

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

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

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

C#
public ReadOnlyTensorSpan(Array? array, scoped ReadOnlySpan<int> start, scoped ReadOnlySpan<IntPtr> lengths, scoped ReadOnlySpan<IntPtr> strides);

Parameters

array
Array

The target array.

start
ReadOnlySpan<Int32>

The starting offset for each dimension.

lengths

ReadOnlySpan<IntPtr>

The lengths of each dimension.

strides

ReadOnlySpan<IntPtr>

The strides for each dimension. This strides will be automatically calculated if not provided.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

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

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

Important

This API is not CLS-compliant.

Creates a new span over the target unmanaged buffer.

C#
[System.CLSCompliant(false)]
public ReadOnlyTensorSpan(T* data, IntPtr dataLength, scoped ReadOnlySpan<IntPtr> lengths, scoped ReadOnlySpan<IntPtr> strides);

Parameters

data
T*

An unmanaged data that points to memory.

dataLength
IntPtr

The number of elements the unmanaged memory can hold.

lengths

ReadOnlySpan<IntPtr>

The lengths of the dimensions. If default is provided, it's assumed to have one dimension with a length equal to the length of the data.

strides

ReadOnlySpan<IntPtr>

The lengths of the strides. If nothing is provided, it figures out the default stride configuration.

Attributes

Exceptions

T is a reference type or contains pointers and hence cannot be stored in unmanaged memory.

The specified length is negative.

Remarks

This constructor is quite dangerous, because the length is not checked. But if this creation is correct, then all subsequent uses are correct.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

ReadOnlyTensorSpan<T>(T[], Index, ReadOnlySpan<IntPtr>, ReadOnlySpan<IntPtr>)

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

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

C#
public ReadOnlyTensorSpan(T[]? array, Index startIndex, scoped ReadOnlySpan<IntPtr> lengths, scoped ReadOnlySpan<IntPtr> strides);

Parameters

array
T[]

The target array.

startIndex
Index

The index at which to begin the span.

lengths

ReadOnlySpan<IntPtr>

The lengths of the dimensions. If default is provided, it's assumed to have one dimension with a length equal to the length of the data.

strides

ReadOnlySpan<IntPtr>

The strides of each dimension. If default or span of length 0 is provided, then strides will be automatically calculated.

Exceptions

array is covariant and its type is not exactly T[].

The specified startIndex or end index is not in the range (<0 or >FlattenedLength).

Remarks

Returns default when array is null.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

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

Source:
ReadOnlyTensorSpan.cs
Source:
ReadOnlyTensorSpan.cs

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

C#
public ReadOnlyTensorSpan(T[]? array, int start, scoped ReadOnlySpan<IntPtr> lengths, scoped ReadOnlySpan<IntPtr> strides);

Parameters

array
T[]

The target array.

start
Int32

The index at which to begin the span.

lengths

ReadOnlySpan<IntPtr>

The lengths of the dimensions. If default is provided, it's assumed to have one dimension with a length equal to the length of the data.

strides

ReadOnlySpan<IntPtr>

The strides of each dimension. If default or span of length 0 is provided, then strides will be automatically calculated.

Exceptions

array is covariant and its type is not exactly T[].

Thrown when the specified start or end index is not in the range (<0 or >FlattenedLength).

Remarks

Returns default when array is null.

Applies to

.NET 10 (package-provided) 和其他版本
产品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)