Skip to content

Commit 16cf1be

Browse files
committed
add file
1 parent d6cfe4f commit 16cf1be

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/common/printers.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
#include <stdio.h>
4+
5+
template< typename T, int N >
6+
void print( T const (&a)[N], char const * name, int const numDigits )
7+
{
8+
char format[8];
9+
snprintf( format, 8, "%%%d.%de", numDigits+7, numDigits );
10+
printf( "%-9s = { ", name );
11+
for( int i=0; i<N; ++i )
12+
{
13+
printf( format, a[i] );
14+
if( i < N-1 )
15+
{
16+
printf( ", " );
17+
}
18+
}
19+
printf( " }\n" );
20+
}
21+
22+
template< typename T, int NROWS, int NCOLS >
23+
void print( CArrayWrapper< T, NROWS, NCOLS > const & matrix, char const * name, int const numDigits )
24+
{
25+
char format[8];
26+
snprintf( format, 8, "%%%d.%de", numDigits+7, numDigits );
27+
28+
printf( "%-9s = { \n", name );
29+
for( int i=0; i<NROWS; ++i )
30+
{
31+
printf( " { " );
32+
for( int j=0; j<NCOLS; ++j )
33+
{
34+
printf( format, matrix( i, j ) );
35+
if( j < NCOLS-1 )
36+
{
37+
printf( ", " );
38+
}
39+
}
40+
printf( "},\n" );
41+
}
42+
printf( " }\n" );
43+
}

0 commit comments

Comments
 (0)