From d4ac8e535eecd0c7bf5293caeddb3f92c52fb9ca Mon Sep 17 00:00:00 2001 From: conrad Date: Mon, 24 Jun 2024 00:18:10 +1000 Subject: [PATCH] catch size errors early --- include/armadillo_bits/op_reshape_meat.hpp | 3 +++ include/armadillo_bits/op_resize_meat.hpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/armadillo_bits/op_reshape_meat.hpp b/include/armadillo_bits/op_reshape_meat.hpp index 453c613f..322223d2 100644 --- a/include/armadillo_bits/op_reshape_meat.hpp +++ b/include/armadillo_bits/op_reshape_meat.hpp @@ -81,6 +81,9 @@ op_reshape::apply_mat_inplace(Mat& A, const uword new_n_rows, const uword ne { arma_debug_sigprint(); + arma_conform_check( (A.vec_state == 1) && (new_n_cols != 1), "reshape(): requested size is not compatible with column vector layout" ); + arma_conform_check( (A.vec_state == 2) && (new_n_rows != 1), "reshape(): requested size is not compatible with row vector layout" ); + const uword new_n_elem = new_n_rows * new_n_cols; if(A.n_elem == new_n_elem) { A.set_size(new_n_rows, new_n_cols); return; } diff --git a/include/armadillo_bits/op_resize_meat.hpp b/include/armadillo_bits/op_resize_meat.hpp index 5abdc992..5db5d425 100644 --- a/include/armadillo_bits/op_resize_meat.hpp +++ b/include/armadillo_bits/op_resize_meat.hpp @@ -58,6 +58,9 @@ op_resize::apply_mat_inplace(Mat& A, const uword new_n_rows, const uword new if( (A.n_rows == new_n_rows) && (A.n_cols == new_n_cols) ) { return; } + arma_conform_check( (A.vec_state == 1) && (new_n_cols != 1), "resize(): requested size is not compatible with column vector layout" ); + arma_conform_check( (A.vec_state == 2) && (new_n_rows != 1), "resize(): requested size is not compatible with row vector layout" ); + if(A.is_empty()) { A.zeros(new_n_rows, new_n_cols); return; } Mat B;