121{
122 sp_mat::const_iterator itA = A.begin();
123 sp_mat::const_iterator endA = A.end();
124 sp_mat::const_iterator itB = B.begin();
125 sp_mat::const_iterator endB = B.end();
126 u32 j = 0;
127
128 vec a = nonzeros(A);
129 vec b = nonzeros(B);
130
131 umat locations(2, a.n_elem + b.n_elem);
132 vec values(a.n_elem + b.n_elem);
133
134 while(itA != endA) {
135 locations(0, j) = itA.row();
136 locations(1, j) = itA.col();
137 values(j) = (*itA);
138 ++itA;
139 ++j;
140 }
141
142 while(itB != endB) {
143 locations(0, j) = itB.row() + A.n_rows;
144 locations(1, j) = itB.col();
145 values(j) = (*itB);
146 ++itB;
147 ++j;
148 }
149
150 sp_mat result(locations, values, A.n_rows+B.n_rows, A.n_cols, true);
151
152 return result;
153}