Table of Contents

Struct NDArray._Unsafe

Namespace
NumSharp
Assembly
NumSharp.dll
public readonly struct NDArray._Unsafe
Inherited Members

Properties

Address

Returns the memory address to the start of this block of memory.

public void* Address { get; }

Property Value

void*

Exceptions

InvalidOperationException

When this NDArray is a slice.

BytesLength

How many bytes are stored in this memory block.

public long BytesLength { get; }

Property Value

long

Remarks

Calculated by Count*ItemLength

Count

How many items are stored in Address.

public long Count { get; }

Property Value

long

Remarks

Not to confuse with BytesLength

ItemLength

The size of a single item stored in Address.

public int ItemLength { get; }

Property Value

int

Remarks

Equivalent to NPTypeCode.SizeOf extension.

Pin

Provides the ability to return a pin to the memory address of NDArray.

public NDArray._Unsafe._Pinning Pin { get; }

Property Value

NDArray._Unsafe._Pinning

Remarks

Possible only when the ndarray is not sliced.

Storage

Provides access to the internal UnmanagedStorage.

public UnmanagedStorage Storage { get; }

Property Value

UnmanagedStorage

Methods

AsSpan<T>()

Returns an UnmanagedSpan representing this NDArray's memory.

public UnmanagedSpan<T> AsSpan<T>() where T : unmanaged

Returns

UnmanagedSpan<T>

Type Parameters

T

Remarks

Does not perform copy. Supports long indexing for arrays > 2B elements.

Bytes()

A Span<byte> over the raw bytes of the array's logical C-order window (size * itemsize bytes), dtype-agnostic — useful for serialization or bit-level reinterpretation. Unsafe and C-contiguous, ≤ MaxValue bytes.

public Span<byte> Bytes()

Returns

Span<byte>

Fill(object)

Fills all indexes with value.

public void Fill(object value)

Parameters

value object

GetIndex(long)

public object GetIndex(long index)

Parameters

index long

Returns

object

GetIndex<T>(long)

public T GetIndex<T>(long index) where T : unmanaged

Parameters

index long

Returns

T

Type Parameters

T

GetPinnableReference()

public ref byte GetPinnableReference()

Returns

byte

Exceptions

InvalidOperationException

When this NDArray is a slice.

GetPinnableReference<T>()

Gets pinnable reference of the first item in the memory block storage.

public ref T GetPinnableReference<T>() where T : unmanaged

Returns

T

Type Parameters

T

Memory<T>()

A Memory<T> aliasing the array's logical C-order elements, backed by an UnmanagedMemoryManager<T>. Unsafe: the manager holds only a raw pointer, so the returned Memory keeps the manager alive but NOT the NDArray — keep the NDArray alive for the Memory's whole lifetime. Requires a C-contiguous array of the exact dtype, ≤ MaxValue elements. Allocates the manager (one small object); the buffer is not copied.

public Memory<T> Memory<T>() where T : unmanaged

Returns

Memory<T>

Type Parameters

T

Pointer<T>()

A raw T* pointer to the array's logical element 0, valid for ANY layout (contiguous or not). For a non-contiguous array this is just the first element's address — walk the rest yourself using strides (byte strides). Unsafe: does not root the buffer. Requires the exact dtype.

public T* Pointer<T>() where T : unmanaged

Returns

T*

Type Parameters

T

ReadOnlyBytes()

Read-only counterpart of Bytes().

public ReadOnlySpan<byte> ReadOnlyBytes()

Returns

ReadOnlySpan<byte>

ReadOnlyMemory<T>()

A ReadOnlyMemory<T> aliasing the array's logical C-order elements. Unsafe, C-contiguous, manager-backed — as Memory<T>().

public ReadOnlyMemory<T> ReadOnlyMemory<T>() where T : unmanaged

Returns

ReadOnlyMemory<T>

Type Parameters

T

ReadOnlySpan<T>()

A read-only ReadOnlySpan<T> aliasing the array's logical C-order elements. Unsafe and C-contiguous, as Span<T>().

public ReadOnlySpan<T> ReadOnlySpan<T>() where T : unmanaged

Returns

ReadOnlySpan<T>

Type Parameters

T

Span<T>()

A Span<T> aliasing the array's logical C-order elements. Unsafe: does not root the buffer — keep the NDArray alive. Requires a C-contiguous array of the exact dtype and ≤ MaxValue elements (throws otherwise; see TryGetSpan<T>(out Span<T>) for the non-throwing form).

public Span<T> Span<T>() where T : unmanaged

Returns

Span<T>

Type Parameters

T

TryGetMemory<T>(out Memory<T>)

Tries to alias the array's logical C-order elements as a Memory<T> (manager-backed). Returns false under the same conditions as TryGetSpan<T>(out Span<T>). Unsafe aliasing, as Memory<T>().

public bool TryGetMemory<T>(out Memory<T> memory) where T : unmanaged

Parameters

memory Memory<T>

Returns

bool

Type Parameters

T

TryGetSpan<T>(out Span<T>)

Tries to alias the array's logical C-order elements as a Span<T>. Returns false (and default) instead of throwing when the dtype does not match, the array is not C-contiguous, or it has more than MaxValue elements. Unsafe aliasing, as Span<T>().

public bool TryGetSpan<T>(out Span<T> span) where T : unmanaged

Parameters

span Span<T>

Returns

bool

Type Parameters

T