Skip to content

Commit

Permalink
print: use verbose settings for print vectors same as for matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
mgates3 committed May 28, 2024
1 parent deb1858 commit 5709ede
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
33 changes: 25 additions & 8 deletions src/print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1173,19 +1173,36 @@ void print(

int width = get_option<int>( opts, Option::PrintWidth, 10 );
int precision = get_option<int>( opts, Option::PrintPrecision, 4 );
int verbose = get_option<int>( opts, Option::PrintVerbose, 4 );
int edgeitems = get_option<int>( opts, Option::PrintEdgeItems, 16 );

width = std::max(width, precision + 6);

char buf[ 80 ];
std::string msg;
printf( "%% %s: vector, n=%lld\n", label, llong( n ) );

if (verbose > 1) {
char buf[ 80 ];
std::string msg;

int64_t ix = (incx > 0 ? 0 : (-n + 1)*incx);
for (int64_t i = 0; i < n; ++i) {
snprintf_value( buf, sizeof(buf), width, precision, x[ix] );
msg += buf;
ix += incx;
int64_t n1 = n, n2 = n;
if (verbose == 2) {
n1 = edgeitems;
n2 = n - edgeitems;
}

int64_t ix = 0;
for (int64_t i = 0; i < n; ++i) {
if (i == n1 && i < n2) {
msg += " ... ";
ix += incx*(n2 - n1);
i = n2;
}
snprintf_value( buf, sizeof(buf), width, precision, x[ix] );
msg += buf;
ix += incx;
}
printf( "%s = [ %s ]';\n", label, msg.c_str() );
}
printf( "%s = [ %s ]';\n", label, msg.c_str() );
}

//------------------------------------------------------------------------------
Expand Down
17 changes: 3 additions & 14 deletions test/print_matrix.hh
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ void print_vector(

// Set defaults
const slate::Options opts = {
{ slate::Option::PrintWidth, params.print_width() },
{ slate::Option::PrintWidth, params.print_width() },
{ slate::Option::PrintPrecision, params.print_precision() },
{ slate::Option::PrintVerbose, params.verbose() },
{ slate::Option::PrintVerbose, params.verbose() },
{ slate::Option::PrintEdgeItems, params.print_edgeitems() },
};

Expand All @@ -295,18 +295,7 @@ void print_vector(
std::vector<scalar_t>& x,
Params& params)
{
if (params.verbose() == 0)
return;

// Set defaults
const slate::Options opts = {
{ slate::Option::PrintWidth, params.print_width() },
{ slate::Option::PrintPrecision, params.print_precision() },
{ slate::Option::PrintVerbose, params.verbose() },
{ slate::Option::PrintEdgeItems, params.print_edgeitems() },
};

slate::print( label, x, opts );
print_vector( label, x.size(), &x[0], 1, params );
}

#endif // SLATE_PRINT_MATRIX_HH

0 comments on commit 5709ede

Please sign in to comment.