void pushMatrix_row(mat& MATRIX, mat ToBePushed) { // cout<< "MATRIX" << MATRIX.n_rows<< ", " <<MATRIX.n_cols <<endl; // cout<< "ToBePushed" << ToBePushed.n_rows << ", " << ToBePushed.n_cols <<endl; if (MATRIX.is_empty()) { // cout <<__LINE__<<endl; MATRIX.resize(ToBePushed.n_rows, ToBePushed.n_cols); for(int i = 0; i < ToBePushed.n_rows; i ++) { for (int j = 0; j < ToBePushed.n_cols; j ++) { MATRIX.at(i, j) = ToBePushed.at(i, j); } } return; } if (MATRIX.n_rows != ToBePushed.n_rows) { cout << " wrong dimension!" <<endl; abort(); } mat tmp; tmp.zeros(MATRIX.n_rows, MATRIX.n_cols + ToBePushed.n_cols); // cout<<"tmp: " << tmp.n_rows <<", " <<tmp.n_cols <<endl; for(int i = 0; i < MATRIX.n_rows; i ++) { // cout << i <<endl; for(int j = 0; j < MATRIX.n_cols; j ++) { tmp.at(i,j) = MATRIX.at(i,j); } } for(int i = 0; i < ToBePushed.n_rows; i ++) { for(int j = 0; j < ToBePushed.n_cols; j ++) { tmp.at(i, j + MATRIX.n_cols) = ToBePushed.at(i, j); // cout<<__LINE__<<endl; } } MATRIX = tmp; }
void pushMatrix_col(mat& MATRIX, mat ToBePushed) { if (MATRIX.is_empty()) { MATRIX.resize(ToBePushed.n_rows, ToBePushed.n_cols); for(int i = 0; i < ToBePushed.n_rows; i ++) { for (int j = 0; j < ToBePushed.n_cols; j ++) { MATRIX.at(i, j) = ToBePushed.at(i, j); } } return; } if(MATRIX.n_cols != ToBePushed.n_cols) { cout << " wrong dimension!" <<endl; abort(); } mat tmp; tmp.zeros(MATRIX.n_rows + ToBePushed.n_rows, MATRIX.n_cols); for (int i = 0; i < MATRIX.n_rows; i ++) { for (int j = 0; j < MATRIX.n_cols; j ++) { tmp.at(i,j) = MATRIX.at(i,j); } } for (int i = 0; i < ToBePushed.n_rows; i ++) { for ( int j = 0; j < ToBePushed.n_rows; j ++) { tmp.at(i + MATRIX.n_rows, j) = ToBePushed.at(i,j); } } MATRIX = tmp; }