max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-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_reshape max@0: //! @{ max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: op_reshape::apply(Mat& 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 unwrap tmp(in.m); max@0: const Mat& A = tmp.M; max@0: max@0: const uword in_n_rows = in.aux_uword_a; max@0: const uword in_n_cols = in.aux_uword_b; max@0: const uword in_dim = in.aux_uword_c; max@0: max@0: const uword in_n_elem = in_n_rows * in_n_cols; max@0: max@0: if(A.n_elem == in_n_elem) max@0: { max@0: if(in_dim == 0) max@0: { max@0: if(&out != &A) max@0: { max@0: out.set_size(in_n_rows, in_n_cols); max@0: arrayops::copy( out.memptr(), A.memptr(), out.n_elem ); max@0: } max@0: else // &out == &A, i.e. inplace resize max@0: { max@0: const bool same_size = ( (out.n_rows == in_n_rows) && (out.n_cols == in_n_cols) ); max@0: max@0: if(same_size == false) max@0: { max@0: arma_debug_check max@0: ( max@0: (out.mem_state == 3), max@0: "reshape(): size can't be changed as template based size specification is in use" max@0: ); max@0: max@0: access::rw(out.n_rows) = in_n_rows; max@0: access::rw(out.n_cols) = in_n_cols; max@0: } max@0: } max@0: } max@0: else max@0: { max@0: unwrap_check< Mat > tmp(A, out); max@0: const Mat& B = tmp.M; max@0: max@0: out.set_size(in_n_rows, in_n_cols); max@0: max@0: eT* out_mem = out.memptr(); max@0: uword i = 0; max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: for(uword row=0; row > tmp(A, out); max@0: const Mat& B = tmp.M; max@0: max@0: const uword n_elem_to_copy = (std::min)(B.n_elem, in_n_elem); max@0: max@0: out.set_size(in_n_rows, in_n_cols); max@0: max@0: eT* out_mem = out.memptr(); max@0: max@0: if(in_dim == 0) max@0: { max@0: arrayops::copy( out_mem, B.memptr(), n_elem_to_copy ); max@0: } max@0: else max@0: { max@0: uword row = 0; max@0: uword col = 0; max@0: max@0: const uword B_n_cols = B.n_cols; max@0: max@0: for(uword i=0; i= B_n_cols) max@0: { max@0: col = 0; max@0: ++row; max@0: } max@0: } max@0: } max@0: max@0: for(uword i=n_elem_to_copy; i max@0: inline max@0: void max@0: op_reshape::apply(Cube& 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 unwrap_cube tmp(in.m); max@0: const Cube& A = tmp.M; max@0: max@0: const uword in_n_rows = in.aux_uword_a; max@0: const uword in_n_cols = in.aux_uword_b; max@0: const uword in_n_slices = in.aux_uword_c; max@0: const uword in_dim = in.aux_uword_d; max@0: max@0: const uword in_n_elem = in_n_rows * in_n_cols * in_n_slices; max@0: max@0: if(A.n_elem == in_n_elem) max@0: { max@0: if(in_dim == 0) max@0: { max@0: if(&out != &A) max@0: { max@0: out.set_size(in_n_rows, in_n_cols, in_n_slices); max@0: arrayops::copy( out.memptr(), A.memptr(), out.n_elem ); max@0: } max@0: else // &out == &A, i.e. inplace resize max@0: { max@0: const bool same_size = ( (out.n_rows == in_n_rows) && (out.n_cols == in_n_cols) && (out.n_slices == in_n_slices) ); max@0: max@0: if(same_size == false) max@0: { max@0: arma_debug_check max@0: ( max@0: (out.mem_state == 3), max@0: "reshape(): size can't be changed as template based size specification is in use" max@0: ); max@0: max@0: out.delete_mat(); max@0: max@0: access::rw(out.n_rows) = in_n_rows; max@0: access::rw(out.n_cols) = in_n_cols; max@0: access::rw(out.n_elem_slice) = in_n_rows * in_n_cols; max@0: access::rw(out.n_slices) = in_n_slices; max@0: max@0: out.create_mat(); max@0: } max@0: } max@0: } max@0: else max@0: { max@0: unwrap_cube_check< Cube > tmp(A, out); max@0: const Cube& B = tmp.M; max@0: max@0: out.set_size(in_n_rows, in_n_cols, in_n_slices); max@0: max@0: eT* out_mem = out.memptr(); max@0: uword i = 0; max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: const uword B_n_slices = B.n_slices; max@0: max@0: for(uword slice=0; slice > tmp(A, out); max@0: const Cube& B = tmp.M; max@0: max@0: const uword n_elem_to_copy = (std::min)(B.n_elem, in_n_elem); max@0: max@0: out.set_size(in_n_rows, in_n_cols, in_n_slices); max@0: max@0: eT* out_mem = out.memptr(); max@0: max@0: if(in_dim == 0) max@0: { max@0: arrayops::copy( out_mem, B.memptr(), n_elem_to_copy ); max@0: } max@0: else max@0: { max@0: uword row = 0; max@0: uword col = 0; max@0: uword slice = 0; max@0: max@0: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: for(uword i=0; i= B_n_cols) max@0: { max@0: col = 0; max@0: ++row; max@0: max@0: if(row >= B_n_rows) max@0: { max@0: row = 0; max@0: ++slice; max@0: } max@0: } max@0: } max@0: } max@0: max@0: for(uword i=n_elem_to_copy; i