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: //! \addtogroup glue_join max@0: //! @{ max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: glue_join::apply(Mat& out, const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const unwrap A_tmp(X.A); max@0: const unwrap B_tmp(X.B); max@0: max@0: const Mat& A = A_tmp.M; max@0: const Mat& B = B_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: const uword B_n_rows = B.n_rows; max@0: const uword B_n_cols = B.n_cols; max@0: max@0: const uword join_type = X.aux_uword; max@0: max@0: if(join_type == 0) max@0: { max@0: arma_debug_check max@0: ( max@0: ( (A_n_cols != B_n_cols) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), max@0: "join_cols(): number of columns must be the same" max@0: ); max@0: } max@0: else max@0: { max@0: arma_debug_check max@0: ( max@0: ( (A_n_rows != B.n_rows) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), max@0: "join_rows(): number of rows must be the same" max@0: ); max@0: } max@0: max@0: max@0: if( (&out != &A) && (&out != &B) ) max@0: { max@0: if(join_type == 0) // join columns (i.e. result matrix has more rows) max@0: { max@0: out.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) ); max@0: max@0: if( out.n_elem > 0 ) max@0: { max@0: if(A.is_empty() == false) max@0: { max@0: out.submat(0, 0, A_n_rows-1, out.n_cols-1) = A; max@0: } max@0: max@0: if(B.is_empty() == false) max@0: { max@0: out.submat(A_n_rows, 0, out.n_rows-1, out.n_cols-1) = B; max@0: } max@0: } max@0: } max@0: else // join rows (i.e. result matrix has more columns) max@0: { max@0: out.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols ); max@0: max@0: if( out.n_elem > 0 ) max@0: { max@0: if(A.is_empty() == false) max@0: { max@0: out.submat(0, 0, out.n_rows-1, A.n_cols-1) = A; max@0: } max@0: max@0: if(B.is_empty() == false) max@0: { max@0: out.submat(0, A_n_cols, out.n_rows-1, out.n_cols-1) = B; max@0: } max@0: } max@0: } max@0: } max@0: else // we have aliasing max@0: { max@0: Mat C; max@0: max@0: if(join_type == 0) max@0: { max@0: C.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) ); max@0: max@0: if( C.n_elem > 0 ) max@0: { max@0: if(A.is_empty() == false) max@0: { max@0: C.submat(0, 0, A_n_rows-1, C.n_cols-1) = A; max@0: } max@0: max@0: if(B.is_empty() == false) max@0: { max@0: C.submat(A_n_rows, 0, C.n_rows-1, C.n_cols-1) = B; max@0: } max@0: } max@0: } max@0: else max@0: { max@0: C.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols ); max@0: max@0: if( C.n_elem > 0 ) max@0: { max@0: if(A.is_empty() == false) max@0: { max@0: C.submat(0, 0, C.n_rows-1, A_n_cols-1) = A; max@0: } max@0: max@0: if(B.is_empty() == false) max@0: { max@0: C.submat(0, A_n_cols, C.n_rows-1, C.n_cols-1) = B; max@0: } max@0: } max@0: } max@0: max@0: out.steal_mem(C); max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: glue_join::apply(Cube& out, const GlueCube& X) 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 A_tmp(X.A); max@0: const unwrap_cube B_tmp(X.B); max@0: max@0: const Cube& A = A_tmp.M; max@0: const Cube& B = B_tmp.M; max@0: max@0: if(A.n_elem == 0) max@0: { max@0: out = B; max@0: return; max@0: } max@0: max@0: if(B.n_elem == 0) max@0: { max@0: out = A; max@0: return; max@0: } max@0: max@0: max@0: arma_debug_check( ( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) ), "join_slices(): size of slices must be the same" ); max@0: max@0: max@0: if( (&out != &A) && (&out != &B) ) max@0: { max@0: out.set_size(A.n_rows, A.n_cols, A.n_slices + B.n_slices); max@0: max@0: out.slices(0, A.n_slices-1 ) = A; max@0: out.slices(A.n_slices, out.n_slices-1) = B; max@0: } max@0: else // we have aliasing max@0: { max@0: Cube C(A.n_rows, A.n_cols, A.n_slices + B.n_slices); max@0: max@0: C.slices(0, A.n_slices-1) = A; max@0: C.slices(A.n_slices, C.n_slices-1) = B; max@0: max@0: out.steal_mem(C); max@0: } max@0: max@0: } max@0: max@0: max@0: max@0: //! @}