Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add matrix and vector print functions #1214

Merged
merged 2 commits into from
May 13, 2024

Conversation

bernlu
Copy link
Contributor

@bernlu bernlu commented May 2, 2024

No description provided.

fabratu
fabratu previously approved these changes May 3, 2024
Comment on lines 457 to 471
namespace NetworKit {
// print functions for test debugging / output
inline std::ostream &operator<<(std::ostream &os, const DynamicMatrix &M) {
for (index i = 0; i < M.numberOfRows(); i++) {
if (i != 0)
os << std::endl;
for (index j = 0; j < M.numberOfColumns(); j++) {
if (j != 0)
os << ", ";
os << M(i, j);
}
}
return os;
}
} // namespace NetworKit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all matrix classes support a (row, col) operator, we should implement this function only once in a MatrixUtil.hpp, e.g.:

// MatrixUtil.hpp

template <class MatrixType>
std::ostream &printMatrix(std::ostream &ostream, const MatrixType& matrix) {
  // ...
  return os;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I suggest using row and col instead of i and j, and use pre-increment instead of post-increment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed the variables.

Considering that there are many other duplicate functions in our three matrix classes, I think a more useful change would be to create a Matrix superclass for all of these functions, and define the print function in this superclass. That is a project for another time though and for now I think it is fine to implement the print function in all three classes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes having a Matrix superclass would be much better.

@fabratu fabratu merged commit 7546fdc into networkit:master May 13, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants