max@0: // Copyright (C) 2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2011 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: max@0: //! \addtogroup op_resize max@0: //! @{ max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: op_resize::apply(Mat& actual_out, const Op& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword out_n_rows = in.aux_uword_a; max@0: const uword out_n_cols = in.aux_uword_b; max@0: max@0: const unwrap tmp(in.m); max@0: const Mat& A = tmp.M; max@0: max@0: const uword A_n_rows = A.n_rows; max@0: const uword A_n_cols = A.n_cols; max@0: max@0: Mat B; max@0: max@0: const bool alias = (&actual_out == &A); max@0: max@0: Mat& out = alias ? B : actual_out; max@0: max@0: out.set_size(out_n_rows, out_n_cols); max@0: max@0: if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) ) max@0: { max@0: out.zeros(); max@0: } max@0: max@0: if( (out.n_elem > 0) && (A.n_elem > 0) ) max@0: { max@0: const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1; max@0: const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1; max@0: max@0: out.submat(0, 0, end_row, end_col) = A.submat(0, 0, end_row, end_col); max@0: } max@0: max@0: if(alias) max@0: { max@0: actual_out.steal_mem(B); max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: op_resize::apply(Cube& actual_out, const OpCube& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const uword out_n_rows = in.aux_uword_a; max@0: const uword out_n_cols = in.aux_uword_b; max@0: const uword out_n_slices = in.aux_uword_c; max@0: max@0: const unwrap_cube tmp(in.m); max@0: const Cube& A = tmp.M; max@0: max@0: const uword A_n_rows = A.n_rows; max@0: const uword A_n_cols = A.n_cols; max@0: const uword A_n_slices = A.n_slices; max@0: max@0: Cube B; max@0: max@0: const bool alias = (&actual_out == &A); max@0: max@0: Cube& out = alias ? B : actual_out; max@0: max@0: out.set_size(out_n_rows, out_n_cols, out_n_slices); max@0: max@0: if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) || (out_n_slices > A_n_slices) ) max@0: { max@0: out.zeros(); max@0: } max@0: max@0: if( (out.n_elem > 0) && (A.n_elem > 0) ) max@0: { max@0: const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1; max@0: const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1; max@0: const uword end_slice = (std::min)(out_n_slices, A_n_slices) - 1; max@0: max@0: out.subcube(0, 0, 0, end_row, end_col, end_slice) = A.subcube(0, 0, 0, end_row, end_col, end_slice); max@0: } max@0: max@0: if(alias) max@0: { max@0: actual_out.steal_mem(B); max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: //! @}