diff --git a/src/print.cc b/src/print.cc index be0a9feca..e4902ecd7 100644 --- a/src/print.cc +++ b/src/print.cc @@ -1173,19 +1173,36 @@ void print( int width = get_option( opts, Option::PrintWidth, 10 ); int precision = get_option( opts, Option::PrintPrecision, 4 ); + int verbose = get_option( opts, Option::PrintVerbose, 4 ); + int edgeitems = get_option( 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() ); } //------------------------------------------------------------------------------ diff --git a/test/print_matrix.hh b/test/print_matrix.hh index a21bf81c7..0df928bbb 100644 --- a/test/print_matrix.hh +++ b/test/print_matrix.hh @@ -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() }, }; @@ -295,18 +295,7 @@ void print_vector( std::vector& 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