Class NDArrayFlags
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
The memory-layout flags of an NDArray — a byte-for-byte port of NumPy 2.4.2's
arrayflags object (numpy/_core/src/multiarray/flagsobject.c): the lowercase
dotted attributes (c_contiguous, f_contiguous, owndata, writeable,
aligned, writebackifcopy, and the derived fnc/forc/behaved/
carray/farray/num), the bracket-key accessor (flags["C"],
flags["F_CONTIGUOUS"], …), the six-line ToString() repr, and equality by the
integer num. Values are read live from the array's Shape and storage,
verified equal to NumPy across every layout (C/F/strided/transposed/broadcast/0-d/empty).
ALIGNED is true for every fresh array (managed allocations are always aligned) and can only be
cleared through setflags(bool?, bool?, bool?) / flags["A"] = false — NumPy parity, the
flag then reads back False and num/behaved/carray/farray follow.
WRITEBACKIFCOPY is always false (NumSharp has no copy-on-write handoff), matching what a
NumSharp array can be.
public sealed class NDArrayFlags : IEquatable<NDArrayFlags>
- Inheritance
-
NDArrayFlags
- Implements
- Inherited Members
Properties
this[string]
Bracket-key access, matching NumPy's flags["C_CONTIGUOUS"] / flags["C"] mapping
(short and long spellings both accepted). GET returns the flag; SET is defined only for the
writeable/aligned/writebackifcopy keys NumPy allows. An unrecognised key raises
KeyError("Unknown flag"), as NumPy does.
public bool this[string key] { get; set; }
Parameters
keystring
Property Value
aligned
The data and all elements are aligned appropriately for the hardware — true for every fresh
NumSharp array; clearable via setflags(bool?, bool?, bool?) (align: false) for NumPy
parity.
public bool aligned { get; }
Property Value
behaved
ALIGNED and WRITEABLE (NumPy's behaved).
public bool behaved { get; }
Property Value
c_contiguous
The data is in a single, C-style contiguous segment (C_CONTIGUOUS).
public bool c_contiguous { get; }
Property Value
carray
ALIGNED, WRITEABLE and C-contiguous (NumPy's carray).
public bool carray { get; }
Property Value
contiguous
Alias of c_contiguous (NumPy's flags.contiguous).
public bool contiguous { get; }
Property Value
f_contiguous
The data is in a single, Fortran-style contiguous segment (F_CONTIGUOUS).
public bool f_contiguous { get; }
Property Value
farray
NumPy's farray: (ALIGNED | WRITEABLE | F_CONTIGUOUS) != 0 AND NOT C-contiguous —
the hand-written any-bit form (so it is true for e.g. a strided or broadcast non-C view because
ALIGNED alone satisfies the left side; since NumSharp is always aligned this reduces to
!c_contiguous, exactly reproducing NumPy across every probed layout).
public bool farray { get; }
Property Value
fnc
F-contiguous but NOT C-contiguous (NumPy's fnc).
public bool fnc { get; }
Property Value
forc
F-contiguous OR C-contiguous (NumPy's forc).
public bool forc { get; }
Property Value
fortran
Alias of f_contiguous (NumPy's flags.fortran).
public bool fortran { get; }
Property Value
num
The persistent flags as a single integer (NumPy's flags.num): the OR of C_CONTIGUOUS
(1), F_CONTIGUOUS (2), OWNDATA (4), ALIGNED (256) and WRITEABLE (1024) — the same bit values
NumPy uses, so num is byte-for-byte NumPy's (e.g. 1281 for a writeable C-contiguous view).
public int num { get; }
Property Value
owndata
The array owns the memory it uses — false for any view (slice/reshape/transpose/broadcast).
public bool owndata { get; }
Property Value
writeable
Whether the array is writeable. Assignable, matching NumPy's a.flags.writeable = …
(which routes through setflags, as this does): setting FALSE makes the array
read-only (in place). Setting TRUE follows NumPy's _IsWriteable rule — an owner of
ordinary memory always re-enables; a view re-enables iff its base is writeable (so a
np.broadcast_to view of your own array CAN be made writeable, writes then aliasing
across the stride-0 axes exactly as in NumPy); an array over foreign read-only memory (an
'r' memmap, a read-only buffer) raises
ValueError("cannot set WRITEABLE flag to True of this array").
public bool writeable { get; set; }
Property Value
writebackifcopy
A copy-on-write handoff is pending — always false in NumSharp (unmodeled).
public bool writebackifcopy { get; }
Property Value
Methods
Equals(NDArrayFlags)
Two flags objects are equal when their num integers match (NumPy's eq).
public bool Equals(NDArrayFlags other)
Parameters
otherNDArrayFlags
Returns
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
ToString()
The six-line human-readable listing NumPy's str(a.flags) / repr(a.flags) produce,
e.g. C_CONTIGUOUS : True … WRITEBACKIFCOPY : False (each line
two-space-indented, Python-cased booleans, trailing newline).
public override string ToString()
Returns
Operators
operator ==(NDArrayFlags, NDArrayFlags)
public static bool operator ==(NDArrayFlags left, NDArrayFlags right)
Parameters
leftNDArrayFlagsrightNDArrayFlags
Returns
operator !=(NDArrayFlags, NDArrayFlags)
public static bool operator !=(NDArrayFlags left, NDArrayFlags right)
Parameters
leftNDArrayFlagsrightNDArrayFlags