Table of Contents

Class UnmanagedStorage

Namespace
NumSharp.Backends
Assembly
NumSharp.dll

Serves as a typed storage for an array.

public class UnmanagedStorage : ICloneable
Inheritance
UnmanagedStorage
Implements
Inherited Members
Extension Methods

Remarks

Responsible for :

  • store data type, elements, Shape
  • offers methods for accessing elements depending on shape
  • offers methods for casting elements
  • offers methods for change tensor order
  • GetData always return reference object to the true storage
  • GetData{T} and SetData{T} change dtype and cast storage
  • CloneData always create a clone of storage and return this as reference object
  • CloneData{T} clone storage and cast this clone

Constructors

UnmanagedStorage(IArraySlice, Shape)

Wraps given arraySlice in UnmanagedStorage.

public UnmanagedStorage(IArraySlice arraySlice, Shape shape)

Parameters

arraySlice IArraySlice

The slice to wrap

shape Shape

UnmanagedStorage(NPTypeCode)

Creates an empty storage of type typeCode.

public UnmanagedStorage(NPTypeCode typeCode)

Parameters

typeCode NPTypeCode

The type of this storage

Remarks

Usually Allocate(Shape, Type) is called after this constructor.

UnmanagedStorage(bool)

public UnmanagedStorage(bool scalar)

Parameters

scalar bool

UnmanagedStorage(bool[])

public UnmanagedStorage(bool[] values)

Parameters

values bool[]

UnmanagedStorage(byte)

public UnmanagedStorage(byte scalar)

Parameters

scalar byte

UnmanagedStorage(byte[])

public UnmanagedStorage(byte[] values)

Parameters

values byte[]

UnmanagedStorage(char)

public UnmanagedStorage(char scalar)

Parameters

scalar char

UnmanagedStorage(char[])

public UnmanagedStorage(char[] values)

Parameters

values char[]

UnmanagedStorage(decimal)

public UnmanagedStorage(decimal scalar)

Parameters

scalar decimal

UnmanagedStorage(decimal[])

public UnmanagedStorage(decimal[] values)

Parameters

values decimal[]

UnmanagedStorage(double)

public UnmanagedStorage(double scalar)

Parameters

scalar double

UnmanagedStorage(double[])

public UnmanagedStorage(double[] values)

Parameters

values double[]

UnmanagedStorage(short)

public UnmanagedStorage(short scalar)

Parameters

scalar short

UnmanagedStorage(short[])

public UnmanagedStorage(short[] values)

Parameters

values short[]

UnmanagedStorage(int)

public UnmanagedStorage(int scalar)

Parameters

scalar int

UnmanagedStorage(int[])

public UnmanagedStorage(int[] values)

Parameters

values int[]

UnmanagedStorage(long)

public UnmanagedStorage(long scalar)

Parameters

scalar long

UnmanagedStorage(long[])

public UnmanagedStorage(long[] values)

Parameters

values long[]

UnmanagedStorage(float)

public UnmanagedStorage(float scalar)

Parameters

scalar float

UnmanagedStorage(float[])

public UnmanagedStorage(float[] values)

Parameters

values float[]

UnmanagedStorage(Type)

Creates an empty storage of type dtype.

public UnmanagedStorage(Type dtype)

Parameters

dtype Type

The type of this storage

Remarks

Usually Allocate(Shape, Type) is called after this constructor.

UnmanagedStorage(ushort)

public UnmanagedStorage(ushort scalar)

Parameters

scalar ushort

UnmanagedStorage(ushort[])

public UnmanagedStorage(ushort[] values)

Parameters

values ushort[]

UnmanagedStorage(uint)

public UnmanagedStorage(uint scalar)

Parameters

scalar uint

UnmanagedStorage(uint[])

public UnmanagedStorage(uint[] values)

Parameters

values uint[]

UnmanagedStorage(ulong)

public UnmanagedStorage(ulong scalar)

Parameters

scalar ulong

UnmanagedStorage(ulong[])

public UnmanagedStorage(ulong[] values)

Parameters

values ulong[]

Fields

Address

public byte* Address

Field Value

byte*

Count

public long Count

Field Value

long

InternalArray

public IArraySlice InternalArray

Field Value

IArraySlice

_arrayBoolean

protected ArraySlice<bool> _arrayBoolean

Field Value

ArraySlice<bool>

_arrayByte

protected ArraySlice<byte> _arrayByte

Field Value

ArraySlice<byte>

_arrayChar

protected ArraySlice<char> _arrayChar

Field Value

ArraySlice<char>

_arrayComplex

protected ArraySlice<Complex> _arrayComplex

Field Value

ArraySlice<Complex>

_arrayDecimal

protected ArraySlice<decimal> _arrayDecimal

Field Value

ArraySlice<decimal>

_arrayDouble

protected ArraySlice<double> _arrayDouble

Field Value

ArraySlice<double>

_arrayHalf

protected ArraySlice<Half> _arrayHalf

Field Value

ArraySlice<Half>

_arrayInt16

protected ArraySlice<short> _arrayInt16

Field Value

ArraySlice<short>

_arrayInt32

protected ArraySlice<int> _arrayInt32

Field Value

ArraySlice<int>

_arrayInt64

protected ArraySlice<long> _arrayInt64

Field Value

ArraySlice<long>

_arraySByte

protected ArraySlice<sbyte> _arraySByte

Field Value

ArraySlice<sbyte>

_arraySingle

protected ArraySlice<float> _arraySingle

Field Value

ArraySlice<float>

_arrayUInt16

protected ArraySlice<ushort> _arrayUInt16

Field Value

ArraySlice<ushort>

_arrayUInt32

protected ArraySlice<uint> _arrayUInt32

Field Value

ArraySlice<uint>

_arrayUInt64

protected ArraySlice<ulong> _arrayUInt64

Field Value

ArraySlice<ulong>

_dtype

protected Type _dtype

Field Value

Type

_shape

protected Shape _shape

Field Value

Shape

_typecode

protected NPTypeCode _typecode

Field Value

NPTypeCode

Properties

BaseStorage

Gets the original storage this is a view of, or null if this storage owns its data.

public UnmanagedStorage? BaseStorage { get; }

Property Value

UnmanagedStorage

The ultimate owner storage for views, or null for owned data.

Remarks

NumPy-compatible: All views chain to the ultimate owner (not intermediate views).

Example:

var a = np.arange(10);           // a.Storage.BaseStorage == null (owns data)
var b = a["2:5"];                // b.Storage.BaseStorage == a.Storage
var c = b["1:2"];                // c.Storage.BaseStorage == a.Storage (chains to original!)

Note: This property is read-only by design. Allowing external modification would risk breaking the memory ownership chain and could lead to use-after-free bugs.

See Also

DType

The data type of internal storage array.

public Type DType { get; }

Property Value

Type

numpys equal dtype

Remarks

Has to be compliant with NPTypeCode.

DTypeSize

The size in bytes of a single value of DType

public int DTypeSize { get; }

Property Value

int

Remarks

Computed by SizeOf(object)

Engine

The engine that was used to create this IStorage.

public TensorEngine Engine { get; protected set; }

Property Value

TensorEngine

IsView

Gets a value indicating whether this storage is a view of another storage.

public bool IsView { get; }

Property Value

bool

true if this storage shares memory with another storage (does not own its data); false if this storage owns its data.

Remarks

Equivalent to checking BaseStorage != null.

Use cases:

  • Determine if an array can be safely modified without affecting other arrays
  • Optimize copy-on-write patterns
  • Debug memory sharing issues

Shape

The shape representing the data in this storage.

public Shape Shape { get; set; }

Property Value

Shape

ShapeReference

The shape representing the data in this storage.

public ref Shape ShapeReference { get; }

Property Value

Shape

Remarks

It is dangerous to set Shape by reference. use Reshape(Shape) instead.

TypeCode

The NPTypeCode of IStorage.DType.

public NPTypeCode TypeCode { get; }

Property Value

NPTypeCode

Methods

Alias()

Creates an alias (view) of this storage that shares the same underlying memory.

public UnmanagedStorage Alias()

Returns

UnmanagedStorage

A new UnmanagedStorage that shares memory with this storage. The returned storage's NumSharp.Backends.UnmanagedStorage._baseStorage points to the ultimate owner.

Remarks

Memory Sharing: The alias shares the same InternalArray and underlying memory. Modifications through the alias affect the original data.

Base Tracking: Sets _baseStorage to chain to the ultimate owner:

  • If this storage owns its data: alias._baseStorage = this
  • If this storage is a view: alias._baseStorage = this._baseStorage

This ensures all views in a chain point to the original owner, not intermediate views.

See Also

Alias(Shape)

Creates an alias (view) of this storage with a different shape.

public UnmanagedStorage Alias(Shape shape)

Parameters

shape Shape

The shape for the alias. Should be compatible with the storage size (not validated).

Returns

UnmanagedStorage

A new UnmanagedStorage that shares memory with this storage but has the specified shape. The returned storage's NumSharp.Backends.UnmanagedStorage._baseStorage points to the ultimate owner.

Remarks

Memory Sharing: The alias shares the same InternalArray and underlying memory. Modifications through the alias affect the original data.

Shape Compatibility: This method does NOT validate that the shape is compatible with the storage size. Use with caution.

Base Tracking: Sets _baseStorage to chain to the ultimate owner.

See Also

Alias(ref Shape)

Creates an alias (view) of this storage with a different shape (by reference).

public UnmanagedStorage Alias(ref Shape shape)

Parameters

shape Shape

The shape for the alias. Should be compatible with the storage size (not validated).

Returns

UnmanagedStorage

A new UnmanagedStorage that shares memory with this storage but has the specified shape. The returned storage's NumSharp.Backends.UnmanagedStorage._baseStorage points to the ultimate owner.

Remarks

Memory Sharing: The alias shares the same InternalArray and underlying memory. Modifications through the alias affect the original data.

Shape Compatibility: This method does NOT validate that the shape is compatible with the storage size. Use with caution.

Base Tracking: Sets _baseStorage to chain to the ultimate owner.

See Also

AliasAs(NPTypeCode)

Creates an alias (view) of this storage with a different dtype, reinterpreting bytes.

public UnmanagedStorage AliasAs(NPTypeCode typeCode)

Parameters

typeCode NPTypeCode

The new dtype to interpret the bytes as.

Returns

UnmanagedStorage

A view with reinterpreted bytes.

AliasAs(Type)

Creates an alias (view) of this storage with a different dtype, reinterpreting bytes.

public UnmanagedStorage AliasAs(Type dtype)

Parameters

dtype Type

The new dtype to interpret the bytes as.

Returns

UnmanagedStorage

A view with reinterpreted bytes.

AliasAs<T>()

Creates an alias (view) of this storage with a different dtype, reinterpreting bytes.

public UnmanagedStorage AliasAs<T>() where T : unmanaged

Returns

UnmanagedStorage

A new UnmanagedStorage that shares memory with this storage but interprets the bytes as a different type. Shape is adjusted if type sizes differ.

Type Parameters

T

The new dtype to interpret the bytes as.

Remarks

Byte Reinterpretation: This does NOT convert values. It reinterprets the raw bytes as a different type, like NumPy's view(). For example, viewing float64 as int64 will show the IEEE 754 bit patterns, not converted values.

Shape Adjustment: If the new type has a different size, the last dimension is adjusted. E.g., float64[3] viewed as float32 becomes float32[6].

Contiguous Requirement: Only contiguous arrays can be viewed with different dtype when sizes differ.

Exceptions

InvalidOperationException

If the array is not contiguous and type sizes differ.

ArgumentException

If the total byte size is not divisible by the new type size.

Allocate(IArraySlice, Shape, bool)

Allocate values into memory.

public void Allocate(IArraySlice values, Shape shape, bool copy = false)

Parameters

values IArraySlice

The array to set as internal data storage

shape Shape

The shape of the array.

copy bool

Should perform a copy of values

Remarks

Does not copy values

Allocate(Shape, NPTypeCode, bool)

Allocates a new Array into memory.

public void Allocate(Shape shape, NPTypeCode dtype, bool fillZeros)

Parameters

shape Shape

The shape of the array.

dtype NPTypeCode

The type of the Array, if null DType is used.

fillZeros bool

Allocate(Shape, Type)

Allocates a new Array into memory.

public void Allocate(Shape shape, Type dtype = null)

Parameters

shape Shape

The shape of the array.

dtype Type

The type of the Array, if null DType is used.

Allocate(Shape, Type, bool)

Allocates a new Array into memory.

public void Allocate(Shape shape, Type dtype, bool fillZeros)

Parameters

shape Shape

The shape of the array.

dtype Type

The type of the Array, if null DType is used.

fillZeros bool

Allocate(Array)

Allocate array into memory.

public void Allocate(Array array)

Parameters

array Array

The array to set as internal data storage

Remarks

Does not copy array

Allocate(Array, Shape)

Allocate values into memory.

public void Allocate(Array values, Shape shape)

Parameters

values Array

The array to set as internal data storage

shape Shape

The shape of given array

Remarks

Does not copy values

Allocate<T>(ArraySlice<T>, Shape, bool)

Assign this ArraySlice<T> as the internal array storage and assign shape to it.

public void Allocate<T>(ArraySlice<T> values, Shape shape, bool copy = false) where T : unmanaged

Parameters

values ArraySlice<T>

The array to set as internal data storage

shape Shape

The shape of the array.

copy bool

Should perform a copy of values

Type Parameters

T

Remarks

Does not copy values

Allocate<T>(T[])

Allocate values into memory.

public void Allocate<T>(T[] values) where T : unmanaged

Parameters

values T[]

The array to set as internal data storage

Type Parameters

T

Remarks

Does not copy values

AsSpan<T>()

Returns an UnmanagedSpan representing this storage's memory.

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

Returns

Span<T>

Type Parameters

T

Remarks

This ignores completely slicing. Supports long indexing for arrays > 2B elements.

AsUnmanagedSpan<T>()

Returns an UnmanagedSpan representing this storage's memory.

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

Returns

UnmanagedSpan<T>

Type Parameters

T

Remarks

This ignores completely slicing. Supports long indexing for arrays > 2B elements.

Cast(NPTypeCode)

Return a casted UnmanagedStorage to a specific dtype.

public UnmanagedStorage Cast(NPTypeCode typeCode)

Parameters

typeCode NPTypeCode

The dtype to convert to

Returns

UnmanagedStorage

A copy of this UnmanagedStorage casted to a specific dtype.

Remarks

Always copies, If dtype==typeof(T) then a Clone() is returned.

Cast(Type)

Return a casted UnmanagedStorage to a specific dtype.

public UnmanagedStorage Cast(Type dtype)

Parameters

dtype Type

The dtype to convert to

Returns

UnmanagedStorage

A copy of this UnmanagedStorage casted to a specific dtype.

Remarks

Always copies, If dtype==typeof(T) then a Clone() is returned.

CastIfNecessary(NPTypeCode)

Return a casted UnmanagedStorage to a specific dtype only if necessary

public UnmanagedStorage CastIfNecessary(NPTypeCode typeCode)

Parameters

typeCode NPTypeCode

The dtype to convert to

Returns

UnmanagedStorage

A copy of this UnmanagedStorage casted to a specific dtype.

Remarks

Copies only if dtypes does not match typeCode

CastIfNecessary(Type)

Return a casted UnmanagedStorage to a specific dtype.

public UnmanagedStorage CastIfNecessary(Type dtype)

Parameters

dtype Type

The dtype to convert to

Returns

UnmanagedStorage

A copy of this UnmanagedStorage casted to a specific dtype.

Remarks

Copies only if dtypes does not match typeCode

CastIfNecessary<T>()

Return a casted UnmanagedStorage to a specific dtype only if necessary.

public UnmanagedStorage CastIfNecessary<T>() where T : unmanaged

Returns

UnmanagedStorage

A copy of this UnmanagedStorage casted to a specific dtype.

Type Parameters

T

The dtype to convert to

Remarks

Copies only if dtypes does not match T

Cast<T>()

Return a casted UnmanagedStorage to a specific dtype.

public UnmanagedStorage Cast<T>() where T : unmanaged

Returns

UnmanagedStorage

A copy of this UnmanagedStorage casted to a specific dtype.

Type Parameters

T

The dtype to convert to

Remarks

Always copies, If dtype==typeof(T) then a Clone() is returned.

Clone()

Perform a complete copy of this UnmanagedStorage and InternalArray.

public UnmanagedStorage Clone()

Returns

UnmanagedStorage

Remarks

If shape is sliced, discards any slicing properties but copies only the sliced data

CloneData()

Clone internal storage and get reference to it

public IArraySlice CloneData()

Returns

IArraySlice

reference to cloned storage as System.Array

CloneData<T>()

Get all elements from cloned storage as ArraySlice<T> and cast if necessary.

public ArraySlice<T> CloneData<T>() where T : unmanaged

Returns

ArraySlice<T>

reference to cloned storage and casted (if necessary) as ArraySlice<T>

Type Parameters

T

cloned storgae dtype

CopyTo(IMemoryBlock)

Copies the entire contents of this storage to given address (using Count).

public void CopyTo(IMemoryBlock block)

Parameters

block IMemoryBlock

The block to copy to.

CopyTo(nint)

Copies the entire contents of this storage to given address.

public void CopyTo(nint ptr)

Parameters

ptr nint

CopyTo(void*)

Copies the entire contents of this storage to given address.

public void CopyTo(void* address)

Parameters

address void*

The address to copy to.

CopyTo<T>(IMemoryBlock<T>)

Copies the entire contents of this storage to given address (using Count).

public void CopyTo<T>(IMemoryBlock<T> block) where T : unmanaged

Parameters

block IMemoryBlock<T>

The block to copy to.

Type Parameters

T

CopyTo<T>(T*)

Copies the entire contents of this storage to given address.

public void CopyTo<T>(T* address) where T : unmanaged

Parameters

address T*

The address to copy to.

Type Parameters

T

CopyTo<T>(T[])

Copies the entire contents of this storage to given array.

public void CopyTo<T>(T[] array) where T : unmanaged

Parameters

array T[]

The array to copy to.

Type Parameters

T

CreateBroadcastedUnsafe(IArraySlice, Shape)

Creates a new storage with a broadcasted shape from an array slice.

public static UnmanagedStorage CreateBroadcastedUnsafe(IArraySlice arraySlice, Shape shape)

Parameters

arraySlice IArraySlice

The array slice to wrap.

shape Shape

The broadcasted shape to represent this storage.

Returns

UnmanagedStorage

A new UnmanagedStorage that owns the data (not a view). The returned storage's NumSharp.Backends.UnmanagedStorage._baseStorage is null.

Remarks

Named "Unsafe": This method does not validate that the shape is compatible with the array slice size.

Ownership: This overload creates owned storage (not a view) because it receives raw data without storage context. Compare with the CreateBroadcastedUnsafe(UnmanagedStorage, Shape) overload which preserves base tracking.

CreateBroadcastedUnsafe(UnmanagedStorage, Shape)

Creates a broadcasted view of an existing storage with a new shape.

public static UnmanagedStorage CreateBroadcastedUnsafe(UnmanagedStorage storage, Shape shape)

Parameters

storage UnmanagedStorage

The source storage to take InternalArray from.

shape Shape

The broadcasted shape to represent this storage.

Returns

UnmanagedStorage

A new UnmanagedStorage that shares memory with the source storage. The returned storage's NumSharp.Backends.UnmanagedStorage._baseStorage points to the ultimate owner.

Remarks

Named "Unsafe": This method does not validate that the shape is compatible with the storage size.

Base Tracking: Sets _baseStorage to chain to the ultimate owner:

  • If source storage owns its data: result._baseStorage = storage
  • If source storage is a view: result._baseStorage = storage._baseStorage

Used By: np.broadcast_to(), np.broadcast_arrays(), and internal broadcasting operations.

See Also

ExpandDimension(int)

protected void ExpandDimension(int axis)

Parameters

axis int

GetAtIndex(long)

public object GetAtIndex(long index)

Parameters

index long

Returns

object

GetAtIndex<T>(long)

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

Parameters

index long

Returns

T

Type Parameters

T

GetBoolean(int[])

Retrieves value of type bool from internal storage.

public bool GetBoolean(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

bool

Exceptions

NullReferenceException

When DType is not bool

GetBoolean(params long[])

Retrieves value of type bool from internal storage.

public bool GetBoolean(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

bool

Exceptions

NullReferenceException

When DType is not bool

GetByte(int[])

Retrieves value of type byte from internal storage.

public byte GetByte(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

byte

Exceptions

NullReferenceException

When DType is not byte

GetByte(params long[])

Retrieves value of type byte from internal storage.

public byte GetByte(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

byte

Exceptions

NullReferenceException

When DType is not byte

GetChar(int[])

Retrieves value of type char from internal storage.

public char GetChar(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

char

Exceptions

NullReferenceException

When DType is not char

GetChar(params long[])

Retrieves value of type char from internal storage.

public char GetChar(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

char

Exceptions

NullReferenceException

When DType is not char

GetComplex(int[])

Retrieves value of type Complex from internal storage.

public Complex GetComplex(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

Complex

Exceptions

NullReferenceException

When DType is not Complex

GetComplex(params long[])

Retrieves value of type Complex from internal storage.

public Complex GetComplex(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

Complex

Exceptions

NullReferenceException

When DType is not Complex

GetData()

Get reference to internal data storage

public IArraySlice GetData()

Returns

IArraySlice

reference to internal storage as System.Array

GetData(int*, int)

Gets a sub-array based on the given indices (pointer version), returning a view that shares memory.

public UnmanagedStorage GetData(int* dims, int ndims)

Parameters

dims int*

Pointer to an array of dimension indices.

ndims int

The number of indices in the array.

Returns

UnmanagedStorage

A new UnmanagedStorage representing the sub-array. This is a view that shares memory with the original storage. The returned storage's NumSharp.Backends.UnmanagedStorage._baseStorage points to the ultimate owner.

Remarks

Memory Sharing: The returned storage shares memory with this storage. Modifications through either storage affect the same underlying data.

Base Tracking: Sets _baseStorage to chain to the ultimate owner, ensuring all views in a chain point to the original storage, not intermediate views.

Code Paths:

  • Broadcasted shapes: Creates a broadcasted view with base tracking
  • Non-contiguous shapes: Delegates to GetView(params Slice[]) which uses Alias(Shape)
  • Contiguous shapes: Creates a direct memory slice with base tracking
See Also

GetData(int[])

Gets a sub-array based on the given indices, returning a view that shares memory.

public UnmanagedStorage GetData(int[] indices)

Parameters

indices int[]

The indices specifying which dimensions to select. Negative indices are supported and are converted to positive indices relative to the dimension size.

Returns

UnmanagedStorage

A new UnmanagedStorage representing the sub-array. This is a view that shares memory with the original storage. The returned storage's NumSharp.Backends.UnmanagedStorage._baseStorage points to the ultimate owner.

Remarks

Memory Sharing: The returned storage shares memory with this storage. Modifications through either storage affect the same underlying data.

Base Tracking: Sets _baseStorage to chain to the ultimate owner, ensuring all views in a chain point to the original storage, not intermediate views.

Code Paths:

  • Broadcasted shapes: Creates a broadcasted view with base tracking
  • Non-contiguous shapes: Delegates to GetView(params Slice[]) which uses Alias(Shape)
  • Contiguous shapes: Creates a direct memory slice with base tracking
See Also

GetData(long*, int)

Gets a sub-array based on the given indices (long pointer version), returning a view that shares memory.

public UnmanagedStorage GetData(long* dims, int ndims)

Parameters

dims long*

Pointer to an array of long dimension indices.

ndims int

The number of indices in the array.

Returns

UnmanagedStorage

A new UnmanagedStorage representing the sub-array.

GetData(params long[])

Gets a sub-array based on the given indices (long array version), returning a view that shares memory.

public UnmanagedStorage GetData(params long[] indices)

Parameters

indices long[]

The dimension indices specifying the sub-array.

Returns

UnmanagedStorage

A new UnmanagedStorage representing the sub-array. This is a view that shares memory with the original storage. The returned storage's NumSharp.Backends.UnmanagedStorage._baseStorage points to the ultimate owner.

See Also

GetData<T>()

Get reference to internal data storage and cast (also copies) elements to new dtype if necessary

public ArraySlice<T> GetData<T>() where T : unmanaged

Returns

ArraySlice<T>

reference to internal (casted) storage as T[]

Type Parameters

T

new storage data type

Remarks

Copies if T does not equal to DType or if Shape is sliced.

GetDecimal(int[])

Retrieves value of type decimal from internal storage.

public decimal GetDecimal(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

decimal

Exceptions

NullReferenceException

When DType is not decimal

GetDecimal(params long[])

Retrieves value of type decimal from internal storage.

public decimal GetDecimal(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

decimal

Exceptions

NullReferenceException

When DType is not decimal

GetDouble(int[])

Retrieves value of type double from internal storage.

public double GetDouble(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

double

Exceptions

NullReferenceException

When DType is not double

GetDouble(params long[])

Retrieves value of type double from internal storage.

public double GetDouble(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

double

Exceptions

NullReferenceException

When DType is not double

GetHalf(int[])

Retrieves value of type Half from internal storage.

public Half GetHalf(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

Half

Exceptions

NullReferenceException

When DType is not Half

GetHalf(params long[])

Retrieves value of type Half from internal storage.

public Half GetHalf(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

Half

Exceptions

NullReferenceException

When DType is not Half

GetInt16(int[])

Retrieves value of type short from internal storage.

public short GetInt16(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

short

Exceptions

NullReferenceException

When DType is not short

GetInt16(params long[])

Retrieves value of type short from internal storage.

public short GetInt16(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

short

Exceptions

NullReferenceException

When DType is not short

GetInt32(int[])

Retrieves value of type int from internal storage.

public int GetInt32(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

int

Exceptions

NullReferenceException

When DType is not int

GetInt32(params long[])

Retrieves value of type int from internal storage.

public int GetInt32(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

int

Exceptions

NullReferenceException

When DType is not int

GetInt64(int[])

Retrieves value of type long from internal storage.

public long GetInt64(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

long

Exceptions

NullReferenceException

When DType is not long

GetInt64(params long[])

Retrieves value of type long from internal storage.

public long GetInt64(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

long

Exceptions

NullReferenceException

When DType is not long

GetSByte(int[])

Retrieves value of type sbyte from internal storage.

public sbyte GetSByte(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

sbyte

Exceptions

NullReferenceException

When DType is not sbyte

GetSByte(params long[])

Retrieves value of type sbyte from internal storage.

public sbyte GetSByte(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

sbyte

Exceptions

NullReferenceException

When DType is not sbyte

GetSingle(int[])

Retrieves value of type float from internal storage.

public float GetSingle(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

float

Exceptions

NullReferenceException

When DType is not float

GetSingle(params long[])

Retrieves value of type float from internal storage.

public float GetSingle(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

float

Exceptions

NullReferenceException

When DType is not float

GetUInt16(int[])

Retrieves value of type ushort from internal storage.

public ushort GetUInt16(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

ushort

Exceptions

NullReferenceException

When DType is not ushort

GetUInt16(params long[])

Retrieves value of type ushort from internal storage.

public ushort GetUInt16(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

ushort

Exceptions

NullReferenceException

When DType is not ushort

GetUInt32(int[])

Retrieves value of type uint from internal storage.

public uint GetUInt32(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

uint

Exceptions

NullReferenceException

When DType is not uint

GetUInt32(params long[])

Retrieves value of type uint from internal storage.

public uint GetUInt32(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

uint

Exceptions

NullReferenceException

When DType is not uint

GetUInt64(int[])

Retrieves value of type ulong from internal storage.

public ulong GetUInt64(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

ulong

Exceptions

NullReferenceException

When DType is not ulong

GetUInt64(params long[])

Retrieves value of type ulong from internal storage.

public ulong GetUInt64(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long version).

Returns

ulong

Exceptions

NullReferenceException

When DType is not ulong

GetValue(int[])

Retrieves value of unspecified type (will figure using IStorage.DType).

public object GetValue(int[] indices)

Parameters

indices int[]

The shape's indices to get.

Returns

object

Exceptions

NullReferenceException

When IStorage.DType is not object

GetValue(params long[])

Retrieves value of unspecified type (will figure using IStorage.DType).

public object GetValue(params long[] indices)

Parameters

indices long[]

The shape's indices to get (long array version).

Returns

object

GetValue<T>(int[])

Get single value from internal storage as type T and cast dtype to T

public T GetValue<T>(int[] indices) where T : unmanaged

Parameters

indices int[]

indices

Returns

T

element from internal storage

Type Parameters

T

new storage data type

Remarks

If you provide less indices than there are dimensions, the rest are filled with 0.

Exceptions

NullReferenceException

When T does not equal to DType

GetValue<T>(params long[])

Get element from internal storage as T

public T GetValue<T>(params long[] indices) where T : unmanaged

Parameters

indices long[]

indices

Returns

T

element from internal storage

Type Parameters

T

new storage data type

Remarks

If you provide less indices than there are dimensions, the rest are filled with 0.

Exceptions

NullReferenceException

When T does not equal to DType

GetView(params Slice[])

public UnmanagedStorage GetView(params Slice[] slices)

Parameters

slices Slice[]

Returns

UnmanagedStorage

GetView(string)

public UnmanagedStorage GetView(string slicing_notation)

Parameters

slicing_notation string

Returns

UnmanagedStorage

ReplaceData(IArraySlice)

Sets values as the internal data source and changes the internal storage data type to values type.

public void ReplaceData(IArraySlice values)

Parameters

values IArraySlice

Remarks

Does not copy values and doesn't change shape.

ReplaceData(IArraySlice, Shape)

Sets values as the internal data source and changes the internal storage data type to values type.

public void ReplaceData(IArraySlice values, Shape shape)

Parameters

values IArraySlice
shape Shape

The shape to set in this storage. (without checking if shape matches storage)

Remarks

Does not copy values and doesn't change shape. Doesn't check if shape size matches.

ReplaceData(IArraySlice, Type)

Sets values as the internal data source and changes the internal storage data type to values type.

public void ReplaceData(IArraySlice values, Type dtype)

Parameters

values IArraySlice
dtype Type

Remarks

Does not copy values and doesn't change shape.

ReplaceData(IArraySlice, Type, Shape)

Sets values as the internal data source and changes the internal storage data type to values type.

public void ReplaceData(IArraySlice values, Type dtype, Shape shape)

Parameters

values IArraySlice
dtype Type
shape Shape

The shape to set in this storage. (without checking if shape matches storage)

Remarks

Does not copy values and doesn't change shape. Doesn't check if shape size matches.

ReplaceData(NDArray)

Sets nd as the internal data storage and changes the internal storage data type to nd type.

public void ReplaceData(NDArray nd)

Parameters

nd NDArray

Remarks

Does not copy values and does change shape and dtype.

ReplaceData(NDArray, Shape)

Sets nd as the internal data storage and changes the internal storage data type to nd type.

public void ReplaceData(NDArray nd, Shape shape)

Parameters

nd NDArray
shape Shape

The shape to set in this storage. (without checking if shape matches storage)

Remarks

Does not copy values and does change shape and dtype. Doesn't check if shape size matches.

ReplaceData(Array)

Sets values as the internal data source and changes the internal storage data type to values type.

public void ReplaceData(Array values)

Parameters

values Array

Remarks

Copies values only if values type does not match DType and doesn't change shape.

ReplaceData(Array, NPTypeCode)

Set an Array to internal storage, cast it to new dtype and if necessary change dtype

public void ReplaceData(Array values, NPTypeCode typeCode)

Parameters

values Array
typeCode NPTypeCode

Remarks

Does not copy values unless cast is necessary and doesn't change shape.

ReplaceData(Array, NPTypeCode, Shape)

Set an Array to internal storage, cast it to new dtype and if necessary change dtype

public void ReplaceData(Array values, NPTypeCode typeCode, Shape shape)

Parameters

values Array
typeCode NPTypeCode
shape Shape

The shape to set in this storage. (without checking if shape matches storage)

Remarks

Does not copy values unless cast is necessary and doesn't change shape. Doesn't check if shape size matches.

ReplaceData(Array, Shape)

Sets values as the internal data source and changes the internal storage data type to values type.

public void ReplaceData(Array values, Shape shape)

Parameters

values Array
shape Shape

The shape to set in this storage. (without checking if shape matches storage)

Remarks

Copies values only if values type does not match DType and doesn't change shape. Doesn't check if shape size matches.

ReplaceData(Array, Type)

Set an Array to internal storage, cast it to new dtype and change dtype

public void ReplaceData(Array values, Type dtype)

Parameters

values Array
dtype Type

Remarks

Does not copy values unless cast in necessary and doesn't change shape.

ReplaceData(Array, Type, Shape)

Set an Array to internal storage, cast it to new dtype and change dtype

public void ReplaceData(Array values, Type dtype, Shape shape)

Parameters

values Array
dtype Type
shape Shape

The shape to set in this storage. (without checking if shape matches storage)

Remarks

Does not copy values unless cast in necessary and doesn't change shape. Doesn't check if shape size matches.

Reshape(Shape, bool)

Changes the shape representing this storage.

public void Reshape(Shape newShape, bool @unsafe = false)

Parameters

newShape Shape
unsafe bool

Exceptions

IncorrectShapeException

If shape's size mismatches current shape size.

ArgumentException

If newShape's size == 0

Reshape(ref Shape, bool)

Changes the shape representing this storage.

public void Reshape(ref Shape newShape, bool @unsafe = false)

Parameters

newShape Shape
unsafe bool

Exceptions

IncorrectShapeException

If shape's size mismatches current shape size.

ArgumentException

If newShape's size == 0

Reshape(params long[])

Changes the shape representing this storage.

public void Reshape(params long[] dimensions)

Parameters

dimensions long[]

Exceptions

IncorrectShapeException

If shape's size mismatches current shape size.

Reshape(long[], bool)

Changes the shape representing this storage.

public void Reshape(long[] dimensions, bool @unsafe)

Parameters

dimensions long[]
unsafe bool

Exceptions

IncorrectShapeException

If shape's size mismatches current shape size.

ArgumentException

If dimensions's size == 0

Scalar(object)

public static UnmanagedStorage Scalar(object value)

Parameters

value object

Returns

UnmanagedStorage

Scalar(object, NPTypeCode)

public static UnmanagedStorage Scalar(object value, NPTypeCode typeCode)

Parameters

value object
typeCode NPTypeCode

Returns

UnmanagedStorage

Scalar<T>(T)

public static UnmanagedStorage Scalar<T>(T value) where T : unmanaged

Parameters

value T

Returns

UnmanagedStorage

Type Parameters

T

SetAtIndex(object, long)

public void SetAtIndex(object value, long index)

Parameters

value object
index long

SetAtIndexUnsafe(object, long)

Performs a set of index without calling TransformOffset(long).

public void SetAtIndexUnsafe(object value, long index)

Parameters

value object
index long

SetAtIndexUnsafe<T>(T, long)

Performs a set of index without calling TransformOffset(long).

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

Parameters

value T
index long

Type Parameters

T

SetAtIndex<T>(T, long)

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

Parameters

value T
index long

Type Parameters

T

SetBoolean(bool, int[])

Sets a bool at specific coordinates.

public void SetBoolean(bool value, int[] indices)

Parameters

value bool

The values to assign

indices int[]

The coordinates to set value at.

SetBoolean(bool, params long[])

Sets a bool at specific coordinates.

public void SetBoolean(bool value, params long[] indices)

Parameters

value bool

The values to assign

indices long[]

The coordinates to set value at (long version).

SetByte(byte, int[])

Sets a byte at specific coordinates.

public void SetByte(byte value, int[] indices)

Parameters

value byte

The values to assign

indices int[]

The coordinates to set value at.

SetByte(byte, params long[])

Sets a byte at specific coordinates.

public void SetByte(byte value, params long[] indices)

Parameters

value byte

The values to assign

indices long[]

The coordinates to set value at (long version).

SetChar(char, int[])

Sets a char at specific coordinates.

public void SetChar(char value, int[] indices)

Parameters

value char

The values to assign

indices int[]

The coordinates to set value at.

SetChar(char, params long[])

Sets a char at specific coordinates.

public void SetChar(char value, params long[] indices)

Parameters

value char

The values to assign

indices long[]

The coordinates to set value at (long version).

SetComplex(Complex, int[])

Sets a Complex at specific coordinates.

public void SetComplex(Complex value, int[] indices)

Parameters

value Complex

The values to assign

indices int[]

The coordinates to set value at.

SetComplex(Complex, params long[])

Sets a Complex at specific coordinates.

public void SetComplex(Complex value, params long[] indices)

Parameters

value Complex

The values to assign

indices long[]

The coordinates to set value at (long version).

SetData(IArraySlice, int[])

Set a IArraySlice at given indices.

public void SetData(IArraySlice value, int[] indices)

Parameters

value IArraySlice

The value to set

indices int[]

The

Remarks

Does not change internal storage data type.
If value does not match DType, value will be converted.

SetData(IArraySlice, params long[])

Set a IArraySlice at given indices (long version).

public void SetData(IArraySlice value, params long[] indices)

Parameters

value IArraySlice
indices long[]

SetData(NDArray, int[])

Set a NDArray at given indices.

public void SetData(NDArray value, int[] indices)

Parameters

value NDArray

The value to set

indices int[]

The

Remarks

Does not change internal storage data type.
If value does not match DType, value will be converted.

SetData(NDArray, params long[])

Set a NDArray at given indices (long version).

public void SetData(NDArray value, params long[] indices)

Parameters

value NDArray
indices long[]

SetData(object, int[])

Set a single value at given indices.

public void SetData(object value, int[] indices)

Parameters

value object

The value to set

indices int[]

The

Remarks

Does not change internal storage data type.
If value does not match DType, value will be converted.

SetData(object, params long[])

Set a value at given indices (long version).

public void SetData(object value, params long[] indices)

Parameters

value object
indices long[]

SetDecimal(decimal, int[])

Sets a decimal at specific coordinates.

public void SetDecimal(decimal value, int[] indices)

Parameters

value decimal

The values to assign

indices int[]

The coordinates to set value at.

SetDecimal(decimal, params long[])

Sets a decimal at specific coordinates.

public void SetDecimal(decimal value, params long[] indices)

Parameters

value decimal

The values to assign

indices long[]

The coordinates to set value at (long version).

SetDouble(double, int[])

Sets a double at specific coordinates.

public void SetDouble(double value, int[] indices)

Parameters

value double

The values to assign

indices int[]

The coordinates to set value at.

SetDouble(double, params long[])

Sets a double at specific coordinates.

public void SetDouble(double value, params long[] indices)

Parameters

value double

The values to assign

indices long[]

The coordinates to set value at.

SetHalf(Half, int[])

Sets a Half at specific coordinates.

public void SetHalf(Half value, int[] indices)

Parameters

value Half

The values to assign

indices int[]

The coordinates to set value at.

SetHalf(Half, params long[])

Sets a Half at specific coordinates.

public void SetHalf(Half value, params long[] indices)

Parameters

value Half

The values to assign

indices long[]

The coordinates to set value at (long version).

SetInt16(short, int[])

Sets a short at specific coordinates.

public void SetInt16(short value, int[] indices)

Parameters

value short

The values to assign

indices int[]

The coordinates to set value at.

SetInt16(short, params long[])

Sets a short at specific coordinates.

public void SetInt16(short value, params long[] indices)

Parameters

value short

The values to assign

indices long[]

The coordinates to set value at (long version).

SetInt32(int, int[])

Sets a int at specific coordinates.

public void SetInt32(int value, int[] indices)

Parameters

value int

The values to assign

indices int[]

The coordinates to set value at.

SetInt32(int, params long[])

Sets a int at specific coordinates.

public void SetInt32(int value, params long[] indices)

Parameters

value int

The values to assign

indices long[]

The coordinates to set value at (long version).

SetInt64(long, int[])

Sets a long at specific coordinates.

public void SetInt64(long value, int[] indices)

Parameters

value long

The values to assign

indices int[]

The coordinates to set value at.

SetInt64(long, params long[])

Sets a long at specific coordinates.

public void SetInt64(long value, params long[] indices)

Parameters

value long

The values to assign

indices long[]

The coordinates to set value at (long version).

SetInternalArray(IArraySlice)

Replace internal storage array with given array.

protected void SetInternalArray(IArraySlice array)

Parameters

array IArraySlice

The array to set as internal storage

Exceptions

InvalidCastException

When type of array does not match DType of this storage

SetInternalArray(Array)

Replace internal storage array with given array.

protected void SetInternalArray(Array array)

Parameters

array Array

The array to set as internal storage

Exceptions

InvalidCastException

When type of array does not match DType of this storage

SetSByte(sbyte, int[])

Sets a sbyte at specific coordinates.

public void SetSByte(sbyte value, int[] indices)

Parameters

value sbyte

The values to assign

indices int[]

The coordinates to set value at.

SetSByte(sbyte, params long[])

Sets a sbyte at specific coordinates.

public void SetSByte(sbyte value, params long[] indices)

Parameters

value sbyte

The values to assign

indices long[]

The coordinates to set value at (long version).

SetShapeUnsafe(Shape)

Set the shape of this storage without checking if sizes match.

protected void SetShapeUnsafe(Shape shape)

Parameters

shape Shape

Remarks

Used during broadcasting

SetShapeUnsafe(ref Shape)

Set the shape of this storage without checking if sizes match.

protected void SetShapeUnsafe(ref Shape shape)

Parameters

shape Shape

Remarks

Used during broadcasting. Uses bufferSize (not size) because broadcast shapes have logical size != physical buffer size.

SetSingle(float, int[])

Sets a float at specific coordinates.

public void SetSingle(float value, int[] indices)

Parameters

value float

The values to assign

indices int[]

The coordinates to set value at.

SetSingle(float, params long[])

Sets a float at specific coordinates.

public void SetSingle(float value, params long[] indices)

Parameters

value float

The values to assign

indices long[]

The coordinates to set value at (long version).

SetUInt16(ushort, int[])

Sets a ushort at specific coordinates.

public void SetUInt16(ushort value, int[] indices)

Parameters

value ushort

The values to assign

indices int[]

The coordinates to set value at.

SetUInt16(ushort, params long[])

Sets a ushort at specific coordinates.

public void SetUInt16(ushort value, params long[] indices)

Parameters

value ushort

The values to assign

indices long[]

The coordinates to set value at (long version).

SetUInt32(uint, int[])

Sets a uint at specific coordinates.

public void SetUInt32(uint value, int[] indices)

Parameters

value uint

The values to assign

indices int[]

The coordinates to set value at.

SetUInt32(uint, params long[])

Sets a uint at specific coordinates.

public void SetUInt32(uint value, params long[] indices)

Parameters

value uint

The values to assign

indices long[]

The coordinates to set value at (long version).

SetUInt64(ulong, int[])

Sets a ulong at specific coordinates.

public void SetUInt64(ulong value, int[] indices)

Parameters

value ulong

The values to assign

indices int[]

The coordinates to set value at.

SetUInt64(ulong, params long[])

Sets a ulong at specific coordinates.

public void SetUInt64(ulong value, params long[] indices)

Parameters

value ulong

The values to assign

indices long[]

The coordinates to set value at (long version).

SetValue(object, int[])

Set a single value at given indices.

public void SetValue(object value, int[] indices)

Parameters

value object

The value to set

indices int[]

The

Remarks

Does not change internal storage data type.
If value does not match DType, value will be converted.

SetValue(object, params long[])

Set a single value at given indices.

public void SetValue(object value, params long[] indices)

Parameters

value object

The value to set

indices long[]

The coordinates (long version).

Remarks

Does not change internal storage data type.
If value does not match DType, value will be converted.

SetValue<T>(T, int[])

Set a single value at given indices.

public void SetValue<T>(T value, int[] indices) where T : unmanaged

Parameters

value T

The value to set

indices int[]

The

Type Parameters

T

Remarks

Does not change internal storage data type.
If value does not match DType, value will be converted.

SetValue<T>(T, params long[])

Set a single value at given indices.

public void SetValue<T>(T value, params long[] indices) where T : unmanaged

Parameters

value T

The value to set

indices long[]

The coordinates (long version).

Type Parameters

T

Remarks

Does not change internal storage data type.
If value does not match DType, value will be converted.

ToArray<T>()

public T[] ToArray<T>() where T : unmanaged

Returns

T[]

Type Parameters

T

_Allocate(Shape, IArraySlice)

protected void _Allocate(Shape shape, IArraySlice values)

Parameters

shape Shape
values IArraySlice

_ChangeTypeOfArray(Array, Type)

Changes the type of sourceArray to to_dtype if necessary.

[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
protected static Array _ChangeTypeOfArray(Array sourceArray, Type to_dtype)

Parameters

sourceArray Array

The array to change his type

to_dtype Type

The type to change to.

Returns

Array

Returns sourceArray or new array with changed type to to_dtype

Remarks

If the return type is equal to source type, this method does not return a copy.

_ChangeTypeOfArray<TOut>(IArraySlice)

Changes the type of sourceArray to to_dtype if necessary.

[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
protected static ArraySlice<TOut> _ChangeTypeOfArray<TOut>(IArraySlice sourceArray) where TOut : unmanaged

Parameters

sourceArray IArraySlice

The array to change his type

Returns

ArraySlice<TOut>

Returns sourceArray or new array with changed type to to_dtype

Type Parameters

TOut

Remarks

If the return type is equal to source type, this method does not return a copy.