From 6ee89edb8cf34eb2fb6759a241bae7167fcb80fc Mon Sep 17 00:00:00 2001 From: conrad Date: Wed, 12 Jun 2024 20:21:34 +1000 Subject: [PATCH] more informative error messages --- include/armadillo_bits/fn_conv_to.hpp | 34 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/include/armadillo_bits/fn_conv_to.hpp b/include/armadillo_bits/fn_conv_to.hpp index 29a291ca..aad322e8 100644 --- a/include/armadillo_bits/fn_conv_to.hpp +++ b/include/armadillo_bits/fn_conv_to.hpp @@ -57,7 +57,13 @@ conv_to::from(const Base& in, const typename arma_not_cx P(in.get_ref()); - arma_conform_check( (P.get_n_elem() != 1), "conv_to(): given object does not have exactly one element" ); + if( (arma_config::check_conform) && (P.get_n_elem() != 1) ) + { + const uword n_rows = P.get_n_rows(); + const uword n_cols = P.get_n_cols(); + + arma_conform_check_bounds(true, (arma_str::format("conv_to(): expected 1x1 matrix; got %zux%zu") % std::size_t(n_rows) % std::size_t(n_cols)) ); + } return out_eT(Proxy::use_at ? P.at(0,0) : P[0]); } @@ -78,7 +84,13 @@ conv_to::from(const Base& in, const typename arma_cx_only P(in.get_ref()); - arma_conform_check( (P.get_n_elem() != 1), "conv_to(): given object does not have exactly one element" ); + if( (arma_config::check_conform) && (P.get_n_elem() != 1) ) + { + const uword n_rows = P.get_n_rows(); + const uword n_cols = P.get_n_cols(); + + arma_conform_check_bounds(true, (arma_str::format("conv_to(): expected 1x1 matrix; got %zux%zu") % std::size_t(n_rows) % std::size_t(n_cols)) ); + } out_eT out; @@ -103,7 +115,14 @@ conv_to::from(const BaseCube& in, const typename arma_not_cx< const ProxyCube P(in.get_ref()); - arma_conform_check( (P.get_n_elem() != 1), "conv_to(): given object does not have exactly one element" ); + if( (arma_config::check_conform) && (P.get_n_elem() != 1) ) + { + const uword n_r = P.get_n_rows(); + const uword n_c = P.get_n_cols(); + const uword n_s = P.get_n_slices(); + + arma_conform_check_bounds(true, (arma_str::format("conv_to(): expected 1x1x1 cube; got %zux%zux%zu") % std::size_t(n_r) % std::size_t(n_c) % std::size_t(n_s)) ); + } return out_eT(ProxyCube::use_at ? P.at(0,0,0) : P[0]); } @@ -124,7 +143,14 @@ conv_to::from(const BaseCube& in, const typename arma_cx_only const ProxyCube P(in.get_ref()); - arma_conform_check( (P.get_n_elem() != 1), "conv_to(): given object does not have exactly one element" ); + if( (arma_config::check_conform) && (P.get_n_elem() != 1) ) + { + const uword n_r = P.get_n_rows(); + const uword n_c = P.get_n_cols(); + const uword n_s = P.get_n_slices(); + + arma_conform_check_bounds(true, (arma_str::format("conv_to(): expected 1x1x1 cube; got %zux%zux%zu") % std::size_t(n_r) % std::size_t(n_c) % std::size_t(n_s)) ); + } out_eT out;