Stratax
Scientific computing containers and operations
Loading...
Searching...
No Matches
stratax::core::Shape Class Reference

Stores a list of dimension lengths for an array shape. More...

#include <Shape.hpp>

Classes

struct  allow_zero_t

Public Member Functions

 Shape () noexcept=default
 Creates an empty shape.
template<Integral... Dims>
requires (sizeof...(Dims) > 0)
 Shape (Dims... dims)
 Creates a shape from positive integer dimension lengths.
 Shape (std::initializer_list< std::size_t > list, allow_zero_t allow_zero)
 Creates a shape from dimension lengths without rejecting zero dimensions.
 Shape (const Buffer< std::size_t > &dims)
 Creates a shape by copying dimension lengths from a buffer.
 Shape (const Buffer< std::size_t > &dims, allow_zero_t allow_zero)
 Creates a shape by copying dimension lengths without rejecting zero dimensions.
 Shape (Buffer< std::size_t > &&dims)
 Creates a shape by taking ownership of dimension lengths from a buffer.
 Shape (Buffer< std::size_t > &&dims, allow_zero_t allow_zero)
 Creates a shape by taking ownership of dimensions without rejecting zero dimensions.
 ~Shape ()=default
 Destroys the shape.
std::size_t elements () const
 Returns the total number of elements described by the shape.
std::size_t rank () const
 Returns the number of stored dimensions.
const std::size_t & operator() (std::size_t index) const
 Returns the length of a specific dimension.
bool empty () const noexcept
 Returns whether the shape has no dimensions.
bool operator== (const Shape &other) const noexcept
 Compares two shapes for exact rank and dimension equality.
bool operator!= (const Shape &other) const noexcept
 Returns whether two shapes differ in rank or dimension values.
auto begin () noexcept
 Returns an iterator to the first stored dimension.
auto end () noexcept
 Returns an iterator one past the last stored dimension.
auto begin () const noexcept
 Returns a const iterator to the first stored dimension.
auto end () const noexcept
 Returns a const iterator one past the last stored dimension.
void swap (Shape &other) noexcept
 Swaps the stored dimensions with another shape.

Static Public Attributes

static constexpr allow_zero_t allow_zero {}

Detailed Description

Stores a list of dimension lengths for an array shape.

Shape tracks rank, dimension sizes, and derived element counts for Stratax containers. It provides lightweight metadata only and does not own any element storage.

Definition at line 19 of file Shape.hpp.

Constructor & Destructor Documentation

◆ Shape() [1/7]

stratax::core::Shape::Shape ( )
defaultnoexcept

Creates an empty shape.

An empty shape has rank 0 and stores no axis lengths.

Referenced by operator!=(), operator==(), Shape(), and swap().

◆ Shape() [2/7]

template<Integral... Dims>
requires (sizeof...(Dims) > 0)
stratax::core::Shape::Shape ( Dims... dims)
inline

Creates a shape from positive integer dimension lengths.

The dimensions are stored in order, from outermost axis to innermost axis. Boolean and character-like types are rejected by the Integral concept.

Parameters
dimsDimension lengths.

Definition at line 56 of file Shape.hpp.

References Shape().

◆ Shape() [3/7]

stratax::core::Shape::Shape ( std::initializer_list< std::size_t > list,
allow_zero_t allow_zero )
inline

Creates a shape from dimension lengths without rejecting zero dimensions.

This overload is intended for container internals that need rank-preserving empty shapes such as (0,) or (0, 0).

Parameters
listDimension lengths.
allow_zeroTag allowing zero-valued dimensions.

Definition at line 71 of file Shape.hpp.

References allow_zero.

◆ Shape() [4/7]

stratax::core::Shape::Shape ( const Buffer< std::size_t > & dims)
inline

Creates a shape by copying dimension lengths from a buffer.

Parameters
dimsSource buffer containing one dimension length per entry.

Definition at line 81 of file Shape.hpp.

◆ Shape() [5/7]

stratax::core::Shape::Shape ( const Buffer< std::size_t > & dims,
allow_zero_t allow_zero )
inline

Creates a shape by copying dimension lengths without rejecting zero dimensions.

Parameters
dimsSource buffer containing one dimension length per entry.
allow_zeroTag allowing zero-valued dimensions.

Definition at line 93 of file Shape.hpp.

References allow_zero.

◆ Shape() [6/7]

stratax::core::Shape::Shape ( Buffer< std::size_t > && dims)
inline

Creates a shape by taking ownership of dimension lengths from a buffer.

Parameters
dimsSource buffer containing one dimension length per entry.

Definition at line 104 of file Shape.hpp.

◆ Shape() [7/7]

stratax::core::Shape::Shape ( Buffer< std::size_t > && dims,
allow_zero_t allow_zero )
inline

Creates a shape by taking ownership of dimensions without rejecting zero dimensions.

Parameters
dimsSource buffer containing one dimension length per entry.
allow_zeroTag allowing zero-valued dimensions.

Definition at line 116 of file Shape.hpp.

References allow_zero.

◆ ~Shape()

stratax::core::Shape::~Shape ( )
default

Destroys the shape.

Member Function Documentation

◆ begin() [1/2]

auto stratax::core::Shape::begin ( ) const
inlinenoexcept

Returns a const iterator to the first stored dimension.

Returns
Const iterator to the beginning of the dimension storage.

Definition at line 247 of file Shape.hpp.

◆ begin() [2/2]

auto stratax::core::Shape::begin ( )
inlinenoexcept

Returns an iterator to the first stored dimension.

Returns
Iterator to the beginning of the dimension storage.

Definition at line 227 of file Shape.hpp.

Referenced by offset().

◆ elements()

std::size_t stratax::core::Shape::elements ( ) const
inlinenodiscard

Returns the total number of elements described by the shape.

The result is the product of all stored dimensions. An empty shape reports zero elements.

Returns
Total number of elements implied by the shape.
Exceptions
Exceptions::DimensionErrorIf the product of dimensions would overflow std::size_t.

Definition at line 138 of file Shape.hpp.

References stratax::core::validation::checked_multiply(), and empty().

Referenced by stratax::container::operator<<(), and reshape().

◆ empty()

bool stratax::core::Shape::empty ( ) const
inlinenodiscardnoexcept

Returns whether the shape has no dimensions.

Returns
true when the shape rank is zero.

Definition at line 182 of file Shape.hpp.

Referenced by elements().

◆ end() [1/2]

auto stratax::core::Shape::end ( ) const
inlinenoexcept

Returns a const iterator one past the last stored dimension.

Returns
Const iterator to the end of the dimension storage.

Definition at line 257 of file Shape.hpp.

◆ end() [2/2]

auto stratax::core::Shape::end ( )
inlinenoexcept

Returns an iterator one past the last stored dimension.

Returns
Iterator to the end of the dimension storage.

Definition at line 237 of file Shape.hpp.

◆ operator!=()

bool stratax::core::Shape::operator!= ( const Shape & other) const
inlinenodiscardnoexcept

Returns whether two shapes differ in rank or dimension values.

Parameters
otherShape to compare against.
Returns
true when the shapes are not equal.

Definition at line 217 of file Shape.hpp.

References Shape().

◆ operator()()

const std::size_t & stratax::core::Shape::operator() ( std::size_t index) const
inline

Returns the length of a specific dimension.

Parameters
indexZero-based dimension index.
Returns
Dimension length at the requested index.
Exceptions
Exceptions::IndexErrorIf index is greater than or equal to the shape rank.

Definition at line 171 of file Shape.hpp.

References rank(), and stratax::core::validation::require_index().

◆ operator==()

bool stratax::core::Shape::operator== ( const Shape & other) const
inlinenodiscardnoexcept

Compares two shapes for exact rank and dimension equality.

Parameters
otherShape to compare against.
Returns
true when both shapes have the same rank and dimension values.

Definition at line 194 of file Shape.hpp.

References rank(), and Shape().

◆ rank()

std::size_t stratax::core::Shape::rank ( ) const
inlinenodiscard

Returns the number of stored dimensions.

Returns
Shape rank.

Definition at line 157 of file Shape.hpp.

Referenced by offset(), operator()(), stratax::core::operator<<(), and operator==().

◆ swap()

void stratax::core::Shape::swap ( Shape & other)
inlinenoexcept

Swaps the stored dimensions with another shape.

Parameters
otherShape to exchange state with.

Definition at line 267 of file Shape.hpp.

References Shape().

Member Data Documentation

◆ allow_zero

allow_zero_t stratax::core::Shape::allow_zero {}
staticconstexpr

Definition at line 36 of file Shape.hpp.

Referenced by stratax::container::Matrix< U >::Matrix(), Shape(), Shape(), and Shape().


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