From c83caaa0da8f26f7db5bbeb28f07a75b4bd5ab98 Mon Sep 17 00:00:00 2001 From: conrad Date: Sat, 18 Jan 2025 23:56:57 +1000 Subject: [PATCH] more efficient handling of expressions --- include/armadillo_bits/op_resize_meat.hpp | 32 ++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/include/armadillo_bits/op_resize_meat.hpp b/include/armadillo_bits/op_resize_meat.hpp index 87166b2c..360d093b 100644 --- a/include/armadillo_bits/op_resize_meat.hpp +++ b/include/armadillo_bits/op_resize_meat.hpp @@ -34,16 +34,36 @@ op_resize::apply(Mat& out, const Op& in) const uword new_n_rows = in.aux_uword_a; const uword new_n_cols = in.aux_uword_b; - const unwrap tmp(in.m); - const Mat& A = tmp.M; - - if(&out == &A) + if(is_Mat::value) { - op_resize::apply_mat_inplace(out, new_n_rows, new_n_cols); + const unwrap U(in.m); + const Mat& A = U.M; + + if(&out == &A) + { + op_resize::apply_mat_inplace(out, new_n_rows, new_n_cols); + } + else + { + op_resize::apply_mat_noalias(out, A, new_n_rows, new_n_cols); + } } else { - op_resize::apply_mat_noalias(out, A, new_n_rows, new_n_cols); + const quasi_unwrap U(in.m); + + if(U.is_alias(out)) + { + Mat tmp; + + op_resize::apply_mat_noalias(tmp, U.M, new_n_rows, new_n_cols); + + out.steal_mem(tmp); + } + else + { + op_resize::apply_mat_noalias(out, U.M, new_n_rows, new_n_cols); + } } }