diff --git a/include/boost/numeric/ublas/tensor/tensor/tensor_static.hpp b/include/boost/numeric/ublas/tensor/tensor/tensor_static.hpp index 644ed9c51..9077251cb 100644 --- a/include/boost/numeric/ublas/tensor/tensor/tensor_static.hpp +++ b/include/boost/numeric/ublas/tensor/tensor/tensor_static.hpp @@ -192,7 +192,7 @@ class tensor_core> * @note extents are automatically extracted from the temporary matrix * * @param expr matrix expression - */ + */ template // NOLINTNEXTLINE(hicpp-explicit-conversions) inline tensor_core (const matrix_expression_type &expr) @@ -208,7 +208,7 @@ class tensor_core> * @note extents are automatically extracted from the temporary matrix * * @param expr vector expression - */ + */ template // NOLINTNEXTLINE(hicpp-explicit-conversions) inline tensor_core (const vector_expression_type &expr) @@ -279,6 +279,11 @@ class tensor_core> [[nodiscard]] inline const_reference at (I1 i1, I2 i2, Is ... is) const { static_assert (sizeof...(is)+2 == ublas::size_v); + if(sizeof...(is)+2 != this->order()){ + throw std::invalid_argument("boost::numeric::ublas::tensor_core::at : " + "Cannot access tensor with multi-index. " + "Number of provided indices does not match with tensor order."); + } const auto idx = ublas::detail::to_index(_strides,i1,i2,is... ); return _container[idx]; } @@ -294,6 +299,11 @@ class tensor_core> [[nodiscard]] inline reference at (I1 i1, I2 i2, Is ... is) { static_assert (sizeof...(is)+2 == ublas::size_v); + if(sizeof...(is)+2 != this->order()){ + throw std::invalid_argument("boost::numeric::ublas::tensor_core::at : " + "Cannot access tensor with multi-index. " + "Number of provided indices does not match with tensor order."); + } const auto idx = ublas::detail::to_index(_strides,i1,i2,is... ); return _container[idx]; } @@ -453,4 +463,3 @@ using vector_static = tensor_static, L>; } // namespace boost::numeric::ublas::experimental #endif -