cheatah
Class

fixarray::Fixed

A fixed-extent, inline-stored array — an cheatah::ndarray::NDArray whose shape lives in the type.

Trivially copyable and allocation-free; a matrix is stored column-major (see the file doc).

Template parameters
T

the element type; any cheatah::ndarray::Field, exactly as NDArray accepts.

Dims

the extents. One extent is a vector, two are a matrix (rows, then columns).

Functions

fn Fixed · 3 overloads
constexpr Fixed()=defaultsource#
constexpr Fixed(Args... args)source#
constexpr Fixed(const std::array< T, size > &elements)source#

Every element zero — the additive identity, and what a default-constructed value holds.

Complexity

O(size).

Allocation

none.

fn operator[] · 4 overloads
T & operator[](std::size_t i)source#
T & operator[](Ix i)source#
const T & operator[](std::size_t i) constsource#
const T & operator[](Ix i) constsource#

Element i of a vector.

Parameters
i

the index, 0 <= i < size.

Returns

a reference to the element.

Complexity

O(1).

Allocation

none.

fn operator() · 4 overloads
T & operator()(std::size_t row, std::size_t col)source#
T & operator()(R row, C col)source#
const T & operator()(std::size_t row, std::size_t col) constsource#
const T & operator()(R row, C col) constsource#

Element (row, col) of a matrix.

The index is mathematical; the storage is column-major.

Parameters
row

the row, 0 <= row < rows.

col

the column, 0 <= col < cols.

Returns

a reference to the element.

Complexity

O(1).

Allocation

none.

fn data · 2 overloads
T * data()source#
const T * data() constsource#

A pointer to the elements, contiguous — column-major for a matrix, which is exactly the order a GPU uniform, a push constant or a BLAS call expects, so an upload is a copy not a transpose.

Returns

the first element's address.

Complexity

O(1).

Allocation

none.

Unit testFixarray.Data
fn bool operator==(const Fixed &other) const =default source#

Elementwise equality.

Exact, as == on the elements is exact — floating-point values compare only if they are bit-for-bit equal.

Parameters
other

the array to compare with.

Returns

true iff every element matches.

Complexity

O(size).

Allocation

none.

fn Fixed & operator+=(const Fixed &other) source#

Add other elementwise, in place.

Parameters
other

the array to add.

Returns

a reference to this array.

Complexity

O(size).

Allocation

none.

fn Fixed & operator-=(const Fixed &other) source#

Subtract other elementwise, in place.

Parameters
other

the array to subtract.

Returns

a reference to this array.

Complexity

O(size).

Allocation

none.

fn Fixed & operator*=(T scalar) source#

Scale every element by scalar, in place.

Parameters
scalar

the factor.

Returns

a reference to this array.

Complexity

O(size).

Allocation

none.

fn Fixed & operator/=(T scalar) source#

Divide every element by scalar, in place.

Parameters
scalar

the divisor.

Returns

a reference to this array.

Complexity

O(size).

Allocation

none.

fn static Fixed identity() source#

The square identity: ones on the diagonal, zeros elsewhere.

Returns

the identity matrix.

Complexity

O(size).

Allocation

none.

fn static Fixed filled(T value) source#

Every element set to valuefilled(0) is the zero value, filled(1) a matrix of ones.

Parameters
value

the element to repeat.

Returns

the filled array.

Complexity

O(size).

Allocation

none.

fn static Fixed from_indices(F &&f) source#

Build an array elementwise: each element i of the flat, contiguous buffer is f(i).

This is the allocation-free, single-pass way to write a component-wise operation — no default zeroing and no separate copy to overwrite, so a call like abs or min compiles to one vector pass (minps/maxpd) rather than two. The index i runs over the storage order (column-major for a matrix), which is exactly what an elementwise operation wants.

Template parameters
F

a callable T(std::size_t).

Parameters
f

produces element i from its flat index.

Returns

the array whose element i is f(i).

Complexity

O(size).

Allocation

none.

fn static Fixed identity_impl(std::index_sequence< I... >) source#

identity's worker: emits each element exactly once, with no zeroing pass.

Template parameters
I

the flat indices 0 … size-1.

Returns

the identity matrix.

fn static Fixed from_indices_impl(F &&f, std::index_sequence< I... >) source#

from_indices's worker: aggregate-initialises the buffer from f(0) … f(size-1), fully unrolled, so there is no loop, no zeroing, and no pointer through which the operands alias.

Template parameters
F

the element-producing callable.

I

the flat indices 0 … size-1.

Parameters
f

produces each element from its flat index.

Returns

the array of f(i).

Constants & variables

var static std::size_t rank source#

The number of extents: 1 for a vector, 2 for a matrix.

var static std::size_t size source#

The total number of elements.

var static std::array< std::size_t, rank > shape source#

The extents, in order (rows, then columns for a matrix).

var static std::size_t rows source#

Rows — the first extent (a vector has one row).

var static std::size_t cols source#

Columns — the second extent, or 1 for a vector.

var std::array< T, size > data_ source#

The elements, inline: a vector in order, a matrix column by column. Zero by default.

Types

type T value_type source#

The element type.