MTCT
Design Automation and Optimization for ETCS Railway Networks
Loading...
Searching...
No Matches
cda_rail::MultiArray< T > Class Template Reference

A dynamically-shaped N-dimensional array stored in row-major order. More...

#include <MultiArray.hpp>

Public Member Functions

template<typename... Args>
 MultiArray (Args... args)
 Constructs a MultiArray with the given dimension extents.
template<typename... Args>
T & operator() (Args... args)
 Checked multi-dimensional element access (non-const).
template<typename... Args>
T & at (Args... args)
 Bounds-checked multi-dimensional element access (non-const).
template<typename... Args>
const T & at (Args... args) const
 Bounds-checked multi-dimensional element access (const).
const FixedSizeVector< size_t > & get_shape () const
 Provides the shape of the array.
size_t size () const
 Computes the total number of elements in the array.
size_t dimensions () const
 Gets the number of dimensions.
const T * begin () const
 Iterates over all elements in row-major order.
const T * end () const
 The end of the iteration, see begin().

Detailed Description

template<typename T>
class cda_rail::MultiArray< T >

A dynamically-shaped N-dimensional array stored in row-major order.

The shape (number of dimensions and the extent of each dimension) is fixed at construction time. Element storage is a flat FixedSizeVector<T> whose length equals the product of all dimension extents. Multi-dimensional indices are linearised using a row-major (last-index-fastest) scheme.

A zero-dimensional MultiArray behaves like a scalar: it contains exactly one element that is accessed via operator()() or at().

Template Parameters
TElement type. Must be default-constructible.
Invariant
m_data.size() equals the product of all extents in m_shape (or 1 when m_shape is empty).

Constructor & Destructor Documentation

◆ MultiArray()

template<typename T>
template<typename... Args>
cda_rail::MultiArray< T >::MultiArray ( Args... args)
inlineexplicit

Constructs a MultiArray with the given dimension extents.

Pass one extent per dimension (e.g. MultiArray<int>(3, 4) creates a 3×4 matrix). Passing no arguments creates a zero-dimensional scalar array containing exactly one element.

Template Parameters
ArgsIntegral types convertible to size_t.
Parameters
argsExtents of each dimension, in order.
Exceptions
std::invalid_argumentIf any argument is a negative signed value.

Member Function Documentation

◆ at() [1/2]

template<typename T>
template<typename... Args>
T & cda_rail::MultiArray< T >::at ( Args... args)
inlinenodiscard

Bounds-checked multi-dimensional element access (non-const).

Template Parameters
ArgsIntegral types convertible to size_t.
Parameters
argsOne index per dimension.
Returns
Reference to the requested element.
Exceptions
std::invalid_argumentIf the number of arguments differs from dimensions().
std::out_of_rangeIf any index exceeds its dimension's extent.

◆ at() [2/2]

template<typename T>
template<typename... Args>
const T & cda_rail::MultiArray< T >::at ( Args... args) const
inlinenodiscard

Bounds-checked multi-dimensional element access (const).

Template Parameters
ArgsIntegral types convertible to size_t.
Parameters
argsOne index per dimension.
Returns
Const reference to the requested element.
Exceptions
std::invalid_argumentIf the number of arguments differs from dimensions().
std::out_of_rangeIf any index exceeds its dimension's extent.

◆ begin()

template<typename T>
const T * cda_rail::MultiArray< T >::begin ( ) const
inlinenodiscard

Iterates over all elements in row-major order.

◆ dimensions()

template<typename T>
size_t cda_rail::MultiArray< T >::dimensions ( ) const
inlinenodiscard

Gets the number of dimensions.

Returns
Number of dimensions (0 for a scalar, 1 for a vector, 2 for a matrix, etc.).

◆ end()

template<typename T>
const T * cda_rail::MultiArray< T >::end ( ) const
inlinenodiscard

The end of the iteration, see begin().

◆ get_shape()

template<typename T>
const FixedSizeVector< size_t > & cda_rail::MultiArray< T >::get_shape ( ) const
inlinenodiscard

Provides the shape of the array.

Returns
Const reference to the array's dimension extents.

◆ operator()()

template<typename T>
template<typename... Args>
T & cda_rail::MultiArray< T >::operator() ( Args... args)
inline

Checked multi-dimensional element access (non-const).

The number of arguments must equal dimensions() and each index must be within bounds; these conditions are enforced via flat_index/check_args. The operator syntax mirrors array access, but this is not unchecked access.

Template Parameters
ArgsIntegral types convertible to size_t.
Parameters
argsOne index per dimension.
Returns
Reference to the requested element.
Exceptions
std::invalid_argumentIf the number of arguments differs from dimensions().
std::out_of_rangeIf any index exceeds its dimension's extent.

◆ size()

template<typename T>
size_t cda_rail::MultiArray< T >::size ( ) const
inlinenodiscard

Computes the total number of elements in the array.

Returns
The product of all dimension extents (1 for a zero-dimensional array).

The documentation for this class was generated from the following file: