Repository navigation
Conversation
xfunction::broadcast_shape copied its cached shape into the output shape without checking that both have the same rank. Assigning a rank-2 xfunction whose shape was already computed to an xt::xtensor<T, 1> wrote past the std::array<std::size_t, 1> (stack-buffer-overflow under ASan). With a larger dynamic output shape, the cached path returned a different shape than the uncached one. The cache is now used only when both ranks match. Otherwise the full broadcast runs and reports incompatible ranks, as it already did when the cache was empty.
Merging this PR will degrade performance by 18.92%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
Checklist
Description
xfunction::broadcast_shapecopied its cached shape into the output shape without checking the rank. Assigning a rank-2 expression to anxt::xtensor<T, 1>should throw, but once the shape of thexfunctionhas been cached, it writes past thestd::array<std::size_t, 1>:Without the
f.shape()call, the cache is empty and the same assignment throwsbroadcast_error. With a larger dynamic shape, the cached path returns{2, 3, MAX}where the uncached one returns{MAX, 2, 3}.The cache is now used only when both ranks match. Other ranks go through the full broadcast, which already reports incompatible ranks.
xfunction.broadcast_shape_cached_other_rankcovers both cases. On master, the higher-rank subcase gets a shape that differs from the uncached result, and the lower-rank subcase triggers a stack-buffer-overflow under AddressSanitizer. Both pass with the fix.