1 #ifndef INCLUDE_AL_SYSTEM_PRINTING_H
2 #define INCLUDE_AL_SYSTEM_PRINTING_H
48 #define AL_PRINTF_LL "I64"
50 #define AL_PRINTF_LL "ll"
68 void print(
const T* arr,
int size,
const char* append =
"");
76 print(arr, size,
"\n");
84 void print(
const T& v,
const char* append =
"") {
101 void print2D(
const T* arr,
int nx,
int ny, FILE* fp = stdout);
109 void printPlot(
float value, uint32_t width = 50,
bool spaces =
true,
110 const char* point =
"o");
113 void err(
const char* msg,
const char* src =
"",
bool exits =
true);
116 #define AL_WARN(fmt, ...) \
117 ::al::_warn(__FILE__, __LINE__, fmt "\n", ##__VA_ARGS__)
120 #define AL_WARN_ONCE(fmt, ...) \
121 ::al::_warnOnce(__FILE__, __LINE__, fmt "\n", ##__VA_ARGS__)
123 void _warn(
const char* fileName,
int lineNumber,
const char* fmt, ...);
124 void _warnOnce(
const char* fileName,
int lineNumber,
const char* fmt, ...);
129 static const char map[] =
130 " .,;-~_+<>i!lI?/|)(1}{][rcvunxzjftLCJUYXZO0Qoahkbdpqwm*WMB8&%$#@";
133 static const int N =
sizeof(map) - 1;
134 v = v < 0 ? 0 : (v > 0.9999999f ? 0.9999999f : v);
135 return map[int(N * v)];
138 #define DEF_PRINT(T, code) \
140 inline void print<T>(const T* arr, int size, const char* append) { \
141 for (int i = 0; i < size; ++i) { \
142 printf(code " ", arr[i]); \
144 if (append[0]) printf("%s", append); \
147 DEF_PRINT(
float,
"%g")
148 DEF_PRINT(
double, "%g")
149 DEF_PRINT(
char, "%d")
150 DEF_PRINT(
unsigned char, "%u")
151 DEF_PRINT(
short, "%d")
152 DEF_PRINT(
unsigned short, "%u")
154 DEF_PRINT(
unsigned int, "%u")
155 DEF_PRINT(
long, "%ld")
156 DEF_PRINT(
unsigned long, "%lu")
157 DEF_PRINT(
long long, "%" AL_PRINTF_LL "d")
158 DEF_PRINT(
unsigned long long, "%" AL_PRINTF_LL "u")
163 void print2D(
const T* pix,
int nx,
int ny, FILE* fp) {
164 for (
int j = 0; j < nx; ++j) {
165 for (
int i = 0; i < ny; ++i) {
166 float v = pix[j * nx + i];
void err(const char *msg, const char *src="", bool exits=true)
Prints error message to stderr and optionally calls exit()
void println(const T *arr, int size)
Print an array of numbers with new line.
void print2D(const T *arr, int nx, int ny, FILE *fp=stdout)
Prints 2D array of intensity values.
void printPlot(float value, uint32_t width=50, bool spaces=true, const char *point="o")
Print signed unit value on a horizontal plot.
char intensityToASCII(float v)
void print(const T *arr, int size, const char *append="")
Print an array of numbers.