Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added out of range exception for static tensor's #144

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions include/boost/numeric/ublas/tensor/tensor/tensor_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class tensor_core<detail::engine_tensor_static<V,L,ns...>>
* @note extents are automatically extracted from the temporary matrix
*
* @param expr matrix expression
*/
*/
template<class D>
// NOLINTNEXTLINE(hicpp-explicit-conversions)
inline tensor_core (const matrix_expression_type<D> &expr)
Expand All @@ -208,7 +208,7 @@ class tensor_core<detail::engine_tensor_static<V,L,ns...>>
* @note extents are automatically extracted from the temporary matrix
*
* @param expr vector expression
*/
*/
template<class D>
// NOLINTNEXTLINE(hicpp-explicit-conversions)
inline tensor_core (const vector_expression_type<D> &expr)
Expand Down Expand Up @@ -279,6 +279,11 @@ class tensor_core<detail::engine_tensor_static<V,L,ns...>>
[[nodiscard]] inline const_reference at (I1 i1, I2 i2, Is ... is) const
{
static_assert (sizeof...(is)+2 == ublas::size_v<extents_type>);
if(sizeof...(is)+2 != this->order()){
throw std::invalid_argument("boost::numeric::ublas::tensor_core<tensor_static>::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];
}
Expand All @@ -294,6 +299,11 @@ class tensor_core<detail::engine_tensor_static<V,L,ns...>>
[[nodiscard]] inline reference at (I1 i1, I2 i2, Is ... is)
{
static_assert (sizeof...(is)+2 == ublas::size_v<extents_type>);
if(sizeof...(is)+2 != this->order()){
throw std::invalid_argument("boost::numeric::ublas::tensor_core<tensor_dynamic>::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];
}
Expand Down Expand Up @@ -453,4 +463,3 @@ using vector_static = tensor_static<V, extents<n1>, L>;
} // namespace boost::numeric::ublas::experimental

#endif