Skip to content

Commit c2d9e0c

Browse files
authored
Improved the error messages when sizes are incompatible (#682)
1 parent 4fd3986 commit c2d9e0c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

include/matx/core/error.h

+21-2
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,30 @@ namespace matx
225225
// This macro asserts compatible dimensions of current class to an operator.
226226
#define ASSERT_COMPATIBLE_OP_SIZES(op) \
227227
if constexpr (Rank() > 0) { \
228+
bool compatible = true; \
228229
_Pragma("unroll") \
229230
for (int32_t i = 0; i < Rank(); i++) { \
230231
[[maybe_unused]] index_t size = matx::detail::get_expanded_size<Rank()>(op, i); \
231-
MATX_ASSERT_STR(size == 0 || size == Size(i), matxInvalidSize, "incompatible op sizes:" + str()); \
232+
compatible = (size == 0 || size == Size(i)); \
232233
} \
233-
}
234+
if (!compatible) { \
235+
std::cerr << "Incompatible operator sizes: ("; \
236+
for (int32_t i = 0; i < Rank(); i++) { \
237+
std::cerr << Size(i); \
238+
if (i != Rank() - 1) { \
239+
std::cerr << ","; \
240+
} \
241+
} \
242+
std::cerr << ") not compatible with ("; \
243+
for (int32_t i = 0; i < Rank(); i++) { \
244+
std::cerr << matx::detail::get_expanded_size<Rank()>(op, i); \
245+
if (i != Rank() - 1) { \
246+
std::cerr << ","; \
247+
} \
248+
} \
249+
std::cerr << ")" << std::endl; \
250+
MATX_THROW(matxInvalidSize, "Incompatible operator sizes"); \
251+
} \
252+
}
234253

235254
} // end namespace matx

0 commit comments

Comments
 (0)