Skip to content

Unexpected alignment with IOFormat and matPrefix

Summary

Environment

  • Operating System : Linux
  • Architecture : x64
  • Eigen Version : 3.4.0
  • Compiler Version : Gcc12.2.0
  • Compile Flags : -O0 -g
  • Vector Extension :

Minimal Example

Consider the following snippet:

Eigen::Matrix3d m1;
m1 << 1.111111, 2, 3.33333, 4, 5, 6, 7, 8.888888, 9;

Eigen::IOFormat Fmt1(4, 0, ", ", "\n", "[", "]", "A=");
Eigen::IOFormat Fmt2(4, 0, ", ", "\n", "[", "]", "A=", "  ");
std::cout << m1.format(Fmt1) << std::endl;
std::cout << m1.format(Fmt2) << std::endl;

What is the current bug behavior?

The output is

A=[1.111,     2, 3.333]
[    4,     5,     6]
[    7, 8.889,     9]
A=[1.111,     2, 3.333]
  [    4,     5,     6]
  [    7, 8.889,     9]  

In other words, the rows in the first example are not aligned. However, if the correct number of spaces is added at the end of the matrix (i.e. as matSuffix parameter), the size of this suffix seems to be used to compute the indentation of the subsequent rows of the matrix, hence the second example appears correctly indented (but there are now spaces at the end of the output, which may not be intentional).

What is the expected correct behavior?

The rows in the first example should be correctly aligned, i.e., the size of matPrefix should be used not `matSuffix'.