$search
00001 // Copyright (C) 2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2011 Conrad Sanderson 00003 // 00004 // This file is part of the Armadillo C++ library. 00005 // It is provided without any warranty of fitness 00006 // for any purpose. You can redistribute this file 00007 // and/or modify it under the terms of the GNU 00008 // Lesser General Public License (LGPL) as published 00009 // by the Free Software Foundation, either version 3 00010 // of the License or (at your option) any later version. 00011 // (see http://www.opensource.org/licenses for more info) 00012 00013 00014 00017 00018 00019 00020 template<typename T1> 00021 inline 00022 void 00023 op_resize::apply(Mat<typename T1::elem_type>& actual_out, const Op<T1,op_resize>& in) 00024 { 00025 arma_extra_debug_sigprint(); 00026 00027 typedef typename T1::elem_type eT; 00028 00029 const uword out_n_rows = in.aux_uword_a; 00030 const uword out_n_cols = in.aux_uword_b; 00031 00032 const unwrap<T1> tmp(in.m); 00033 const Mat<eT>& A = tmp.M; 00034 00035 const uword A_n_rows = A.n_rows; 00036 const uword A_n_cols = A.n_cols; 00037 00038 Mat<eT> B; 00039 00040 const bool alias = (&actual_out == &A); 00041 00042 Mat<eT>& out = alias ? B : actual_out; 00043 00044 out.set_size(out_n_rows, out_n_cols); 00045 00046 if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) ) 00047 { 00048 out.zeros(); 00049 } 00050 00051 if( (out.n_elem > 0) && (A.n_elem > 0) ) 00052 { 00053 const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1; 00054 const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1; 00055 00056 out.submat(0, 0, end_row, end_col) = A.submat(0, 0, end_row, end_col); 00057 } 00058 00059 if(alias) 00060 { 00061 actual_out.steal_mem(B); 00062 } 00063 00064 } 00065 00066 00067 00068 template<typename T1> 00069 inline 00070 void 00071 op_resize::apply(Cube<typename T1::elem_type>& actual_out, const OpCube<T1,op_resize>& in) 00072 { 00073 arma_extra_debug_sigprint(); 00074 00075 typedef typename T1::elem_type eT; 00076 00077 const uword out_n_rows = in.aux_uword_a; 00078 const uword out_n_cols = in.aux_uword_b; 00079 const uword out_n_slices = in.aux_uword_c; 00080 00081 const unwrap_cube<T1> tmp(in.m); 00082 const Cube<eT>& A = tmp.M; 00083 00084 const uword A_n_rows = A.n_rows; 00085 const uword A_n_cols = A.n_cols; 00086 const uword A_n_slices = A.n_slices; 00087 00088 Cube<eT> B; 00089 00090 const bool alias = (&actual_out == &A); 00091 00092 Cube<eT>& out = alias ? B : actual_out; 00093 00094 out.set_size(out_n_rows, out_n_cols, out_n_slices); 00095 00096 if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) || (out_n_slices > A_n_slices) ) 00097 { 00098 out.zeros(); 00099 } 00100 00101 if( (out.n_elem > 0) && (A.n_elem > 0) ) 00102 { 00103 const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1; 00104 const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1; 00105 const uword end_slice = (std::min)(out_n_slices, A_n_slices) - 1; 00106 00107 out.subcube(0, 0, 0, end_row, end_col, end_slice) = A.subcube(0, 0, 0, end_row, end_col, end_slice); 00108 } 00109 00110 if(alias) 00111 { 00112 actual_out.steal_mem(B); 00113 } 00114 00115 } 00116 00117 00118