Skip to content
class

ShapeMismatch

extendsLucidError
ShapeMismatch

Thrown when two tensors have shapes that are incompatible with an operation's broadcasting or contraction rules.

The expected and actual shapes are retained as integer vectors so callers can inspect them programmatically rather than parsing what(). The message string formatted by the constructor includes both shapes plus the context annotation supplied by ErrorBuilder. Mapped to lucid._C.engine.ShapeMismatch on the Python side.

See Also

Validator : Wraps the common precondition checks that raise this exception via ErrorBuilder.

Parameters

expectedstd::vector<std::int64_t>
Shape the operation required, in row-major dimension order.
gotstd::vector<std::int64_t>
Shape that was actually supplied.
contextstd::string
Free-form annotation produced by ErrorBuilder (typically the op name plus the optional detail argument and any thread-local trace).

Attributes

expected_std::vector<std::int64_t>
Stored copy of the required shape.
got_std::vector<std::int64_t>
Stored copy of the offending shape.

Examples

```
ErrorBuilder("matmul").shape_mismatch(expected, got, "rhs");
```

Constructors

1
ctor

ShapeMismatch

void ShapeMismatch(int expected, int got, int context)

Construct a ShapeMismatch with the expected vs actual shape and the op-level context annotation the call site captured. All three become part of the formatted what() message.

Methods

2
fnconst

expected

→const std::vector<std::int64_t>&
const int & expected()

Returns the shape the operation required.

Returns

const std::vector<std::int64_t>&

Stored expected argument; lifetime tied to *this.

fnconst

got

→const std::vector<std::int64_t>&
const int & got()

Returns the shape that was actually supplied.

Returns

const std::vector<std::int64_t>&

Stored got argument; lifetime tied to *this.