ndarray::basic_ndarray
An N-dimensional array of T (a Field element type — real or complex): a view ({shape, strides, offset}) over a shared element buffer.
Copies are cheap and share the buffer; reshape/broadcast produce new views without copying elements. Index math goes through at, which bounds-checks. The element type is deduced from the data (e.g. array([1,2,3]) is integer, array([1.0,…]) is double); NDArray is the default basic_ndarray<double>. Complex element types (std::complex<double>) make complex matrices/vectors — and the complex eigenvalues a real matrix can have — first-class.
Functions
basic_ndarray · 3 overloads
Construct an empty 0-d array with a fresh empty buffer.
Leaves shape and strides empty and the buffer holding no elements; note this is distinct from a 0-d scalar (see scalar), whose buffer holds one element.
O(1).
allocates the empty shared buffer.
CheatahNDArray.ToStringScalarStdlibE2E.NdarrayThe shape (dimensions).
The element strides.
reference to the strides vector.
O(1).
none.
CheatahNDArray.BroadcastToThe number of dimensions (rank).
The element count (product of dims; 1 for a 0-d scalar).
Recomputes the overflow-checked product of the shape on each call rather than caching it; an empty (no-dimension) shape yields 1.
the number of elements.
O(ndim).
none; throws on size overflow.
item_ref · 2 overloads
MUTABLE element reference by multi-index — the write path behind cheatah subscript assignment x[i] = v / x[i, j] = v.
Negative indices count from the end of their dimension; rank and bounds are checked.
ixs | one (possibly negative) coordinate per dimension. |
a writable reference into the backing buffer.
O(ndim).
none.
CheatahNDArray.SubscriptReadWriteLangFeatures.NdarraySubscript1-D subscript: mask[i] = v assignment and raw element writes.
Accepts an integer or a scoped enum column label (see Subscript), so q[QuatCol::W] = v writes column W of a 1-D row.
i | the element index (negative counts from the end, Python-style). |
a mutable reference to element i.
O(1).
none.
CheatahNDArray.SubscriptReadWriteThe buffer position of a (possibly negative) multi-index — rank and bounds are checked here, once, for both item_ref overloads.
ixs | one index per dimension (negative counts from the end, Python-style). |
the flat position in the buffer of that element.
O(ndim).
none.
CheatahNDArray.SubscriptReadWriteWritable element at index — the mutable companion to at, used to write through a view (a slice assignment addresses elements it does not own outright).
index | one coordinate per dimension. |
a reference to the element.
O(ndim).
none.
CheatahNDArray.SliceAssignCopiesInStdlibE2E.NdarrayRead one element by a full multidimensional index (one component per axis), resolved via the array's strides.
Computes the flat buffer position as offset + sum(index[i] * strides[i]), so it correctly resolves views (including broadcast dims with stride 0). Bounds- and rank-checked.
index | the per-axis indices; its size must equal the array's rank. |
a copy of the addressed element.
std::runtime_error | if |
O(rank).
none.
The shared backing buffer.
reference to the element buffer shared_ptr.
O(1).
none.
CheatahNDArray.BroadcastingAddThe flat offset into the buffer where this view starts.
Python-style text rendering, e.g.
"[[1, 2], [3, 4]]" — the str() member, the same full form to_string and operator<< produce (io.print reaches an array through cheatah_pretty_print and operator<<, not this hook). Defers to the free to_string; defined out-of-line below, where to_string is declared.
the array formatted as nested brackets.
O(n) in the element count.
allocates the result string.
Pretty-print hook used by io.print: renders the array in nested-bracket form but ABBREVIATES a large array with ... (numpy-style edge items), so printing a big array stays readable.
io.rprint (and str()/operator<<) keep the FULL untruncated form — slice the array and rprint the subset to see everything.
os | destination stream. |
indent | unused (arrays are self-delimiting with brackets); present so |
O(size) — an abbreviated axis is still stepped over; only its edge items are formatted.
allocates intermediate strings.
NdarrayCompileRun.PrintAbbreviatesLargeArrayBuild a contiguous array of shape whose buffer is sized but left UNINITIALIZED — for internal ops (binary ops, ufuncs, reshape, array) that immediately write every element, so paying for a zero-fill first is pure waste.
shape | the dimensions. |
an array of shape with an uninitialized buffer.
O(ndim) beyond the allocation (no element initialization pass for a trivially-constructible T).
allocates an uninitialized product(shape)-element buffer; overflow-checked.
CheatahNDArray.BroadcastingAddStdlibE2E.NdarrayConstants & variables
Types
The stored element type (an Element T).
