From fa460e0b336f4da64aa936ef8cc168fe75fadfec Mon Sep 17 00:00:00 2001 From: conrad Date: Mon, 20 Dec 2021 13:20:07 +1000 Subject: [PATCH] simplifications + fixes --- include/armadillo_bits/op_reshape_meat.hpp | 38 +++++----------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/include/armadillo_bits/op_reshape_meat.hpp b/include/armadillo_bits/op_reshape_meat.hpp index d42c8311..62fabdd2 100644 --- a/include/armadillo_bits/op_reshape_meat.hpp +++ b/include/armadillo_bits/op_reshape_meat.hpp @@ -85,22 +85,11 @@ op_reshape::apply_mat_inplace(Mat& A, const uword new_n_rows, const uword ne if(A.n_elem == new_n_elem) { A.set_size(new_n_rows, new_n_cols); return; } - const uword n_elem_to_copy = (std::min)(A.n_elem, new_n_elem); + Mat B; - Mat tmp(new_n_rows, new_n_cols, arma_nozeros_indicator()); + op_reshape::apply_mat_noalias(B, A, new_n_rows, new_n_cols); - eT* tmp_mem = tmp.memptr(); - - arrayops::copy( tmp_mem, A.memptr(), n_elem_to_copy ); - - if(n_elem_to_copy < new_n_elem) - { - const uword n_elem_leftover = new_n_elem - n_elem_to_copy; - - arrayops::fill_zeros(&(tmp_mem[n_elem_to_copy]), n_elem_leftover); - } - - A.steal_mem(tmp); + A.steal_mem(B); } @@ -220,22 +209,11 @@ op_reshape::apply_cube_inplace(Cube& A, const uword new_n_rows, const uword if(A.n_elem == new_n_elem) { A.set_size(new_n_rows, new_n_cols, new_n_slices); return; } - const uword n_elem_to_copy = (std::min)(A.n_elem, new_n_elem); + Cube B; - Cube tmp(new_n_rows, new_n_cols, new_n_slices); + op_reshape::apply_cube_noalias(B, A, new_n_rows, new_n_cols, new_n_slices); - eT* tmp_mem = tmp.memptr(); - - arrayops::copy( tmp_mem, A.memptr(), n_elem_to_copy ); - - if(n_elem_to_copy < new_n_elem) - { - const uword n_elem_leftover = new_n_elem - n_elem_to_copy; - - arrayops::fill_zeros(&(tmp_mem[n_elem_to_copy]), n_elem_leftover); - } - - A.steal_mem(tmp); + A.steal_mem(B); } @@ -292,7 +270,7 @@ op_reshape_old::apply(Mat& out, const Op& out, const Mat& A, const uword ne op_strans::apply_mat_noalias(tmp, A); - op_reshape::apply_mat_noalias(A, tmp, new_n_rows, new_n_cols); + op_reshape::apply_mat_noalias(out, tmp, new_n_rows, new_n_cols); } }