Print diagonal matrix
Reference issue
Allows users to print diagonal matrix expressions without assigning them to a dense object. Cute utility that may be useful for debugging. Surprisingly, it is remarkably flexible and incurs no allocations (provided the expression itself does not).
Example input:
int main()
{
VectorXf a(10);
internal::set_is_malloc_allowed(false);
a.setRandom();
// plain vectors
std::cout << a.asDiagonal() << "\n\n";
// simple expressions
std::cout << VectorXf::EqualSpaced(10, -2.0f, 1.5f).asDiagonal() << "\n\n";
// slightly more complicated expressions
std::cout << MatrixXf::Random(10, 10).diagonal(-1).asDiagonal() << "\n\n";
}
Example output:
-0.997497 0 0 0 0 0 0 0 0 0
0 0.127171 0 0 0 0 0 0 0 0
0 0 -0.613392 0 0 0 0 0 0 0
0 0 0 0.617481 0 0 0 0 0 0
0 0 0 0 0.170019 0 0 0 0 0
0 0 0 0 0 -0.0402539 0 0 0 0
0 0 0 0 0 0 -0.299417 0 0 0
0 0 0 0 0 0 0 0.791925 0 0
0 0 0 0 0 0 0 0 0.64568 0
0 0 0 0 0 0 0 0 0 0.49321
-2 0 0 0 0 0 0 0 0 0
0 -0.5 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 2.5 0 0 0 0 0 0
0 0 0 0 4 0 0 0 0 0
0 0 0 0 0 5.5 0 0 0 0
0 0 0 0 0 0 7 0 0 0
0 0 0 0 0 0 0 8.5 0 0
0 0 0 0 0 0 0 0 10 0
0 0 0 0 0 0 0 0 0 11.5
-0.668203 0 0 0 0 0 0 0 0
0 0.97705 0 0 0 0 0 0 0
0 0 -0.108615 0 0 0 0 0 0
0 0 0 -0.761834 0 0 0 0 0
0 0 0 0 -0.990661 0 0 0 0
0 0 0 0 0 -0.982177 0 0 0
0 0 0 0 0 0 -0.24424 0 0
0 0 0 0 0 0 0 0.0633259 0
0 0 0 0 0 0 0 0 0.142369
What does this implement/fix?
Additional information
Edited by Charles Schlosser