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(
std::initializer_list<T> dimensions,
)#

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(const Shape &other) = default#

Copy-constructs a shape.

Shape(Shape &&other) = default#

Move-constructs a shape.

~Shape() = default#
Shape &operator=(const Shape &other) = default#

Copy-assigns a shape.

Shape &operator=(Shape &&other) = default#

Move-assigns a shape.

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.

Parameters:

index – [in] Axis index, in the range [-ndim(), ndim()).

Returns:

Size of the specified dimension.

bool operator==(const Shape &other) const#

Checks whether two shapes are identical.

Parameters:

other – [in] The Shape to compare against.

Returns:

true if 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:

true if 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 other or be 1.

Parameters:

other – [in] The target shape to broadcast to.

Returns:

true if this shape is broadcast-compatible with other.

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 other may be -1, in which case its size is inferred so that the total number of elements equals size(). All other dimensions in other must 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 other contains more than one -1 dimension, if other contains negative dimensions other than -1, or if the total element count is incompatible with other.

Returns:

A fully specified Shape with the same total element count as this shape.

std::string toString() const#

Returns a human-readable string representation of this shape.

Returns:

A string such as "(3, 4, 5)", or "()" for a scalar shape.

Protected Attributes

std::vector<int64_t> m_shape#

Ordered list of dimension sizes, one entry per axis.