Print

Prints matrix contents to the Experts log.

void matrix::Print(
   ulong    flags=0,         // flags
   string   format_string="" // format string for outputting numbers
   );

Parameters

flags

[in] Flags for controlling matrix output to the log.

format_string

[in] String for formatting numbers if the MATRIX_PRINT_USE_FORMATSTRING flag is set.

Return Value

The method returns no value. In case of failure (uninitialized matrix, empty format string, invalid format string), an error is raised. The error code can be obtained using GetLastError().

Flags can be combinations of the following values:

Flag

Value

Description

MATRIX_PRINT_USE_FORMATSTRING

0x0001

Use a format string when outputting a matrix element

MATRIX_PRINT_INFO

0x0002

Print matrix information in the first line: class, type and dimensions

MATRIX_PRINT_INDEXES

0x0004

Print row and column indexes

MATRIX_PRINT_FULL

0x0008

Print the entire matrix to the log without any truncation

MATRIX_PRINT_PARTIAL_LEFT

0x0010

Print the left part of the matrix to the log

MATRIX_PRINT_PARTIAL_RIGHT

0x0020

Print the right part of the matrix to the log

MATRIX_PRINT_PARTIAL_TOP

0x0040

Print the upper part of the matrix to the log

MATRIX_PRINT_PARTIAL_BOTTOM

0x0080

Print the lower part of the matrix to the log

MATRIX_PRINT_PARTIAL

(MATRIX_PRINT_PARTIAL_LEFT | MATRIX_PRINT_PARTIAL_RIGHT | MATRIX_PRINT_PARTIAL_TOP | MATRIX_PRINT_PARTIAL_BOTTOM)

Print the specified parts of the matrix to the log

Note

Matrices with no more than 50 rows and with columns that fit into a buffer shorter than 512 characters are printed to the log completely, without truncation. For example, a 50 x 21 matrix will be printed without truncation when no formatting is used. A 50 x 56 matrix with elements in the range from 0 to 1 and the "%.5f" format string will also be printed without truncation. To guarantee that the matrix is printed to the log without truncation, use the MATRIX_PRINT_FULL flag.

Examples:

An ill-conditioned matrix with a value range spanning more than 50 orders of magnitude:

 matrix matrix_a(5,10);
 vector vector_a=vector::Random(10,-1.0,1.0);
 matrix_a.Row(vector_a,0);
 vector_a=vector::Random(10,0.0,1000.0);
 matrix_a.Row(vector_a,1);
 vector_a=vector::Random(10,-1000.0,0.0);
 matrix_a.Row(vector_a,2);
 vector_a=vector::Random(10,0.0,1e-30);
 matrix_a.Row(vector_a,3);
 vector_a=vector::Random(10,0.0,1e+30);
 matrix_a.Row(vector_a,4);
 
 matrix_a.Print();
 matrix_a.Print(MATRIX_PRINT_USE_FORMATSTRING|MATRIX_PRINT_INDEXES,"%.6e");

The first Print call with default parameters:

[[    0.5590638740824219,   -0.18868502909054163,     0.5922359152678949,     0.8639735974986045,    -0.7719553713155807,     -0.815408580893513,     0.7818219973197724,     -0.728249088332115,    -0.7753896945564518,     0.5773408984712654]
 [     479.4379201436969,     109.58748033959127,      880.3346755170112,      310.0090663204922,      845.9597960687148,     109.99259075848212,     425.02365364344405,     17.072204970073003,     434.37093622851444,       269.887945910424]
 [   -52.388742112645104,    -314.95409116962793,     -731.5748640642443,     -803.5949582242395,     -784.1211617421641,     -70.02209012164317,      -87.8936923313638,     -541.1503663149547,     -777.3225125338237,     -370.1343455748014]
 [ 9.237566829947188e-31, 3.4064281856190485e-31,  4.382033279254575e-31,  3.616966596715378e-31,   1.77732296329395e-32,  7.385673899526167e-31, 7.5279191177170545e-31,  8.270328803516536e-31,  2.755479159009522e-31, 2.3663216229449778e-31]
 [ 6.281136557525289e+29,  9.867243799350049e+29,  3.082299079532339e+29, 1.1587504765854102e+29,  7.053530157323351e+29,  5.529440961668604e+29,  9.474819742486538e+29, 1.0086873688289634e+29, 1.7539649577238513e+29,  3.694467191513271e+29]

The second Print call with indexes and formatting:

                 0              1              2              3              4              5              6              7              8              9
0  [[ 5.590639e-01, -1.886850e-01,  5.922359e-01,  8.639736e-01, -7.719554e-01, -8.154086e-01,  7.818220e-01, -7.282491e-01, -7.753897e-01,  5.773409e-01]
1   [ 4.794379e+02,  1.095875e+02,  8.803347e+02,  3.100091e+02,  8.459598e+02,  1.099926e+02,  4.250237e+02,  1.707220e+01,  4.343709e+02,  2.698879e+02]
2   [-5.238874e+01, -3.149541e+02, -7.315749e+02, -8.035950e+02, -7.841212e+02, -7.002209e+01, -8.789369e+01, -5.411504e+02, -7.773225e+02, -3.701343e+02]
3   [ 9.237567e-31,  3.406428e-31,  4.382033e-31,  3.616967e-31,  1.777323e-32,  7.385674e-31,  7.527919e-31,  8.270329e-31,  2.755479e-31,  2.366322e-31]
4   [ 6.281137e+29,  9.867244e+29,  3.082299e+29,  1.158750e+29,  7.053530e+29,  5.529441e+29,  9.474820e+29,  1.008687e+29,  1.753965e+29,  3.694467e+29]]

Example with matrix information output:

 matrix matrix_t=(matrix::Random(5,5)).TriL();
 matrix_t.Print(MATRIX_PRINT_INFO);

Printing a lower triangular matrix:

lower triangular matrix TYPE_MATRIXD rows=5 cols=5
[[ 0.2591851722121204,                 0.0,                 0.0,                 0.0,                 0.0]
 [ 0.8555854032411206,  0.8123811429395297,                 0.0,                 0.0,                 0.0]
 [ 0.6299442031024826,  0.8465243775505862,  0.7297496911440393,                 0.0,                 0.0]
 [0.34490645684881754,  0.1824836356524573,  0.9628033656540335, 0.44543146561957697,                 0.0]
 [0.15595249206664796,   0.994806045432297,  0.9356895773521833,  0.3660733379344627, 0.38713852278588773]]

Examples with partial output:

 matrix matrix_c=matrix::Random(100,56);
 matrix_c.Print(MATRIX_PRINT_USE_FORMATSTRING|MATRIX_PRINT_INFO|MATRIX_PRINT_INDEXES|MATRIX_PRINT_PARTIAL_LEFT,"%.5f");

The upper-left part of the matrix is printed to the log:

general matrix TYPE_MATRIXD rows=100 cols=56
            0        1        2        3        4   ...  
 0  [[0.02695, 0.80907, 0.55499, 0.49136, 0.64393,  ...  
 1   [0.86880, 0.74037, 0.42364, 0.46662, 0.36582,  ...  
 2   [0.90027, 0.69670, 0.17349, 0.34099, 0.36550,  ...  
 3   [0.49019, 0.69500, 0.08940, 0.93820, 0.34878,  ...  
 4   [0.09602, 0.21479, 0.15040, 0.46355, 0.64508,  ...  
 5   [0.22736, 0.32438, 0.66466, 0.47897, 0.26145,  ...  
 6   [0.60876, 0.32834, 0.66710, 0.10431, 0.08120,  ...  
 7   [0.21453, 0.56489, 0.79544, 0.08643, 0.27602,  ...  
 8   [0.18163, 0.48241, 0.23162, 0.40599, 0.62502,  ...  
 9   [0.60875, 0.15773, 0.20555, 0.51265, 0.32782,  ...  
...

Another example:

 matrix matrix_c=matrix::Random(100,56);
 matrix_c.Print(MATRIX_PRINT_USE_FORMATSTRING|MATRIX_PRINT_INFO|MATRIX_PRINT_INDEXES|MATRIX_PRINT_PARTIAL_LEFT|MATRIX_PRINT_PARTIAL_TOP|MATRIX_PRINT_PARTIAL_BOTTOM,"%.5f");

Partial output of the left part of the matrix:

general matrix TYPE_MATRIXD rows=100 cols=56
            0        1        2        3        4   ...  
 0  [[0.02695, 0.80907, 0.55499, 0.49136, 0.64393,  ...  
 1   [0.86880, 0.74037, 0.42364, 0.46662, 0.36582,  ...  
 2   [0.90027, 0.69670, 0.17349, 0.34099, 0.36550,  ...  
 3   [0.49019, 0.69500, 0.08940, 0.93820, 0.34878,  ...  
 4   [0.09602, 0.21479, 0.15040, 0.46355, 0.64508,  ...  
...
95   [0.15883, 0.52814, 0.87470, 0.05490, 0.10853,  ...  
96   [0.42209, 0.69922, 0.21160, 0.66176, 0.94695,  ...  
97   [0.71632, 0.90784, 0.66557, 0.18421, 0.02700,  ...  
98   [0.10539, 0.54643, 0.52259, 0.10098, 0.46184,  ...  
99   [0.71227, 0.49993, 0.86942, 0.46830, 0.60911,  ...  

Another example:

 matrix matrix_c=matrix::Random(100,56);
 matrix_c.Print(MATRIX_PRINT_USE_FORMATSTRING|MATRIX_PRINT_INFO|MATRIX_PRINT_INDEXES|MATRIX_PRINT_PARTIAL_LEFT|MATRIX_PRINT_PARTIAL_RIGHT|MATRIX_PRINT_PARTIAL_BOTTOM,"%.5f");

Partial output of the lower part of the matrix:

general matrix TYPE_MATRIXD rows=100 cols=56
            0        1        2        3        4   ...       51       52       53       54       55
...
95   [0.158830.528140.874700.054900.10853,  ...  0.498370.815210.551080.963320.48618]
96   [0.422090.699220.211600.661760.94695,  ...  0.817050.151070.635380.516480.92651]
97   [0.716320.907840.665570.184210.02700,  ...  0.891340.172740.297320.491900.05529]
98   [0.105390.546430.522590.100980.46184,  ...  0.168260.549890.158510.485860.16551]
99   [0.712270.499930.869420.468300.60911,  ...  0.820810.774870.578680.155840.31860]]

The partial output size is 5 rows and 5 columns. This is the default value.

The number of output rows and columns can be controlled using flags. The flags parameter is of the ulong. type. The lower half is reserved for the flags themselves. The upper half (two 16-bit words) can store the number of rows and columns.

 matrix matrix_c=matrix::Random(100,56);
 ulong flags=(7ull<<48)+(4ull<<32);
 matrix_c.Print(flags|MATRIX_PRINT_USE_FORMATSTRING|MATRIX_PRINT_INFO|MATRIX_PRINT_INDEXES|MATRIX_PRINT_PARTIAL,"%.5f");

Partial output of 4 matrix parts with 7 rows and 4 columns:

general matrix TYPE_MATRIXD rows=100 cols=56
            0        1        2        3   ...       52       53       54       55
 0  [[0.02695, 0.80907, 0.55499, 0.49136,  ...  0.80789, 0.46080, 0.54249, 0.91261]
 1   [0.86880, 0.74037, 0.42364, 0.46662,  ...  0.06764, 0.63572, 0.04515, 0.04779]
 2   [0.90027, 0.69670, 0.17349, 0.34099,  ...  0.76012, 0.37694, 0.17990, 0.42098]
 3   [0.49019, 0.69500, 0.08940, 0.93820,  ...  0.74310, 0.53014, 0.66096, 0.37256]
 4   [0.09602, 0.21479, 0.15040, 0.46355,  ...  0.37758, 0.18302, 0.47886, 0.12550]
 5   [0.22736, 0.32438, 0.66466, 0.47897,  ...  0.30290, 0.63452, 0.34728, 0.28565]
 6   [0.60876, 0.32834, 0.66710, 0.10431,  ...  0.99954, 0.41966, 0.57928, 0.43339]
...
93   [0.40377, 0.31646, 0.13730, 0.33577,  ...  0.14799, 0.58725, 0.66397, 0.13798]
94   [0.24014, 0.56178, 0.01189, 0.72526,  ...  0.98071, 0.56474, 0.38492, 0.17089]
95   [0.15883, 0.52814, 0.87470, 0.05490,  ...  0.81521, 0.55108, 0.96332, 0.48618]
96   [0.42209, 0.69922, 0.21160, 0.66176,  ...  0.15107, 0.63538, 0.51648, 0.92651]
97   [0.71632, 0.90784, 0.66557, 0.18421,  ...  0.17274, 0.29732, 0.49190, 0.05529]
98   [0.10539, 0.54643, 0.52259, 0.10098,  ...  0.54989, 0.15851, 0.48586, 0.16551]
99   [0.71227, 0.49993, 0.86942, 0.46830,  ...  0.77487, 0.57868, 0.15584, 0.31860]]