gpp_logging

Contents:

gpp_logging.hpp

This file contains some macros wrapping std::printf(). Currently, the “log file” is just stdout. And the verbosity level must be chosen at compile-time, although we do provide separate macros for debug, verbose, warning, and error.

We also have utilities for printing commonly used structures in the code. Currently this file contains a printer for an array of ClosedInterval.

Long term, this file will connect to a real logging library.

TODO(GH-130): connect MOE/C++ to a real logging library instead of using stdout as our log.

Defines

OL_DEBUG_PRINTF(...)

Macro wrapper for printf so it can be easily disabled via the compiler option OL_DEBUG_PRINT. This is meant to give extra details about internal workings/state of code.

OL_VERBOSE_PRINTF(...)

Macro wrapper for printf so it can be easily disabled via the compiler option OL_VERBOSE_PRINT. This is meant to provide extra information about convergence characteristics, etc.

OL_WARNING_PRINTF(...)

Macro wrapper for printf so it can be easily disabled via the compiler option OL_WARNING_PRINT. This is meant for printing messages that are warnings–something went wrong, but the error is not severe enough to warrant exiting.

OL_ERROR_PRINTF(...)

Macro wrapper for printf so it can be easily disabled via the compiler option OL_ERROR_PRINT. This is meant for printing messages that are errors–something went catastrophically wrong.

OL_ANSI_COLOR_RESET

Macros for printf’ing in color.

Inserting these macros before a string component of printf() changes the color of printf until a new color or reset is specified. These macros can be interspersed between strings in printf()’s first argument (see examples).

Example usage:

printf(OL_ANSI_COLOR_GREEN "Hi I am %d" OL_ANSI_COLOR_RESET "And you are %d\n", 2, 3);

Would print:

Hi I am 2 And you are 3.
|  GREEN | DEFAULT COLOR|

Without reset, the following would happen:

printf(OL_ANSI_COLOR_GREEN "Hi I am %d\n", 2);
printf("And you are %d\n", 3);
Hi I am 2     <--- in green
And you are 3 <--- ALSO in green!

OL_ANSI_COLOR_RED

OL_ANSI_COLOR_BLACK

OL_ANSI_COLOR_GREEN

OL_ANSI_COLOR_YELLOW

OL_ANSI_COLOR_BLUE

OL_ANSI_COLOR_MAGENTA

OL_ANSI_COLOR_CYAN

OL_ANSI_COLOR_WHITE

OL_ANSI_COLOR_BOLDBLACK

OL_ANSI_COLOR_BOLDRED

OL_ANSI_COLOR_BOLDGREEN

OL_ANSI_COLOR_BOLDYELLOW

OL_ANSI_COLOR_BOLDBLUE

OL_ANSI_COLOR_BOLDMAGENTA

OL_ANSI_COLOR_BOLDCYAN

OL_ANSI_COLOR_BOLDWHITE

OL_SUCCESS_PRINTF(...)

OL_FAILURE_PRINTF(...)

OL_PARTIAL_SUCCESS_PRINTF(...)

OL_PARTIAL_FAILURE_PRINTF(...)

namespace optimal_learning

Macro to allow restrict as a keyword for C++ compilation and CUDA/nvcc compilation. See related entry in gpp_common.hpp for more details.

gpp_logging.cpp

Utilities for printing commonly used structures. We put printing code here to hide std::printf() calls.

namespace optimal_learning

Macro to allow restrict as a keyword for C++ compilation and CUDA/nvcc compilation. See related entry in gpp_common.hpp for more details.

Functions

void PrintMatrix(double const *restrict matrix, int num_rows, int num_cols)

Since matrices are stored column-major and the natural screen-printed formatting is by rows, we need to access the matrix in transposed order.

void PrintMatrixTrans(double const *restrict matrix, int num_rows, int num_cols)

Opposite PrintMatrix(), the screen formatted ordering here is the same as the matrix storage ordering.

Utility function to print a 2D matrix (formatted) to stdout. Uses %.18E descriptors to printf.

For example, the input: A[3][4] = [4 53 81 32 12 2 5 8 93 2 1 0]

would be printed as (with decimal points removed):

4  32  5  2
53 12  8  1
81  2  93 0

No inputs may be nullptr.

Parameters:
matrix[num_rows][num_cols]:
 matrix to be printed
num_rows:number of rows
num_cols:number of columns

emdrst*/ void PrintMatrix(double const * restrict matrix, int num_rows, int num_cols) noexcept OL_NONNULL_POINTERS;

/*!verbatim embed:rst

Utility function to print the TRANSPOSE of a 2D matrix (formatted) to stdout. Uses %.18E descriptors to printf.

For example, the input: A[3][4] = [4 53 81 32 12 2 5 8 93 2 1 0]

would be printed as (with decimal points removed):

4  53 81
32 12 2
5  8  93
2  1  0

Equivalent to:

MatrixTranspose(matrix, num_rows, num_cols, MatrixTranspose);
PrintMatrix(MatrixTranspose, num_cols, num_rows)

No inputs may be nullptr.

Parameters:
matrix[num_rows][num_cols]:
 matrix to be printed
num_rows:number of rows
num_cols:number of columns

void PrintDomainBounds(ClosedInterval const *restrict domain_bounds, int dim)

Prints an array of ClosedInterval, formatted as [x_i_min, x_i_max] for i = 0 .. dim-1, one interval per line.

Parameters:
domain[dim]:array of ClosedInterval specifying the boundaries of a dim-dimensional tensor-product domain.
dim:number of spatial dimensions