Table of Contents

Interface IArraySlice

Namespace
NumSharp.Backends.Unmanaged
Assembly
NumSharp.dll
public interface IArraySlice : IMemoryBlock, ICloneable, IEnumerable
Inherited Members
Extension Methods

Properties

IsReleased

Diagnostic: true once the underlying buffer has been freed.

bool IsReleased { get; }

Property Value

bool

IsUniquelyReferenced

true when the underlying MemoryBlock is held by at most one logical reference (this owner), i.e. no other NDArray / view shares its buffer. Non-owning wraps (external / pinned memory) report true since their refcount is immortal and meaningless. Used by ndarray.resize's refcheck to mirror NumPy's "references or is referenced by another array" guard.

bool IsUniquelyReferenced { get; }

Property Value

bool

this[long]

object this[long index] { get; set; }

Parameters

index long

Property Value

object

MemoryBlock

IMemoryBlock MemoryBlock { get; }

Property Value

IMemoryBlock

Methods

Abandon()

Atomically decrement the reference count WITHOUT freeing the buffer when the count reaches zero — the finalizer-path counterpart of Release(). A finalizer proves only that one wrapper became unreachable, not that no other reachable alias (a bare storage/slice) still reads the buffer; the block's own finalizer frees it once the whole alias graph is unreachable.

void Abandon()

AsSpan<T>()

Returns an UnmanagedSpan representing this slice's memory.

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.

Clone()

IArraySlice Clone()

Returns

IArraySlice

Clone<T>()

ArraySlice<T> Clone<T>() where T : unmanaged

Returns

ArraySlice<T>

Type Parameters

T

CopyTo<T>(UnmanagedSpan<T>)

Copies this slice's contents to an UnmanagedSpan destination. Supports long indexing for arrays > 2B elements.

void CopyTo<T>(UnmanagedSpan<T> destination) where T : unmanaged

Parameters

destination UnmanagedSpan<T>

Type Parameters

T

CopyTo<T>(Span<T>)

void CopyTo<T>(Span<T> destination)

Parameters

destination Span<T>

Type Parameters

T

DangerousFree()

Performs dispose on the internal unmanaged memory block.

void DangerousFree()

Remarks

Dangerous because this ArraySlice might be a slice of a larger block, so other slices might point to the current MemoryBlock.
So releasing the MemoryBlock might cause memory corruption elsewhere.
It is best to leave MemoryBlock to GC.

Fill(object)

Fills all indexes with value.

void Fill(object value)

Parameters

value object

GetIndex(long)

object GetIndex(long index)

Parameters

index long

Returns

object

GetIndex<T>(long)

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

Parameters

index long

Returns

T

Type Parameters

T

GetItems(long, long, Span<object>)

Reads a strided run of elements as their C# values — the run form of GetIndex(long): element start + i * stride into destination[i] for every i of destination. ndarray.tolist() reads each innermost row of its nested lists with one call.

void GetItems(long start, long stride, Span<object> destination)

Parameters

start long

The first element, as an index into this slice (what GetIndex(long) takes).

stride long

The step between consecutive elements, in elements: 0 reads one element repeatedly (a broadcast axis), a negative step walks backwards (a reversed view).

destination Span<object>

Receives the values; its length is the number of elements read.

Remarks

Every implementation gives exactly what GetIndex(long) gives for each element — the same boxed type, the same text, a fresh object per element, the same exception at the same element (a slice outside the library raises what its own GetIndex(long) raises) — and reads nothing outside the run's elements. The caller guarantees that every element of the run is inside the slice; nothing here checks it (an index outside reads other memory, as GetIndex(long) would). This default calls GetIndex(long) per element; the library's slices read the run in one pass: a numeric slice boxes straight from its memory, a fixed-width string slice decodes each element without the per-call dispatch, and a StringDType slice takes its allocator's lock once for the run instead of once per element (NumPy's getitem locks per element; the lock guards the same reads).

Exceptions

SystemError

A U element holds a unit above U+10FFFF (CPython's invalid maximum character passed to PyUnicode_New). Raised at the first such element: the slots before it are filled, the rest are not.

OutOfMemoryException

A StringDType element whose cell is corrupt (NumPy's Failed to load string in StringDType getitem) or whose text is too long for a .NET string; raised as above.

GetPinnableReference<T>()

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

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

Returns

T

Type Parameters

T

Release()

Atomically decrement the reference count. Frees the underlying buffer immediately on the final release.

void Release()

SetIndex(long, object)

void SetIndex(long index, object value)

Parameters

index long
value object

SetIndex<T>(long, T)

void SetIndex<T>(long index, T value) where T : unmanaged

Parameters

index long
value T

Type Parameters

T

Slice(long)

Perform a slicing on this IMemoryBlock without copying data.

IArraySlice Slice(long start)

Parameters

start long

The index to start from

Returns

IArraySlice

Remarks

Creates a slice without copying.

Slice(long, long)

Perform a slicing on this IMemoryBlock without copying data.

IArraySlice Slice(long start, long count)

Parameters

start long

The index to start from

count long

The number of items to slice (not bytes)

Returns

IArraySlice

Remarks

Creates a slice without copying.

ToArray()

Copies this IArraySlice contents into a new array.

Array ToArray()

Returns

Array

TryAddRef()

Atomically increment the reference count on the underlying MemoryBlock. Returns false if the block has already been released and must not be referenced further.

bool TryAddRef()

Returns

bool