An N-dimensional shape. A plain aggregate of dimensions with no invariant beyond "non-negative dimensions" – see oop_design/context_oop_design_fundamentals.md's struct-vs-class discussion for why this is still a class (numel()/is_reshape_compatible() are derived queries, not raw public fields the caller could desync from dims_).
More...
#include <shape.hpp>
|
| | Shape (std::initializer_list< int64_t > dims) |
| | Constructs a shape from a dimension list. An empty list is a rank-0 scalar (numel() == 1).
|
| |
| | Shape (const std::vector< int64_t > &dims) |
| | Constructs a shape from a runtime-sized dimension list.
|
| |
| int64_t | rank () const |
| | Number of dimensions. 0 for a scalar.
|
| |
| int64_t | numel () const |
| | Total element count – the product of all dimensions.
|
| |
| int64_t | dim (size_t index) const |
| | Size of a single dimension.
|
| |
| bool | is_reshape_compatible (const Shape &other) const |
| | Whether this shape and other have the same numel() – the precondition for a valid reshape between them (same underlying buffer, different dimension grouping).
|
| |
| bool | operator== (const Shape &other) const |
| |
| bool | operator!= (const Shape &other) const |
| |
An N-dimensional shape. A plain aggregate of dimensions with no invariant beyond "non-negative dimensions" – see oop_design/context_oop_design_fundamentals.md's struct-vs-class discussion for why this is still a class (numel()/is_reshape_compatible() are derived queries, not raw public fields the caller could desync from dims_).
◆ Shape() [1/2]
| pulsatrix::Shape::Shape |
( |
std::initializer_list< int64_t > |
dims | ) |
|
|
inline |
Constructs a shape from a dimension list. An empty list is a rank-0 scalar (numel() == 1).
- Exceptions
-
| std::invalid_argument | if any dimension is negative. |
- Note
- Shape is an external boundary – Shape objects are built directly from externally-supplied dimension lists (e.g. bindings/pulsatrix_py.cpp's shape_from_list, from a Python caller). A negative dimension is exactly the kind of malformed input a well-formed internal caller would never produce but an external one can – see campaign_exai_dl_library_adversarial_hardening.md's Mission 0 classification.
◆ Shape() [2/2]
| pulsatrix::Shape::Shape |
( |
const std::vector< int64_t > & |
dims | ) |
|
|
inlineexplicit |
Constructs a shape from a runtime-sized dimension list.
- Exceptions
-
| std::invalid_argument | if any dimension is negative. |
- Note
- Same rationale as Tensor's std::vector<float> constructor overload (tensor.hpp): std::initializer_list has no portable public constructor from a runtime-sized buffer, so a caller computing a rank at runtime (e.g. Tensor::Stack building an output shape whose rank matches its input tensors') cannot use the initializer_list overload at all, not just less conveniently.
◆ dim()
| int64_t pulsatrix::Shape::dim |
( |
size_t |
index | ) |
const |
|
inline |
Size of a single dimension.
- Parameters
-
| index | Dimension index, must be in [0, rank()). |
- Returns
- The dimension's size.
- Note
- PULSATRIX_ASSERT, not throw – internal invariant per Mission 0's classification table: every call site in this codebase computes index from an already-known-valid rank, never from unvalidated external input directly.
◆ is_reshape_compatible()
| bool pulsatrix::Shape::is_reshape_compatible |
( |
const Shape & |
other | ) |
const |
|
inline |
Whether this shape and other have the same numel() – the precondition for a valid reshape between them (same underlying buffer, different dimension grouping).
- Parameters
-
| other | Candidate target shape. |
- Returns
- true iff numel() == other.numel().
◆ numel()
| int64_t pulsatrix::Shape::numel |
( |
| ) |
const |
|
inline |
Total element count – the product of all dimensions.
- Exceptions
-
| std::overflow_error | if the product overflows int64_t. |
- Note
- A rank-0 shape has numel() == 1 (the empty-product convention), matching scalar semantics. Any dimension of 0 makes numel() == 0.
-
Same external-boundary reasoning as the constructor – externally-supplied dimensions can be chosen specifically to overflow this product, which would otherwise silently wrap into a small or negative value that gets cast to size_t for an allocation size downstream (a huge- or mis-sized allocation).
◆ operator!=()
| bool pulsatrix::Shape::operator!= |
( |
const Shape & |
other | ) |
const |
|
inline |
◆ operator==()
| bool pulsatrix::Shape::operator== |
( |
const Shape & |
other | ) |
const |
|
inline |
◆ rank()
| int64_t pulsatrix::Shape::rank |
( |
| ) |
const |
|
inline |
Number of dimensions. 0 for a scalar.
The documentation for this class was generated from the following file: