glue_join_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12 
13 
16 
17 
18 
19 template<typename T1, typename T2>
20 inline
21 void
23  {
25 
26  typedef typename T1::elem_type eT;
27 
28  const unwrap<T1> A_tmp(X.A);
29  const unwrap<T2> B_tmp(X.B);
30 
31  const Mat<eT>& A = A_tmp.M;
32  const Mat<eT>& B = B_tmp.M;
33 
34  const uword A_n_rows = A.n_rows;
35  const uword A_n_cols = A.n_cols;
36 
37  const uword B_n_rows = B.n_rows;
38  const uword B_n_cols = B.n_cols;
39 
40  const uword join_type = X.aux_uword;
41 
42  if(join_type == 0)
43  {
45  (
46  ( (A_n_cols != B_n_cols) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ),
47  "join_cols(): number of columns must be the same"
48  );
49  }
50  else
51  {
53  (
54  ( (A_n_rows != B.n_rows) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ),
55  "join_rows(): number of rows must be the same"
56  );
57  }
58 
59 
60  if( (&out != &A) && (&out != &B) )
61  {
62  if(join_type == 0) // join columns (i.e. result matrix has more rows)
63  {
64  out.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) );
65 
66  if( out.n_elem > 0 )
67  {
68  if(A.is_empty() == false)
69  {
70  out.submat(0, 0, A_n_rows-1, out.n_cols-1) = A;
71  }
72 
73  if(B.is_empty() == false)
74  {
75  out.submat(A_n_rows, 0, out.n_rows-1, out.n_cols-1) = B;
76  }
77  }
78  }
79  else // join rows (i.e. result matrix has more columns)
80  {
81  out.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols );
82 
83  if( out.n_elem > 0 )
84  {
85  if(A.is_empty() == false)
86  {
87  out.submat(0, 0, out.n_rows-1, A.n_cols-1) = A;
88  }
89 
90  if(B.is_empty() == false)
91  {
92  out.submat(0, A_n_cols, out.n_rows-1, out.n_cols-1) = B;
93  }
94  }
95  }
96  }
97  else // we have aliasing
98  {
99  Mat<eT> C;
100 
101  if(join_type == 0)
102  {
103  C.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) );
104 
105  if( C.n_elem > 0 )
106  {
107  if(A.is_empty() == false)
108  {
109  C.submat(0, 0, A_n_rows-1, C.n_cols-1) = A;
110  }
111 
112  if(B.is_empty() == false)
113  {
114  C.submat(A_n_rows, 0, C.n_rows-1, C.n_cols-1) = B;
115  }
116  }
117  }
118  else
119  {
120  C.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols );
121 
122  if( C.n_elem > 0 )
123  {
124  if(A.is_empty() == false)
125  {
126  C.submat(0, 0, C.n_rows-1, A_n_cols-1) = A;
127  }
128 
129  if(B.is_empty() == false)
130  {
131  C.submat(0, A_n_cols, C.n_rows-1, C.n_cols-1) = B;
132  }
133  }
134  }
135 
136  out.steal_mem(C);
137  }
138 
139  }
140 
141 
142 
143 template<typename T1, typename T2>
144 inline
145 void
147  {
149 
150  typedef typename T1::elem_type eT;
151 
152  const unwrap_cube<T1> A_tmp(X.A);
153  const unwrap_cube<T2> B_tmp(X.B);
154 
155  const Cube<eT>& A = A_tmp.M;
156  const Cube<eT>& B = B_tmp.M;
157 
158  if(A.n_elem == 0)
159  {
160  out = B;
161  return;
162  }
163 
164  if(B.n_elem == 0)
165  {
166  out = A;
167  return;
168  }
169 
170 
171  arma_debug_check( ( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) ), "join_slices(): size of slices must be the same" );
172 
173 
174  if( (&out != &A) && (&out != &B) )
175  {
176  out.set_size(A.n_rows, A.n_cols, A.n_slices + B.n_slices);
177 
178  out.slices(0, A.n_slices-1 ) = A;
179  out.slices(A.n_slices, out.n_slices-1) = B;
180  }
181  else // we have aliasing
182  {
183  Cube<eT> C(A.n_rows, A.n_cols, A.n_slices + B.n_slices);
184 
185  C.slices(0, A.n_slices-1) = A;
186  C.slices(A.n_slices, C.n_slices-1) = B;
187 
188  out.steal_mem(C);
189  }
190 
191  }
192 
193 
194 
arma_inline subview_cube< eT > slices(const uword in_slice1, const uword in_slice2)
creation of subview_cube (subcube comprised of specified slices)
Definition: Cube_meat.hpp:834
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
Definition: Mat_meat.hpp:4211
void steal_mem(Mat &X)
Definition: Mat_meat.hpp:630
arma_inline subview< eT > submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2)
creation of subview (submatrix)
Definition: Mat_meat.hpp:2092
static void apply(Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_join > &X)
void set_size(const uword in_rows, const uword in_cols, const uword in_slices)
change the cube to have user specified dimensions (data is not preserved)
Definition: Cube_meat.hpp:2414
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
const uword n_elem
number of elements in the matrix (read-only)
Definition: Mat_bones.hpp:31
arma_inline const Op< T1, op_max > max(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Delayed &#39;maximum values&#39; operation. The dimension, along which the maxima are found, is set via &#39;dim&#39;. For dim = 0, the maximum value of each column is found (i.e. searches by traversing across rows). For dim = 1, the maximum value of each row is found (i.e. searches by traversing across columns). The default is dim = 0.
Definition: fn_max.hpp:28
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
void steal_mem(Cube &X)
Definition: Cube_meat.hpp:310
u32 uword
Definition: typedef.hpp:85
const uword n_cols
number of columns in each slice (read-only)
Definition: Cube_bones.hpp:38
#define arma_debug_check
Definition: debug.hpp:1084
const T1 & A
first operand
Definition: Glue_bones.hpp:44
const Mat< eT > M
Definition: unwrap.hpp:32
Dense cube class.
Definition: Cube_bones.hpp:30
const T2 & B
second operand
Definition: Glue_bones.hpp:45
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
const uword n_elem
number of elements in the cube (read-only)
Definition: Cube_bones.hpp:41
Dense matrix class.
const T2 & B
second operand
const Cube< eT > M
Definition: unwrap_cube.hpp:33
const T1 & A
first operand
uword aux_uword
storage of auxiliary data, uword format
Definition: Glue_bones.hpp:46
analog of the Glue class, intended for Cube objects
arma_inline arma_warn_unused bool is_empty() const
returns true if the matrix has no elements
Definition: Mat_meat.hpp:3812
const uword n_slices
number of slices in the cube (read-only)
Definition: Cube_bones.hpp:40
const uword n_rows
number of rows in each slice (read-only)
Definition: Cube_bones.hpp:37


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:57