-
Notifications
You must be signed in to change notification settings - Fork 222
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
Conversation
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 |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
No description provided.