Minimum, messy code
This commit is contained in:
@@ -70,4 +70,47 @@ std::string concatpath(const std::string &left, const std::string &right)
|
||||
}
|
||||
}
|
||||
|
||||
void print_sp_matrix_structure(const arma::sp_cx_mat &A)
|
||||
{
|
||||
using namespace std;
|
||||
using namespace arma;
|
||||
|
||||
// Declare a C-style 2D array of strings.
|
||||
string S[A.n_rows][A.n_cols];
|
||||
|
||||
// Initialise all the strings to " ".
|
||||
for (int i = 0; i < A.n_rows; i++) {
|
||||
for (int j = 0; j < A.n_cols; j++) {
|
||||
S[i][j] = " ";
|
||||
}
|
||||
}
|
||||
|
||||
// Next, we want to set the string to a dot at each non-zero element.
|
||||
// To do this we use the special loop iterator from the sp_cx_mat class
|
||||
// to help us loop over only the non-zero matrix elements.
|
||||
sp_cx_mat::const_iterator it = A.begin();
|
||||
sp_cx_mat::const_iterator it_end = A.end();
|
||||
|
||||
int nnz = 0;
|
||||
for (; it != it_end; ++it) {
|
||||
S[it.row()][it.col()] = "•";
|
||||
nnz++;
|
||||
}
|
||||
|
||||
// Finally, print the matrix to screen.
|
||||
cout << endl;
|
||||
for (int i = 0; i < A.n_rows; i++) {
|
||||
cout << "| ";
|
||||
for (int j = 0; j < A.n_cols; j++) {
|
||||
cout << S[i][j] << " ";
|
||||
}
|
||||
cout << "|\n";
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
cout << "matrix size: " << A.n_rows << "x" << A.n_cols << endl;
|
||||
cout << "non-zero elements: " << nnz << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
Reference in New Issue
Block a user