matrix: adjust printing for if symmetric (lower triangular only)

This commit is contained in:
Daniel Agar 2024-01-16 10:20:21 -05:00 committed by GitHub
parent 64f28c4c07
commit c3ae7b28c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 9 deletions

View File

@ -365,7 +365,7 @@ public:
}
}
void print(float eps = 0.00001f) const
void print(float eps = 1e-9) const
{
// print column numbering
if (N > 1) {
@ -393,6 +393,14 @@ public:
printf("\033[1m");
}
// if symmetric don't print upper triangular elements
if ((M == N) && (j > i) && (i < N) && (j < M)
&& (fabs(d - static_cast<double>(self(j, i))) < (double)eps)
) {
// print empty space
printf(" ");
} else {
// avoid -0.0 for display
if (fabs(d - 0.0) < (double)eps) {
// print fixed width zero
@ -404,6 +412,7 @@ public:
} else {
printf("% 6.5f ", d);
}
}
// Matrix diagonal elements
if (N > 1 && M > 1 && i == j) {