Shape#
Fully qualified name: isaacsim::common::array::Shape
-
class Shape#
Represents the multi-dimensional shape of an array.
A Shape holds an ordered sequence of dimension sizes as signed integers, one per axis. A default-constructed Shape is empty (zero dimensions). Dimensions are accessed by index via operator[](), with negative indices counting from the last axis.
Shape supports NumPy-style broadcasting semantics via canBroadcastTo() and resolve().
Public Functions
-
Shape(const details::SupportedShapeSpecification &shape)#
Constructs a Shape from a supported shape specification.
A scalar variant produces a 1-D shape; a vector variant produces an N-D shape with one dimension per element.
- Parameters:
shape – [in] Integer scalar or vector of dimension sizes.
-
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
inline Shape(
)# Constructs a Shape from a brace-enclosed list of integral dimension sizes.
- Template Parameters:
T – An integral type used to express the dimension sizes.
- Parameters:
dimensions – [in] Ordered list of dimension sizes, one per axis.
-
Shape() = default#
Constructs an empty, zero-dimensional shape.
-
~Shape() = default#
-
int64_t operator[](int64_t index) const#
Returns the size of the dimension at the given index.
Negative indices are supported and count from the last axis: index -1 refers to the last dimension.
-
bool operator==(const Shape &other) const#
Checks whether two shapes are identical.
- Parameters:
other – [in] The Shape to compare against.
- Returns:
trueif both shapes have the same number of dimensions and equal sizes.
-
bool operator!=(const Shape &other) const#
Checks whether two shapes differ.
- Parameters:
other – [in] The Shape to compare against.
- Returns:
trueif the shapes differ in rank or in any dimension size.
-
std::vector<int64_t> shape() const#
Returns the dimension sizes as a vector of signed integers.
- Returns:
A vector of length ndim() containing the size of each axis.
-
const int64_t *data() const#
Returns a read-only pointer to the stored dimension sizes.
The pointer remains valid until this Shape is assigned or destroyed.
- Returns:
Pointer to the first dimension, or an unspecified pointer for a zero-dimensional shape.
-
size_t ndim() const#
Returns the number of dimensions (rank) of this shape.
- Returns:
Number of axes.
-
size_t size() const#
Returns the total number of elements described by this shape.
- Throws:
std::invalid_argument – if any dimension is negative.
- Returns:
Product of all dimension sizes, or 1 for a zero-dimensional shape.
-
bool canBroadcastTo(const Shape &other) const#
Returns whether this shape can be broadcast to
other.Follows NumPy broadcasting rules: dimensions are compared from the trailing axis, and each dimension of this shape must either equal the corresponding dimension of
otheror be 1.- Parameters:
other – [in] The target shape to broadcast to.
- Returns:
trueif this shape is broadcast-compatible withother.
-
Shape resolve(const Shape &other) const#
Reshape helper: resolves a target shape against this shape’s total element count.
Returns a fully specified shape with the same total number of elements as this shape, suitable for use as a reshape target. At most one dimension in
othermay be -1, in which case its size is inferred so that the total number of elements equals size(). All other dimensions inothermust be non-negative. This shape must contain no negative dimensions.- Parameters:
other – [in] Target shape, optionally containing one -1 dimension to infer.
- Throws:
std::invalid_argument – if this shape contains negative dimensions, if
othercontains more than one -1 dimension, ifothercontains negative dimensions other than -1, or if the total element count is incompatible withother.- Returns:
A fully specified Shape with the same total element count as this shape.
-
Shape(const details::SupportedShapeSpecification &shape)#