diff --git a/include/xtensor/containers/xcontainer.hpp b/include/xtensor/containers/xcontainer.hpp index a2ab4fd0d..7f17ffe01 100644 --- a/include/xtensor/containers/xcontainer.hpp +++ b/include/xtensor/containers/xcontainer.hpp @@ -997,10 +997,10 @@ namespace xt template inline void xstrided_container::resize(S&& shape, bool force) { - XTENSOR_ASSERT_MSG( + XTENSOR_PRECONDITION( detail::check_resize_dimension(m_shape, shape), "cannot change the number of dimensions of xtensor" - ) + ); std::size_t dim = shape.size(); if (m_shape.size() != dim || !std::equal(std::begin(shape), std::end(shape), std::begin(m_shape)) || force) diff --git a/test/test_xassign.cpp b/test/test_xassign.cpp index c6ca46305..3535b4886 100644 --- a/test/test_xassign.cpp +++ b/test/test_xassign.cpp @@ -15,6 +15,7 @@ #include "xtensor/containers/xtensor.hpp" #include "xtensor/core/xassign.hpp" #include "xtensor/core/xnoalias.hpp" +#include "xtensor/misc/xmanipulation.hpp" #include "test_common.hpp" #include "test_common_macros.hpp" @@ -167,4 +168,10 @@ namespace xt EXPECT_EQ(a.shape(1), 3); } } + + TEST(xassign, fixed_dimension_mismatch) + { + auto a = xt::xtensor::from_shape({2}); + XT_ASSERT_THROW(a = xt::expand_dims(a, 0), std::runtime_error); + } }