Class UnmanagedStorage
Serves as a typed storage for an array.
public class UnmanagedStorage : ICloneable
- Inheritance
-
UnmanagedStorage
- Implements
- Inherited Members
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
arraySliceIArraySliceThe slice to wrap
shapeShape
UnmanagedStorage(DType)
Creates an empty storage described by descr — NumPy's PyArray_NewFromDescr entry:
the descriptor IS the array's dtype (Descr), its class supplies the storage lane
(TypeCode) and CLR element type (DType).
public UnmanagedStorage(DType descr)
Parameters
descrDTypeThe dtype descriptor; a non-native byte order is canonicalised (NumSharp buffers are always native).
Remarks
Usually Allocate(Shape, DType, bool) is called after this constructor.
Exceptions
- ArgumentNullException
descris null.- NotSupportedException
The descriptor's class has no storage lane yet (a datetime64/timedelta64 descriptor before Stage C).
UnmanagedStorage(NPTypeCode)
Creates an empty storage of type typeCode.
public UnmanagedStorage(NPTypeCode typeCode)
Parameters
typeCodeNPTypeCodeThe type of this storage
Remarks
Usually Allocate(Shape, Type) is called after this constructor.
UnmanagedStorage(bool)
public UnmanagedStorage(bool scalar)
Parameters
scalarbool
UnmanagedStorage(bool[])
public UnmanagedStorage(bool[] values)
Parameters
valuesbool[]
UnmanagedStorage(byte)
public UnmanagedStorage(byte scalar)
Parameters
scalarbyte
UnmanagedStorage(byte[])
public UnmanagedStorage(byte[] values)
Parameters
valuesbyte[]
UnmanagedStorage(char)
public UnmanagedStorage(char scalar)
Parameters
scalarchar
UnmanagedStorage(char[])
public UnmanagedStorage(char[] values)
Parameters
valueschar[]
UnmanagedStorage(decimal)
public UnmanagedStorage(decimal scalar)
Parameters
scalardecimal
UnmanagedStorage(decimal[])
public UnmanagedStorage(decimal[] values)
Parameters
valuesdecimal[]
UnmanagedStorage(double)
public UnmanagedStorage(double scalar)
Parameters
scalardouble
UnmanagedStorage(double[])
public UnmanagedStorage(double[] values)
Parameters
valuesdouble[]
UnmanagedStorage(short)
public UnmanagedStorage(short scalar)
Parameters
scalarshort
UnmanagedStorage(short[])
public UnmanagedStorage(short[] values)
Parameters
valuesshort[]
UnmanagedStorage(int)
public UnmanagedStorage(int scalar)
Parameters
scalarint
UnmanagedStorage(int[])
public UnmanagedStorage(int[] values)
Parameters
valuesint[]
UnmanagedStorage(long)
public UnmanagedStorage(long scalar)
Parameters
scalarlong
UnmanagedStorage(long[])
public UnmanagedStorage(long[] values)
Parameters
valueslong[]
UnmanagedStorage(float)
public UnmanagedStorage(float scalar)
Parameters
scalarfloat
UnmanagedStorage(float[])
public UnmanagedStorage(float[] values)
Parameters
valuesfloat[]
UnmanagedStorage(Type)
Creates an empty storage of type dtype.
public UnmanagedStorage(Type dtype)
Parameters
dtypeTypeThe type of this storage
Remarks
Usually Allocate(Shape, Type) is called after this constructor.
UnmanagedStorage(ushort)
public UnmanagedStorage(ushort scalar)
Parameters
scalarushort
UnmanagedStorage(ushort[])
public UnmanagedStorage(ushort[] values)
Parameters
valuesushort[]
UnmanagedStorage(uint)
public UnmanagedStorage(uint scalar)
Parameters
scalaruint
UnmanagedStorage(uint[])
public UnmanagedStorage(uint[] values)
Parameters
valuesuint[]
UnmanagedStorage(ulong)
public UnmanagedStorage(ulong scalar)
Parameters
scalarulong
UnmanagedStorage(ulong[])
public UnmanagedStorage(ulong[] values)
Parameters
valuesulong[]
Fields
Address
public byte* Address
Field Value
- byte*
Count
public long Count
Field Value
InternalArray
public IArraySlice InternalArray
Field Value
_descr
The dtype DESCRIPTOR of this storage (NumPy's PyArrayObject.descr) — see Descr.
Lazily resolved from _typecode for the storage-backed builtins (each has exactly one canonical
descriptor, the class singleton), and reset whenever the storage's lane changes (_Allocate(Shape, IArraySlice),
ReplaceData). A parametric descriptor (a future datetime64[ns], whose unit lives on the
instance rather than in the enum) is stored here explicitly and travels with aliases/clones.
protected DType _descr
Field Value
_dtype
protected Type _dtype
Field Value
_shape
protected Shape _shape
Field Value
_typecode
protected NPTypeCode _typecode
Field Value
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
nullfor 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 as stored in the unmanaged buffer.
public int DTypeSize { get; }
Property Value
Remarks
Returns the in-memory element stride, not the marshaling size.
For bool that is 1, not SizeOf(object)'s 4
(bool is marshaled to win32 BOOL = int). All pointer arithmetic
over Address uses this value, so the in-memory layout is
the only correct reference.
Exceptions
- NotSupportedException
This storage holds NEP 55
StringDTypetext. Every caller of this property moves or reinterprets elements as raw bytes of this width, which is never valid for aStringDTypecell (an arena offset or a heap pointer that only its own buffer's allocator can read), so the property refuses: a route without itsStringDTypeform fails loudly instead of copying cells. Code that only needs the descriptor's item size (strides in bytes,nbytes, overlap bounds) reads ItemBytes.
Descr
The dtype DESCRIPTOR of this storage — NumPy's PyArrayObject.descr, the object ndarray.dtype
returns. For the storage-backed builtins this is the class's canonical instance
(np.dtype("int32") for an Int32 lane — the same object every time, so
a.dtype == b.dtype is a cheap structural compare); a parametric descriptor is carried explicitly.
DType (the CLR element Type) and TypeCode stay the kernel
currency — the descriptor is the identity, they are its storage keys.
public DType Descr { get; }
Property Value
Engine
The engine that was used to create this UnmanagedStorage.
public TensorEngine Engine { get; protected set; }
Property Value
ExternalBase
Set when this storage's memory belongs to a FOREIGN owner even though no
NumSharp.Backends.UnmanagedStorage._baseStorage exists — a memory-mapped file (every mmap_mode, the file
mapping is the real owner), or an external buffer wrap. It is the NumPy analog of a
non-array base object: such arrays report flags.owndata == False (NumPy's
memmap does, in every mode) and np.require(…, "O") copies them.
public bool ExternalBase { get; }
Property Value
Remarks
Orthogonal to WriteProtected: an 'r+' memmap is externally based
yet writable; an 'r' memmap is both. Readable by everyone, set only inside NumSharp when the storage is
created: the shape's cached OWNDATA bit is computed from it then, so a later change would leave
flags.owndata stale.
IsDataAligned
Is every element of this storage's array aligned for its dtype — the memory half of NumPy's
ALIGNED flag (raw_array_is_aligned, numpy/_core/src/common/array_assign.c), which
NumPy recomputes for every new array object. flags reports aligned only when
this holds AND the shape's ALIGNED bit (cleared by setflags(align=False))
is set; setflags(align=True) refuses when it does not hold.
public bool IsDataAligned { get; }
Property Value
Remarks
NumPy ORs the data pointer with the byte stride of every axis longer than 1 and tests the low bits. NumSharp's offsets and strides are whole elements, and every dtype's itemsize is a multiple of its alignment, so those terms never add a misaligned bit: the storage's base address alone decides. An empty array is always aligned, as in NumPy.
NumSharp's own allocations are always aligned. Misaligned data comes from a caller's buffer at an odd
byte offset (np.ndarray(shape, buffer=b, offset=3), np.frombuffer(b, offset=3)) or a field
view at an odd byte offset (getfield), and every view of such an array shares its address, so the
flag follows to every view without each view path computing it.
Recomputed on every read (one address test), so it follows the storage as it is now.
IsFixedString
True when this storage holds fixed-width strings (S or U, a StringArraySlice).
public bool IsFixedString { get; }
Property Value
IsString
True when this storage holds TEXT — the String lane, shared by the fixed-width strings
(S, U: a StringArraySlice) and NEP 55 StringDType (T: a
VStringArraySlice). The two layouts
have nothing in common below the lane: test IsFixedString / IsVString (or the
descriptor's class) before reading elements as bytes.
public bool IsString { get; }
Property Value
Remarks
A route that branches on this property and then treats the elements as fixed-width units reaches
StringSlice, which refuses a StringDType storage with a clear
NotSupportedException: every text operation has its own StringDType route (tested with
IsVString first), so a T storage that gets here is a route that skipped that test, and it
fails loudly instead of copying cells that are meaningless without their own allocator.
IsVString
True when this storage holds NEP 55 StringDType text (T, a VStringArraySlice).
public bool IsVString { get; }
Property Value
IsView
Gets a value indicating whether this storage is a view of another storage.
public bool IsView { get; }
Property Value
- bool
trueif this storage shares memory with another storage (does not own its data);falseif 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
ItemBytes
The descriptor's item size in bytes (NumPy's dtype.itemsize) for every storage: DTypeSize
for the numeric and fixed-width string lanes, and 16 (one packed cell) for a NEP 55 StringDType storage.
public int ItemBytes { get; }
Property Value
Remarks
Use it for byte ARITHMETIC that never moves an element (byte strides, nbytes, the extent of a view for an
overlap test). A route that copies or reinterprets elements must read DTypeSize, which refuses a
StringDType storage.
OwnsData
Does this storage own the memory it addresses — NumPy's OWNDATA: no base storage
(NumSharp.Backends.UnmanagedStorage._baseStorage) and no foreign owner (ExternalBase). Read by
ndarray.flags.owndata and np.require("O").
public bool OwnsData { get; }
Property Value
Remarks
Answers for the storage object itself: a view's storage reports false even when the array it views
owns its buffer.
Shape
The shape representing the data in this storage.
public Shape Shape { get; set; }
Property Value
ShapeReference
The shape representing the data in this storage.
public ref Shape ShapeReference { get; }
Property Value
Remarks
It is dangerous to set Shape by reference. use Reshape(Shape) instead.
StringSlice
The StringArraySlice of a fixed-width string storage (null for a numeric lane) — the bytes plus the element width they are read with.
public StringArraySlice StringSlice { get; }
Property Value
Remarks
The slice covers the whole buffer: a view's elements start at its Shape's offset and follow its strides, both counted in elements of the slice's width.
Exceptions
- NotSupportedException
This storage holds
StringDTypetext: every caller of this property is a fixed-width route (unit views, the byte codec, width arithmetic), andStringDTypetext takes its own routes (VStringSlice), so it refuses here rather than reading the 16-byte cells as fixed-width text.
TypeCode
The NPTypeCode of DType.
public NPTypeCode TypeCode { get; }
Property Value
VStringSlice
The VStringArraySlice of a StringDType storage (null for every other storage).
public VStringArraySlice VStringSlice { get; }
Property Value
Remarks
The route from an array to its texts: .Cells are the 16-byte cells of the whole buffer (a view's
elements start at its Shape's offset), and .Allocator is the one allocator that may read or
write them.
WriteProtected
Set when this storage wraps FOREIGN memory that must never become writeable — a read-only
memory-mapped file (np.load(mmap_mode: "r")), or a buffer whose exporter declared it
read-only (np.frombuffer over a read-only MemoryView). It is the gate
NumPy expresses through the buffer protocol (its _IsWriteable asks the non-array base
for a writable buffer and a read-only exporter refuses): without it,
setflags(write: true) on an 'r' memmap would re-enable WRITEABLE and the next
write would reach PROT_READ pages — an access violation, not an exception.
public bool WriteProtected { get; }
Property Value
Remarks
Ordinary owned allocations and ordinary views never set this; a cleared WRITEABLE flag alone
(e.g. a.flags.writeable = false on your own array) is reversible and does NOT imply it.
It answers only that question: whether a cleared WRITEABLE flag may be set again. It does not block a
write while the flag is set. So np.nditer's views carry it too, writeable ones included
(NDIterRef.CurrentView): their NumPy base is the iterator, an object that exports no buffer at all,
so a write flag cleared on one cannot be set again.
Readable by everyone, set only inside NumSharp (where the storage over the foreign memory is created): clearing it on a read-only mapping would let the next write reach PROT_READ pages.
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
shapeShapeThe 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
shapeShapeThe 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
typeCodeNPTypeCodeThe 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
dtypeTypeThe 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 —
the storage half of NumPy's ndarray.view(dtype).
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
TThe 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.
Same itemsize: The dtype tag changes and the shape, strides and offset are kept verbatim, so ANY layout works (C/F-contiguous, sliced, strided, transposed, negative-stride, broadcast, 0-d). A read-only source (broadcast) stays read-only.
Different itemsize (NumPy 2.x rule): only the LAST axis must be contiguous
(byte-stride == old itemsize) — the whole array need NOT be C-contiguous. That last axis is
resized by the size ratio while every outer axis keeps its byte stride, so
a[::2].view(...) and other outer-strided/offset views are supported, matching NumPy.
Read-only (broadcast) sources stay read-only.
Exceptions
- ValueError
NumPy's errors with NumPy's texts (ReinterpretShape(int, int, out long)): a 0-d array whose itemsize changes, a non-contiguous last axis, a smaller dtype that does not divide the old itemsize, a larger one that does not divide the last axis' byte length.
- InvalidOperationException
NumSharp stores strides/offset in ELEMENTS rather than bytes, so the rare strided+offset view whose byte offset/stride is not a whole multiple of the new itemsize is refused (NumPy, which carries a byte pointer, would allow it).
AliasComplexLane(bool)
Creates a double (float64) VIEW onto one lane — real or imaginary — of a
Complex storage, reproducing NumPy's a.real / a.imag:
a strided float64 view that SHARES memory (and writeability) with the Complex base.
public UnmanagedStorage AliasComplexLane(bool imaginary)
Parameters
imaginaryboolfalseselects the real lane,truethe imaginary lane.
Returns
- UnmanagedStorage
A float64 UnmanagedStorage aliasing this storage's chosen lane. Writes through to the Complex base; the base's buffer is kept alive by the lane's counted reference on the base's block (WrapShared<T>(void*, long, IArraySlice)) — disposing the base while the lane lives does not free it — and the base object by
_baseStorage.
Remarks
A Complex is two consecutive float64s (real, then imaginary),
laid out exactly like NumPy's complex128. A lane is therefore a plain strided float64
view: every Complex element stride is doubled (a Complex spans two float64s) and the base
offset is doubled, plus one for the imaginary lane. This works for EVERY layout
(contiguous / F-contiguous / transposed / strided / negative-stride / sliced-offset /
broadcast), because it operates on the raw contiguous backing buffer and mirrors whatever
strides/offset the Complex shape carries — the same strided-lane read the FFT driver uses.
A lane of a read-only Complex (a broadcast view, or an 'r' memmap) stays read-only.
Exceptions
- InvalidOperationException
If this storage is not a Complex storage.
Allocate(IArraySlice, Shape, bool)
Makes values this storage's data and installs shape's layout over it AS
GIVEN — strides, offset and flags included. This is the analog of NumPy's C API
(PyArray_NewFromDescr with a data pointer and strides, where the caller is responsible for correctness),
not of the Python-level np.ndarray(shape, buffer=...).
public void Allocate(IArraySlice values, Shape shape, bool copy = false)
Parameters
valuesIArraySliceThe buffer to adopt as this storage's data.
shapeShapeThe exact layout to install. Every element it addresses must lie inside
values; nothing here checks that.copyboolTrue to adopt a clone of
valuesinstead of the slice itself.
Remarks
Does not copy values unless copy is true.
A view's layout installed here reads past the buffer: for x = arange(20)["::4"],
Allocate(fiveElements, x.Shape) reads element i at i * 4. The public wrap constructors
(new NDArray(IArraySlice, Shape, char), new NDArray(Array, Shape, char)) therefore lay out the
dimensions afresh first (ForWrappedBuffer(char)), as NumPy's ndarray does, and only pass
a layout they built.
Exceptions
- ArgumentNullException
shapeis uninitialized (default(Shape)).- ArgumentException
The element count of
valuesis not the size ofshape.
Allocate(Shape, DType, bool)
Allocates a new Array into memory described by a dtype DESCRIPTOR (NumPy's
PyArray_NewFromDescr): the descriptor becomes Descr, its class supplies the lane.
public void Allocate(Shape shape, DType dtype, bool fillZeros)
Parameters
shapeShapeThe dimensions to allocate. Only a fresh layout (C, F or a dense permutation at offset 0) is kept; a view's layout is re-laid out in C order (NumSharp.Shape.ForFreshAllocation()), which is what makes
new NDArray(dtype, x.Shape),np.empty(x.Shape)andnp.zeros(x.Shape)safe for a viewx.dtypeDTypeThe dtype descriptor of the array; a non-native byte order is canonicalised (NumSharp buffers are always native).
fillZerosboolZero the fresh buffer, else leave the allocation noise.
Exceptions
- ArgumentNullException
shapeis uninitialized, ordtypeis null.- NotSupportedException
The descriptor's class has no storage lane yet (a datetime64/timedelta64 descriptor before Stage C).
- ValueError
A dimension is negative, or the byte count overflows (NumSharp.AllocationGuard).
Allocate(Shape, NPTypeCode, bool)
Allocates a new buffer for shape's dimensions and makes it this storage's data — NumPy's
PyArray_NewFromDescr with no data pointer.
public void Allocate(Shape shape, NPTypeCode dtype, bool fillZeros)
Parameters
shapeShapeThe dimensions to allocate. Only a fresh layout (C, F or a dense permutation at offset 0) is kept; a view's layout is re-laid out in C order (NumSharp.Shape.ForFreshAllocation()).
dtypeNPTypeCodeThe storage lane to allocate.
fillZerosboolZero the fresh buffer, else leave the allocation noise (the caller writes every element).
Exceptions
- ArgumentNullException
shapeis uninitialized, ordtypeis Empty.- NotSupportedException
dtypeis String and this storage has no string descriptor to keep (the lane alone names no width; see From(NPTypeCode)).- ValueError
A dimension is negative, or the byte count overflows (NumSharp.AllocationGuard).
Allocate(Shape, Type)
Allocates a new, zero-filled buffer for shape's dimensions and makes it this storage's
data — NumPy's PyArray_NewFromDescr with no data pointer.
public void Allocate(Shape shape, Type dtype = null)
Parameters
shapeShapeThe dimensions to allocate. Only a fresh layout (C, F or a dense permutation at offset 0) is kept; a view's layout (stepped, offset, reversed, broadcast) is re-laid out in C order (NumSharp.Shape.ForFreshAllocation()), so
Allocate(x.Shape)of a view never addresses past the new buffer.dtypeTypeThe type of the Array, if null DType is used.
Exceptions
- ArgumentNullException
shapeis uninitialized (default(Shape)).- ValueError
A dimension is negative, or the byte count overflows (NumSharp.AllocationGuard).
Allocate(Shape, Type, bool)
Allocates a new buffer for shape's dimensions and makes it this storage's data — NumPy's
PyArray_NewFromDescr with no data pointer.
public void Allocate(Shape shape, Type dtype, bool fillZeros)
Parameters
shapeShapeThe dimensions to allocate. Only a fresh layout (C, F or a dense permutation at offset 0) is kept; a view's layout is re-laid out in C order (NumSharp.Shape.ForFreshAllocation()).
dtypeTypeThe type of the Array, if null DType is used.
fillZerosboolZero the fresh buffer, else leave the allocation noise (the caller writes every element).
Exceptions
- ArgumentNullException
shapeis uninitialized (default(Shape)).- ValueError
A dimension is negative, or the byte count overflows (NumSharp.AllocationGuard).
Allocate(Array)
Allocate array into memory.
public void Allocate(Array array)
Parameters
arrayArrayThe 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
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
valuesArraySlice<T>The array to set as internal data storage
shapeShapeThe shape of the array.
copyboolShould 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
valuesT[]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
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
typeCodeNPTypeCodeThe 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
dtypeTypeThe 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
typeCodeNPTypeCodeThe 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
dtypeTypeThe 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
TThe 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
TThe 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
Remarks
If shape is sliced, discards any slicing properties but copies only the sliced data
CloneData()
Clone internal storage and return an owning IArraySlice
sized to _shape.size (NOT InternalArray.Count).
public IArraySlice CloneData()
Returns
- IArraySlice
A freshly-allocated IArraySlice whose
Count == _shape.size. For contiguous shapes the elements come fromInternalArray[_shape.offset.._shape.offset + _shape.size)via Slice(long, long) + Clone; for strided / broadcast / transposed shapes they are materialised via Copy(NDArray, NDArray).
Remarks
Subtle: the C-contig branch must always slice to
_shape.size when _shape.bufferSize > _shape.size,
even when offset == 0. A 1-D slice like
arr[0:4] on a 5-element source has offset 0 yet covers
only the first 4 elements; a previous version unconditionally
cloned the entire InternalArray in the offset == 0
branch, then handed the 5-element clone to UnmanagedStorage(IArraySlice, Shape)
paired with a (4,) shape, tripping
IncorrectShapeException.
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
Tcloned storgae dtype
CopyTo(IMemoryBlock)
Copies the entire contents of this storage to given address (using Count).
public void CopyTo(IMemoryBlock block)
Parameters
blockIMemoryBlockThe block to copy to.
CopyTo(nint)
Copies the entire contents of this storage to given address.
public void CopyTo(nint ptr)
Parameters
ptrnint
CopyTo(void*)
Copies the entire contents of this storage to given address.
public void CopyTo(void* address)
Parameters
addressvoid*The address to copy to; it must hold
Count * DTypeSizebytes.
Remarks
A fixed-width string storage copies its raw element bytes (DTypeSize each: NUL-padded ASCII
for S, UCS-4 code units for U) in C order — the bytes tobytes() returns.
Exceptions
- ArgumentNullException
addressis null.
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
blockIMemoryBlock<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
addressT*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
arrayT[]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
arraySliceIArraySliceThe array slice to wrap.
shapeShapeThe 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
storageUnmanagedStorageThe source storage to take InternalArray from.
shapeShapeThe 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
axisint
GetAtIndex(long)
Reads the element at logical flat index index (C order) boxed as the dtype's own CLR
type, after NumPy's flat-index check (a.item(i), a.flat[i]).
public object GetAtIndex(long index)
Parameters
indexlongThe flat index; a negative one counts from the end of the array.
Returns
- object
The element, boxed.
Exceptions
- IndexError
indexis outside the array (NumPy's item texts).- NotSupportedException
The storage has no element type.
GetAtIndex<T>(long)
Reads the element at logical flat index index (C order) as T: the
stored value for the dtype's own type, NumPy's cast of it for any other T.
public T GetAtIndex<T>(long index) where T : unmanaged
Parameters
indexlongThe flat index; a negative one counts from the end of the array.
Returns
- T
The element as
T.
Type Parameters
TThe type to read the element as.
Remarks
Before parity QA-12 / QA-33 this loaded sizeof(T) bytes at an unchecked offset (a Debug.Assert
was the only type test), so a wrong T or index read neighbouring elements or memory
past the buffer in Release.
Exceptions
- IndexError
indexis outside the array (NumPy's item texts).- NotSupportedException
The storage has no element type.
GetBoolean(int[])
Reads the element at indices as a bool: the stored value itself in a
bool array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public bool GetBoolean(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetBoolean(params long[])
Reads the element at indices as a bool: the stored value itself in a
bool array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public bool GetBoolean(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetByte(int[])
Reads the element at indices as a byte: the stored value itself in a
uint8 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public byte GetByte(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetByte(params long[])
Reads the element at indices as a byte: the stored value itself in a
uint8 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public byte GetByte(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetChar(int[])
Reads the element at indices as a char: the stored value itself in a
char array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public char GetChar(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetChar(params long[])
Reads the element at indices as a char: the stored value itself in a
char array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public char GetChar(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetComplex(int[])
Reads the element at indices as a Complex: the stored value itself in a
complex128 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public Complex GetComplex(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetComplex(params long[])
Reads the element at indices as a Complex: the stored value itself in a
complex128 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public Complex GetComplex(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
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
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
indicesint[]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
dimslong*Pointer to an array of long dimension indices.
ndimsintThe number of indices in the array.
Returns
- UnmanagedStorage
A new UnmanagedStorage representing the sub-array.
- See Also
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
indiceslong[]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
Tnew storage data type
Remarks
Copies if T does not equal to DType or if Shape is sliced.
GetDecimal(int[])
Reads the element at indices as a decimal: the stored value itself in a
decimal array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public decimal GetDecimal(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetDecimal(params long[])
Reads the element at indices as a decimal: the stored value itself in a
decimal array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public decimal GetDecimal(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetDouble(int[])
Reads the element at indices as a double: the stored value itself in a
float64 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public double GetDouble(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetDouble(params long[])
Reads the element at indices as a double: the stored value itself in a
float64 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public double GetDouble(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetFieldAlias(NPTypeCode, int)
Dtype-code dispatcher for GetFieldAlias<T>(int) — mirrors AliasAs(NPTypeCode).
public UnmanagedStorage GetFieldAlias(NPTypeCode typeCode, int offset)
Parameters
typeCodeNPTypeCodeThe field dtype to read.
offsetintByte offset of the field within each element.
Returns
GetFieldAlias<T>(int)
Builds a byte-reinterpreting VIEW of one field of each element — the storage half of
NumPy's ndarray.getfield(dtype, offset) (numpy/_core/src/multiarray/methods.c,
PyArray_GetField). Unlike AliasAs<T>() (view(dtype), which rescales
the last axis), this keeps EVERY byte-stride and dimension verbatim and simply reads
T out of the offset-th byte of each element.
public UnmanagedStorage GetFieldAlias<T>(int offset) where T : unmanaged
Parameters
offsetintByte offset of the field within each element;
[0, oldItemsize - newItemsize].
Returns
- UnmanagedStorage
A new UnmanagedStorage of dtype
Tthat SHARES memory with this storage (writes through, unless the source is read-only). The base is rooted through_baseStorageso the shared buffer outlives the view.
Type Parameters
TThe field dtype to read; its itemsize must be ≤ this storage's itemsize.
Remarks
Byte-strides are preserved. NumPy carries strides in bytes; the getfield view keeps
them unchanged, so a C-contiguous int32[4] field-viewed as int16 stays strided
(byte-stride 4, itemsize 2 → non-contiguous), reading the low or high half of each int32.
NumSharp stores strides in ELEMENTS, so each is recomputed as oldByteStride / newItemsize
— always exact, because every NumSharp itemsize (1/2/4/8/16) divides every larger one, so an
old byte-stride (a whole multiple of the old itemsize) is always a whole multiple of the new.
Sub-element byte offset. When offset is not a multiple of the new
itemsize (e.g. int32.getfield(int16, 1)), the logical element start falls mid-element,
which the element-granular offset cannot express. The remainder
r = offset % newItemsize is absorbed into the WRAP POINTER (shifted by r bytes)
while offset carries the aligned part — so EVERY offset in range is
representable, matching NumPy's raw byte pointer.
Contiguity flags are recomputed from the resulting strides (NumPy does the same — a same-size
field of a C-contiguous array stays C-contiguous, a narrower one does not). A read-only source
(broadcast view, 'r' memmap) yields a read-only field view.
Exceptions
- ValueError
new type is larger than original type(newItemsize > oldItemsize),offset is negative, ornew type plus offset is larger than original type(offset > oldItemsize − newItemsize) — the three verbatim NumPyValueErrortexts, in NumPy's check order.
GetHalf(int[])
Reads the element at indices as a Half: the stored value itself in a
float16 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public Half GetHalf(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetHalf(params long[])
Reads the element at indices as a Half: the stored value itself in a
float16 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public Half GetHalf(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetInt16(int[])
Reads the element at indices as a short: the stored value itself in a
int16 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public short GetInt16(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetInt16(params long[])
Reads the element at indices as a short: the stored value itself in a
int16 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public short GetInt16(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetInt32(int[])
Reads the element at indices as a int: the stored value itself in a
int32 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public int GetInt32(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetInt32(params long[])
Reads the element at indices as a int: the stored value itself in a
int32 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public int GetInt32(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetInt64(int[])
Reads the element at indices as a long: the stored value itself in a
int64 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public long GetInt64(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetInt64(params long[])
Reads the element at indices as a long: the stored value itself in a
int64 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public long GetInt64(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetSByte(int[])
Reads the element at indices as a sbyte: the stored value itself in a
int8 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public sbyte GetSByte(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetSByte(params long[])
Reads the element at indices as a sbyte: the stored value itself in a
int8 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public sbyte GetSByte(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetSingle(int[])
Reads the element at indices as a float: the stored value itself in a
float32 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public float GetSingle(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetSingle(params long[])
Reads the element at indices as a float: the stored value itself in a
float32 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public float GetSingle(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetUInt16(int[])
Reads the element at indices as a ushort: the stored value itself in a
uint16 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public ushort GetUInt16(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetUInt16(params long[])
Reads the element at indices as a ushort: the stored value itself in a
uint16 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public ushort GetUInt16(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetUInt32(int[])
Reads the element at indices as a uint: the stored value itself in a
uint32 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public uint GetUInt32(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetUInt32(params long[])
Reads the element at indices as a uint: the stored value itself in a
uint32 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public uint GetUInt32(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetUInt64(int[])
Reads the element at indices as a ulong: the stored value itself in a
uint64 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public ulong GetUInt64(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetUInt64(params long[])
Reads the element at indices as a ulong: the stored value itself in a
uint64 array, NumPy's cast of it (the cast astype runs) in an array of any other dtype.
public ulong GetUInt64(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
GetValue(int[])
Reads the element at indices boxed as the dtype's own CLR type (a text element as its
decoded C# value), after NumPy's coordinate check — the read behind item(i, j, …).
public object GetValue(int[] indices)
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
- object
The element, boxed.
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
- NotSupportedException
The storage has no element type.
GetValue(params long[])
Reads the element at indices boxed as the dtype's own CLR type (a text element as its
decoded C# value), after NumPy's coordinate check — the read behind item(i, j, …).
public object GetValue(params long[] indices)
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
- object
The element, boxed.
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
- NotSupportedException
The storage has no element type.
GetValue<T>(int[])
Reads the element at indices as T: the stored value for the
dtype's own type, NumPy's cast of it (the cast astype runs) for any other T.
public T GetValue<T>(int[] indices) where T : unmanaged
Parameters
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
- T
The element as
T.
Type Parameters
TThe type to read the element as.
Remarks
Before parity QA-12 / QA-33 this loaded sizeof(T) bytes at an unchecked offset: GetValue<double>(1)
of a float32 array read elements 1 and 2 as one double, and a wrong coordinate read another row or memory
outside the array in Release.
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
- NotSupportedException
The storage has no element type.
GetValue<T>(params long[])
Reads the element at indices as T: the stored value for the
dtype's own type, NumPy's cast of it (the cast astype runs) for any other T.
public T GetValue<T>(params long[] indices) where T : unmanaged
Parameters
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out read their first element.
Returns
- T
The element as
T.
Type Parameters
TThe type to read the element as.
Remarks
See GetValue<T>(int[]).
Exceptions
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is read).
- NotSupportedException
The storage has no element type.
GetView(params Slice[])
public UnmanagedStorage GetView(params Slice[] slices)
Parameters
slicesSlice[]
Returns
GetView(string)
public UnmanagedStorage GetView(string slicing_notation)
Parameters
slicing_notationstring
Returns
OnReshaped()
Post-transition hook — run after this storage's _shape is (re)assigned or its
ownership links (NumSharp.Backends.UnmanagedStorage._baseStorage / ExternalBase) change. Reconciles
the shape's OWNDATA bit with OwnsData — the NumSharp
analog of NumPy's PyArray_NewFromDescr_int
(ctors.c: fa->flags |= NPY_ARRAY_OWNDATA when it allocates,
fa->flags &= ~NPY_ARRAY_OWNDATA when data is passed in) plus the invariant
NumPy asserts in _IsWriteable (common.c): base != NULL ⟹ !OWNDATA.
protected void OnReshaped()
Remarks
Must be called wherever ownership or _shape transitions: at the end of every
allocating constructor / _Allocate(Shape, IArraySlice), after every NumSharp.Backends.UnmanagedStorage._baseStorage
assignment (views borrow the parent's shape, which carries the parent's bit), after
ExternalBase is raised, and in SetShapeUnsafe(ref Shape) /
the ReplaceData family (freshly built shapes never carry the bit, which would
silently strip it from an owner).
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
valuesIArraySlice
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
valuesIArraySliceshapeShapeThe 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
valuesIArraySlicedtypeType
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
valuesIArraySlicedtypeTypeshapeShapeThe 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
ndNDArray
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
ndNDArrayshapeShapeThe 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
valuesArray
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
valuesArraytypeCodeNPTypeCode
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
valuesArraytypeCodeNPTypeCodeshapeShapeThe 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
valuesArrayshapeShapeThe 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
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
valuesArraydtypeTypeshapeShapeThe 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
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
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
dimensionslong[]
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
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
valueobject
Returns
Scalar(object, NPTypeCode)
public static UnmanagedStorage Scalar(object value, NPTypeCode typeCode)
Parameters
valueobjecttypeCodeNPTypeCode
Returns
Scalar<T>(T)
public static UnmanagedStorage Scalar<T>(T value) where T : unmanaged
Parameters
valueT
Returns
Type Parameters
T
SetAtIndex(object, long)
Writes one boxed element at a logical flat index (resolved through the shape's strides and offset). The
value must be the dtype's exact CLR type — an explicit unboxing, never a conversion — except null,
which is Python's None and stores what NumPy's setitem stores for it.
public void SetAtIndex(object value, long index)
Parameters
valueobjectThe element, boxed as this storage's exact type;
nullisNone(NaN for a float dtype,nan+nanjfor complex,Falsefor bool,'None'or aStringDTypeNA object for text).indexlongThe logical flat index (C order); a negative one counts from the end of the array.
Exceptions
- ValueError
The storage is read-only (
assignment destination is read-only), orNoneinto aStringDType(coerce=False)storage.- TypeError
Noneinto an integer ordecimalstorage (Python'sint(None)).- InvalidCastException
A non-null value that is not the dtype's exact CLR type.
- IndexError
indexis outside the array (NumPy's item texts; nothing is written).
SetAtIndexUnsafe(object, long)
Performs a set of index without calling TransformOffset(long).
public void SetAtIndexUnsafe(object value, long index)
Parameters
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
valueTindexlong
Type Parameters
T
SetAtIndex<T>(T, long)
Stores value at logical flat index index (C order): as it is for the
dtype's own type, cast to the dtype with NumPy's cast for any other T.
public void SetAtIndex<T>(T value, long index) where T : unmanaged
Parameters
valueTThe value to store.
indexlongThe flat index; a negative one counts from the end of the array.
Type Parameters
TThe value's type.
Remarks
Before parity QA-12 / QA-33 this stored sizeof(T) raw bytes at an unchecked offset: a double into a
float32 array overwrote two elements, and its last element four bytes past the buffer, in Release.
Exceptions
- ValueError
The storage is read-only (
assignment destination is read-only).- IndexError
indexis outside the array (NumPy's item texts; nothing is written).- NotSupportedException
The storage has no element type.
SetBoolean(bool, int[])
Stores value at indices: as it is in a bool array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a bool scalar).
public void SetBoolean(bool value, int[] indices)
Parameters
valueboolThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetBoolean(bool, params long[])
Stores value at indices: as it is in a bool array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a bool scalar).
public void SetBoolean(bool value, params long[] indices)
Parameters
valueboolThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetByte(byte, int[])
Stores value at indices: as it is in a uint8 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a uint8 scalar).
public void SetByte(byte value, int[] indices)
Parameters
valuebyteThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetByte(byte, params long[])
Stores value at indices: as it is in a uint8 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a uint8 scalar).
public void SetByte(byte value, params long[] indices)
Parameters
valuebyteThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetChar(char, int[])
Stores value at indices: as it is in a char array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a char scalar).
public void SetChar(char value, int[] indices)
Parameters
valuecharThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetChar(char, params long[])
Stores value at indices: as it is in a char array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a char scalar).
public void SetChar(char value, params long[] indices)
Parameters
valuecharThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetComplex(Complex, int[])
Stores value at indices: as it is in a complex128 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a complex128 scalar).
public void SetComplex(Complex value, int[] indices)
Parameters
valueComplexThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetComplex(Complex, params long[])
Stores value at indices: as it is in a complex128 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a complex128 scalar).
public void SetComplex(Complex value, params long[] indices)
Parameters
valueComplexThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetData(IArraySlice, int[])
Set a IArraySlice at given indices.
public void SetData(IArraySlice value, int[] indices)
Parameters
valueIArraySliceThe value to set
indicesint[]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
valueIArraySliceindiceslong[]
SetData(NDArray, int[])
Set a NDArray at given indices.
public void SetData(NDArray value, int[] indices)
Parameters
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted:
an array is CAST (NumPy's unsafe assignment cast), a C# literal (NumSharp.NDArray.WasPythonLiteral) is
PACKED as the Python scalar it stands for (PackForStore(object)).
Exceptions
- OverflowError
A C# literal out of this dtype's range (NumPy's OverflowError texts).
- ValueError
A float NaN literal into an integer dtype, a sequence into one element, or a value that does not broadcast to the selection.
- TypeError
A complex literal into a real dtype;
None(a nullvalue) into an integer ordecimalstorage — Python'sint(None)text, raised after the coordinates' bounds check (a[10] = Noneon a 4-element array is NumPy's IndexError) and for an empty selection too. A null is Python'sNoneeverywhere: a float storage stores NaN (NumPy's positiveNPY_NAN), complexnan+nanj, boolFalse, a NEP 55StringDTypestorage its NA object or'None', and a fixed-width text storage'None', truncated to its width.- ValueError
Noneinto aStringDType(coerce=False)storage.
SetData(NDArray, params long[])
Set a NDArray at given indices (long version).
public void SetData(NDArray value, params long[] indices)
Parameters
valueNDArrayThe value; null is Python's
None: a float storage stores NaN, complexnan+nanj, boolFalse, a NEP 55StringDTypestorage its NA object or'None', a fixed-width one'None', truncated; an integer storage raisesint(None)'s TypeError.indiceslong[]The leading coordinates.
Exceptions
- OverflowException
A coordinate outside the
intrange.- Exception
The SetData(NDArray, int[]) overload's errors.
SetData(object, int[])
Sets the element or sub-array at indices from value: an array-like
value goes through SetData(NDArray, int[]), a boxed scalar is stored at the element the
coordinates address.
public void SetData(object value, int[] indices)
Parameters
valueobjectAn NDArray, an IArraySlice, a C# array, a boxed scalar of the dtype's exact CLR type, or
null— Python'sNone.indicesint[]The leading coordinates; a negative coordinate counts from the end of its axis.
Remarks
Does not change the storage's dtype. A boxed scalar is unboxed as the dtype's exact type, never converted (see SetValue(object, int[])).
Exceptions
- ValueError
The storage is read-only, or
Noneinto aStringDType(coerce=False)storage.- TypeError
None(a nullvalue) into an integer ordecimalstorage, raised after the coordinates' bounds check (SetData(NDArray, int[])).- InvalidCastException
A boxed scalar that is not the dtype's exact CLR type.
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing is written).
SetData(object, params long[])
Set a value at given indices (long version).
public void SetData(object value, params long[] indices)
Parameters
valueobjectAn NDArray, an IArraySlice, a C# array, a boxed scalar, or
null— Python'sNone(see SetData(NDArray, int[])).indiceslong[]The leading coordinates.
Exceptions
- ValueError
The storage is read-only, or
Noneinto aStringDType(coerce=False)storage.- TypeError
Noneinto an integer ordecimalstorage.- InvalidCastException
A boxed scalar that is not the dtype's exact CLR type.
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing is written).
SetDecimal(decimal, int[])
Stores value at indices: as it is in a decimal array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a decimal scalar).
public void SetDecimal(decimal value, int[] indices)
Parameters
valuedecimalThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetDecimal(decimal, params long[])
Stores value at indices: as it is in a decimal array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a decimal scalar).
public void SetDecimal(decimal value, params long[] indices)
Parameters
valuedecimalThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetDouble(double, int[])
Stores value at indices: as it is in a float64 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a float64 scalar).
public void SetDouble(double value, int[] indices)
Parameters
valuedoubleThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetDouble(double, params long[])
Stores value at indices: as it is in a float64 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a float64 scalar).
public void SetDouble(double value, params long[] indices)
Parameters
valuedoubleThe value to store.
indiceslong[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetHalf(Half, int[])
Stores value at indices: as it is in a float16 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a float16 scalar).
public void SetHalf(Half value, int[] indices)
Parameters
valueHalfThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetHalf(Half, params long[])
Stores value at indices: as it is in a float16 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a float16 scalar).
public void SetHalf(Half value, params long[] indices)
Parameters
valueHalfThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetInt16(short, int[])
Stores value at indices: as it is in a int16 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a int16 scalar).
public void SetInt16(short value, int[] indices)
Parameters
valueshortThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetInt16(short, params long[])
Stores value at indices: as it is in a int16 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a int16 scalar).
public void SetInt16(short value, params long[] indices)
Parameters
valueshortThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetInt32(int, int[])
Stores value at indices: as it is in a int32 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a int32 scalar).
public void SetInt32(int value, int[] indices)
Parameters
valueintThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetInt32(int, params long[])
Stores value at indices: as it is in a int32 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a int32 scalar).
public void SetInt32(int value, params long[] indices)
Parameters
valueintThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetInt64(long, int[])
Stores value at indices: as it is in a int64 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a int64 scalar).
public void SetInt64(long value, int[] indices)
Parameters
valuelongThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetInt64(long, params long[])
Stores value at indices: as it is in a int64 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a int64 scalar).
public void SetInt64(long value, params long[] indices)
Parameters
valuelongThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetInternalArray(IArraySlice)
Replace internal storage array with given array.
protected void SetInternalArray(IArraySlice array)
Parameters
arrayIArraySliceThe array to set as internal storage
Exceptions
- InvalidCastException
When type of
arraydoes not match DType of this storage
SetInternalArray(Array)
Replace internal storage array with given array.
protected void SetInternalArray(Array array)
Parameters
arrayArrayThe array to set as internal storage
Exceptions
- InvalidCastException
When type of
arraydoes not match DType of this storage
SetSByte(sbyte, int[])
Stores value at indices: as it is in a int8 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a int8 scalar).
public void SetSByte(sbyte value, int[] indices)
Parameters
valuesbyteThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetSByte(sbyte, params long[])
Stores value at indices: as it is in a int8 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a int8 scalar).
public void SetSByte(sbyte value, params long[] indices)
Parameters
valuesbyteThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetShapeUnsafe(Shape)
Set the shape of this storage without checking if sizes match.
protected void SetShapeUnsafe(Shape shape)
Parameters
shapeShape
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
shapeShape
Remarks
Used during broadcasting. Uses bufferSize (not size) because broadcast shapes have logical size != physical buffer size.
SetSingle(float, int[])
Stores value at indices: as it is in a float32 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a float32 scalar).
public void SetSingle(float value, int[] indices)
Parameters
valuefloatThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetSingle(float, params long[])
Stores value at indices: as it is in a float32 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a float32 scalar).
public void SetSingle(float value, params long[] indices)
Parameters
valuefloatThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetUInt16(ushort, int[])
Stores value at indices: as it is in a uint16 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a uint16 scalar).
public void SetUInt16(ushort value, int[] indices)
Parameters
valueushortThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetUInt16(ushort, params long[])
Stores value at indices: as it is in a uint16 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a uint16 scalar).
public void SetUInt16(ushort value, params long[] indices)
Parameters
valueushortThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetUInt32(uint, int[])
Stores value at indices: as it is in a uint32 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a uint32 scalar).
public void SetUInt32(uint value, int[] indices)
Parameters
valueuintThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetUInt32(uint, params long[])
Stores value at indices: as it is in a uint32 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a uint32 scalar).
public void SetUInt32(uint value, params long[] indices)
Parameters
valueuintThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetUInt64(ulong, int[])
Stores value at indices: as it is in a uint64 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a uint64 scalar).
public void SetUInt64(ulong value, int[] indices)
Parameters
valueulongThe value to store.
indicesint[]The element's coordinates; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetUInt64(ulong, params long[])
Stores value at indices: as it is in a uint64 array, cast to the
array's dtype with NumPy's cast in an array of any other dtype (NumPy's setitem of a uint64 scalar).
public void SetUInt64(ulong value, params long[] indices)
Parameters
valueulongThe value to store.
indiceslong[]The element's coordinates (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Exceptions
- ValueError
The array is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing outside the array is written).
SetValue(object, int[])
Stores one boxed element at indices. The value must be the dtype's exact CLR type — an
explicit unboxing, never a conversion — except null, which is Python's None and stores what
NumPy's setitem stores for it.
public void SetValue(object value, int[] indices)
Parameters
valueobjectThe element, boxed as this storage's exact type;
nullisNone(NaN for a float dtype,nan+nanjfor complex,Falsefor bool,'None'or aStringDTypeNA object for text).indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Remarks
Does not change the storage's dtype. The generic SetValue<T>(T, int[]) converts a value of another type; this boxed form does not.
Exceptions
- ValueError
The storage is read-only, or
Noneinto aStringDType(coerce=False)storage.- TypeError
None(a nullvalue) into an integer ordecimalstorage; a float storage stores NaN, complexnan+nanj, boolFalse.- InvalidCastException
A non-null value that is not the dtype's exact CLR type.
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing is written).
SetValue(object, params long[])
Stores one boxed element at indices. The value must be the dtype's exact CLR type — an
explicit unboxing, never a conversion — except null, which is Python's None and stores what
NumPy's setitem stores for it.
public void SetValue(object value, params long[] indices)
Parameters
valueobjectThe element, boxed as this storage's exact type;
nullisNone(NaN for a float dtype,nan+nanjfor complex,Falsefor bool,'None'or aStringDTypeNA object for text).indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Remarks
Does not change the storage's dtype. The generic SetValue<T>(T, params long[]) converts a value of another type; this boxed form does not.
Exceptions
- ValueError
The storage is read-only, or
Noneinto aStringDType(coerce=False)storage.- TypeError
None(a nullvalue) into an integer ordecimalstorage; a float storage stores NaN, complexnan+nanj, boolFalse.- InvalidCastException
A non-null value that is not the dtype's exact CLR type.
- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing is written).
SetValue<T>(T, int[])
Stores value at indices: as it is for the dtype's own type, cast to the
dtype with NumPy's cast (the cast astype runs) for any other T — NumPy's
setitem of a scalar of another type.
public void SetValue<T>(T value, int[] indices) where T : unmanaged
Parameters
valueTThe value to store.
indicesint[]One coordinate per leading axis; a negative coordinate counts from the end of its axis, and axes left out address their first element.
Type Parameters
TThe value's type.
Remarks
Does not change the storage's dtype. Before parity QA-12 / QA-33 this stored sizeof(T) raw bytes at an
unchecked offset (a Debug.Assert was the only type test): SetValue(2.5, 0) on a float32 array
gave [0, 2.0625, …], the last element wrote past the buffer, and a wrong coordinate wrote into another
row or outside the array, in Release.
Exceptions
- ValueError
The storage is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing is written).
- NotSupportedException
The storage has no element type.
SetValue<T>(T, params long[])
Stores value at indices: as it is for the dtype's own type, cast to the
dtype with NumPy's cast (the cast astype runs) for any other T — NumPy's
setitem of a scalar of another type.
public void SetValue<T>(T value, params long[] indices) where T : unmanaged
Parameters
valueTThe value to store.
indiceslong[]One coordinate per leading axis (long version); a negative coordinate counts from the end of its axis, and axes left out address their first element.
Type Parameters
TThe value's type.
Remarks
Exceptions
- ValueError
The storage is read-only (
assignment destination is read-only).- IndexError
A coordinate outside its axis, or more coordinates than dimensions (NumPy's texts; nothing is written).
- NotSupportedException
The storage has no element type.
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
shapeShapevaluesIArraySlice
_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
Returns
- Array
Returns
sourceArrayor new array with changed type toto_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
sourceArrayIArraySliceThe array to change his type
Returns
- ArraySlice<TOut>
Returns
sourceArrayor new array with changed type toto_dtype
Type Parameters
TOut
Remarks
If the return type is equal to source type, this method does not return a copy.