Stores the dimensions of a multidimensional array.
More...
#include <Shape.hpp>
Stores the dimensions of a multidimensional array.
Dimensions are stored in contiguous, read-only order. The number of stored dimensions is the shape's rank, and elements() returns their product when that product can be represented by std::size_t.
- Example
shape.elements();
shape.at(-1);
Stores the dimensions of a multidimensional array.
size_type rank() const noexcept
Returns the number of dimensions.
Definition at line 35 of file Shape.hpp.
◆ const_iterator
Read-only contiguous iterator over dimensions.
Definition at line 50 of file Shape.hpp.
◆ const_reference
Read-only reference to a dimension.
Definition at line 48 of file Shape.hpp.
◆ const_reverse_iterator
Read-only iterator over dimensions in reverse order.
Definition at line 52 of file Shape.hpp.
◆ difference_type
Signed type used for checked indices and iterator distances.
Definition at line 46 of file Shape.hpp.
◆ size_type
Unsigned type used for ranks and dimension indices.
Definition at line 44 of file Shape.hpp.
◆ value_type
Type used to represent each dimension.
Definition at line 42 of file Shape.hpp.
◆ Shape() [1/3]
| stratax::core::Shape::Shape |
( |
| ) |
|
|
defaultnoexcept |
Constructs an empty, rank-zero shape.
- Complexity
- O(1).
◆ Shape() [2/3]
| stratax::core::Shape::Shape |
( |
std::initializer_list< value_type > |
dims | ) |
|
|
inline |
Constructs a shape from dimensions in outermost-to-innermost order.
- Parameters
-
| dims | Dimensions to copy into the shape. |
- Exceptions
-
| std::bad_alloc | If dimension storage cannot be allocated. |
- Complexity
- O(dims.size()).
Definition at line 67 of file Shape.hpp.
◆ Shape() [3/3]
| stratax::core::Shape::Shape |
( |
const std::vector< value_type > & |
dims | ) |
|
|
inline |
Constructs a shape by copying a vector of dimensions.
- Parameters
-
| dims | Dimensions in outermost-to-innermost order. |
- Exceptions
-
| std::bad_alloc | If dimension storage cannot be allocated. |
- Complexity
- O(dims.size()).
Definition at line 78 of file Shape.hpp.
◆ at()
Returns a dimension using checked, Python-style indexing.
Negative indices count backward from the final dimension, so at(-1) returns the last dimension.
- Parameters
-
- Returns
- Const reference to the normalized dimension.
- Exceptions
-
- Complexity
- O(1).
Definition at line 189 of file Shape.hpp.
◆ begin()
Returns a const iterator to the first dimension.
- Complexity
- O(1).
Definition at line 227 of file Shape.hpp.
◆ cbegin()
Returns a const iterator to the first dimension.
- Complexity
- O(1).
Definition at line 237 of file Shape.hpp.
◆ cend()
Returns a const iterator past the final dimension.
- Complexity
- O(1).
Definition at line 242 of file Shape.hpp.
◆ crbegin()
Returns a const reverse iterator to the final dimension.
- Complexity
- O(1).
Definition at line 252 of file Shape.hpp.
◆ crend()
Returns the past-the-end const reverse iterator.
- Complexity
- O(1).
Definition at line 262 of file Shape.hpp.
◆ elements()
| size_type stratax::core::Shape::elements |
( |
| ) |
const |
|
inline |
Computes the total number of elements described by the shape.
Returns zero for a rank-zero shape or for any shape containing a zero dimension. Multiplication is checked to prevent unsigned overflow.
- Returns
- Product of all dimensions, or zero for an empty/zero-sized shape.
- Exceptions
-
- Complexity
- O(rank()).
Definition at line 94 of file Shape.hpp.
◆ empty()
| bool stratax::core::Shape::empty |
( |
| ) |
const |
|
inlinenoexcept |
Reports whether the shape has rank zero.
- Returns
true if no dimensions are stored; otherwise false.
- Complexity
- O(1).
Definition at line 199 of file Shape.hpp.
◆ end()
Returns a const iterator past the final dimension.
- Complexity
- O(1).
Definition at line 232 of file Shape.hpp.
◆ operator==()
| bool stratax::core::Shape::operator== |
( |
const Shape & |
other | ) |
const |
|
inlinenoexcept |
Compares two shapes dimension by dimension.
- Parameters
-
| other | Shape to compare with. |
- Returns
true if both shapes have identical rank and dimensions.
- Complexity
- O(rank()).
Definition at line 210 of file Shape.hpp.
◆ operator[]()
Returns a dimension without bounds checking.
- Parameters
-
| index | Zero-based dimension index. |
- Returns
- Const reference to the dimension at
index.
- Precondition
index < rank(); otherwise behavior is undefined.
- Complexity
- O(1).
Definition at line 173 of file Shape.hpp.
◆ rank()
| size_type stratax::core::Shape::rank |
( |
| ) |
const |
|
inlinenoexcept |
Returns the number of dimensions.
- Returns
- Number of stored dimension values.
- Complexity
- O(1).
Definition at line 124 of file Shape.hpp.
◆ rbegin()
Returns a const reverse iterator to the final dimension.
- Complexity
- O(1).
Definition at line 247 of file Shape.hpp.
◆ rend()
Returns the past-the-end reverse iterator.
- Complexity
- O(1).
Definition at line 257 of file Shape.hpp.
◆ strides()
| Shape stratax::core::Shape::strides |
( |
| ) |
const |
|
inline |
Computes canonical row-major strides for this shape.
The returned shape has the same rank as this shape. Its final stride is one, and each preceding stride is the product of the dimensions to its right. A rank-zero shape produces a rank-zero stride shape.
- Returns
- Shape containing the row-major stride for each dimension.
- Exceptions
-
- Complexity
- O(rank()).
Definition at line 142 of file Shape.hpp.
◆ swap()
| void stratax::core::Shape::swap |
( |
Shape & |
other | ) |
|
|
inlinenoexcept |
Exchanges dimension storage with another shape.
- Parameters
-
| other | Shape whose dimensions are exchanged with this shape. |
- Complexity
- O(1).
Definition at line 272 of file Shape.hpp.
The documentation for this class was generated from the following file: