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 32 of file Shape.hpp.
◆ const_iterator
Read-only contiguous iterator over dimensions.
Definition at line 47 of file Shape.hpp.
◆ const_reference
Read-only reference to a dimension.
Definition at line 45 of file Shape.hpp.
◆ const_reverse_iterator
Read-only iterator over dimensions in reverse order.
Definition at line 49 of file Shape.hpp.
◆ difference_type
Signed type used for checked indices and iterator distances.
Definition at line 43 of file Shape.hpp.
◆ size_type
Unsigned type used for ranks and dimension indices.
Definition at line 41 of file Shape.hpp.
◆ value_type
Type used to represent each dimension.
Definition at line 39 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 64 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 75 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 185 of file Shape.hpp.
◆ begin()
Returns a const iterator to the first dimension.
- Complexity
- O(1).
Definition at line 223 of file Shape.hpp.
◆ cbegin()
Returns a const iterator to the first dimension.
- Complexity
- O(1).
Definition at line 233 of file Shape.hpp.
◆ cend()
Returns a const iterator past the final dimension.
- Complexity
- O(1).
Definition at line 238 of file Shape.hpp.
◆ crbegin()
Returns a const reverse iterator to the final dimension.
- Complexity
- O(1).
Definition at line 248 of file Shape.hpp.
◆ crend()
Returns the past-the-end const reverse iterator.
- Complexity
- O(1).
Definition at line 258 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 91 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 195 of file Shape.hpp.
◆ end()
Returns a const iterator past the final dimension.
- Complexity
- O(1).
Definition at line 228 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 206 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 169 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 121 of file Shape.hpp.
◆ rbegin()
Returns a const reverse iterator to the final dimension.
- Complexity
- O(1).
Definition at line 243 of file Shape.hpp.
◆ rend()
Returns the past-the-end reverse iterator.
- Complexity
- O(1).
Definition at line 253 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 138 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 268 of file Shape.hpp.
The documentation for this class was generated from the following file: