$search
00001 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2008-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 00016 00017 00018 00019 template<typename T1, typename T2> 00020 inline 00021 void 00022 glue_join::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_join>& X) 00023 { 00024 arma_extra_debug_sigprint(); 00025 00026 typedef typename T1::elem_type eT; 00027 00028 const unwrap<T1> A_tmp(X.A); 00029 const unwrap<T2> B_tmp(X.B); 00030 00031 const Mat<eT>& A = A_tmp.M; 00032 const Mat<eT>& B = B_tmp.M; 00033 00034 const uword A_n_rows = A.n_rows; 00035 const uword A_n_cols = A.n_cols; 00036 00037 const uword B_n_rows = B.n_rows; 00038 const uword B_n_cols = B.n_cols; 00039 00040 const uword join_type = X.aux_uword; 00041 00042 if(join_type == 0) 00043 { 00044 arma_debug_check 00045 ( 00046 ( (A_n_cols != B_n_cols) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), 00047 "join_cols(): number of columns must be the same" 00048 ); 00049 } 00050 else 00051 { 00052 arma_debug_check 00053 ( 00054 ( (A_n_rows != B.n_rows) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), 00055 "join_rows(): number of rows must be the same" 00056 ); 00057 } 00058 00059 00060 if( (&out != &A) && (&out != &B) ) 00061 { 00062 if(join_type == 0) // join columns (i.e. result matrix has more rows) 00063 { 00064 out.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) ); 00065 00066 if( out.n_elem > 0 ) 00067 { 00068 if(A.is_empty() == false) 00069 { 00070 out.submat(0, 0, A_n_rows-1, out.n_cols-1) = A; 00071 } 00072 00073 if(B.is_empty() == false) 00074 { 00075 out.submat(A_n_rows, 0, out.n_rows-1, out.n_cols-1) = B; 00076 } 00077 } 00078 } 00079 else // join rows (i.e. result matrix has more columns) 00080 { 00081 out.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols ); 00082 00083 if( out.n_elem > 0 ) 00084 { 00085 if(A.is_empty() == false) 00086 { 00087 out.submat(0, 0, out.n_rows-1, A.n_cols-1) = A; 00088 } 00089 00090 if(B.is_empty() == false) 00091 { 00092 out.submat(0, A_n_cols, out.n_rows-1, out.n_cols-1) = B; 00093 } 00094 } 00095 } 00096 } 00097 else // we have aliasing 00098 { 00099 Mat<eT> C; 00100 00101 if(join_type == 0) 00102 { 00103 C.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) ); 00104 00105 if( C.n_elem > 0 ) 00106 { 00107 if(A.is_empty() == false) 00108 { 00109 C.submat(0, 0, A_n_rows-1, C.n_cols-1) = A; 00110 } 00111 00112 if(B.is_empty() == false) 00113 { 00114 C.submat(A_n_rows, 0, C.n_rows-1, C.n_cols-1) = B; 00115 } 00116 } 00117 } 00118 else 00119 { 00120 C.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols ); 00121 00122 if( C.n_elem > 0 ) 00123 { 00124 if(A.is_empty() == false) 00125 { 00126 C.submat(0, 0, C.n_rows-1, A_n_cols-1) = A; 00127 } 00128 00129 if(B.is_empty() == false) 00130 { 00131 C.submat(0, A_n_cols, C.n_rows-1, C.n_cols-1) = B; 00132 } 00133 } 00134 } 00135 00136 out.steal_mem(C); 00137 } 00138 00139 } 00140 00141 00142 00143 template<typename T1, typename T2> 00144 inline 00145 void 00146 glue_join::apply(Cube<typename T1::elem_type>& out, const GlueCube<T1,T2,glue_join>& X) 00147 { 00148 arma_extra_debug_sigprint(); 00149 00150 typedef typename T1::elem_type eT; 00151 00152 const unwrap_cube<T1> A_tmp(X.A); 00153 const unwrap_cube<T2> B_tmp(X.B); 00154 00155 const Cube<eT>& A = A_tmp.M; 00156 const Cube<eT>& B = B_tmp.M; 00157 00158 if(A.n_elem == 0) 00159 { 00160 out = B; 00161 return; 00162 } 00163 00164 if(B.n_elem == 0) 00165 { 00166 out = A; 00167 return; 00168 } 00169 00170 00171 arma_debug_check( ( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) ), "join_slices(): size of slices must be the same" ); 00172 00173 00174 if( (&out != &A) && (&out != &B) ) 00175 { 00176 out.set_size(A.n_rows, A.n_cols, A.n_slices + B.n_slices); 00177 00178 out.slices(0, A.n_slices-1 ) = A; 00179 out.slices(A.n_slices, out.n_slices-1) = B; 00180 } 00181 else // we have aliasing 00182 { 00183 Cube<eT> C(A.n_rows, A.n_cols, A.n_slices + B.n_slices); 00184 00185 C.slices(0, A.n_slices-1) = A; 00186 C.slices(A.n_slices, C.n_slices-1) = B; 00187 00188 out.steal_mem(C); 00189 } 00190 00191 } 00192 00193 00194