dimforge / dimforge/nalgebra

Debug output of `SMatrix` is confusing

Open
#898 8 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Consider the following code:

```rust
let matrix = Matrix2::new(1.0, 2.0, 3.0, 4.0);
println!("{:?}", matrix);
```
The output is:
```text
Matrix { data: [[1.0, 3.0], [2.0, 4.0]] }
```
As a casual user, just looking at the `Debug` output I'm likely to think that the matrix stored here is
```
[ 1 3 ]
[ 2 4 ]
```
whereas this is the transposed of the true matrix. The reason here is of course that `nalgebra` stores its matrices in a column-major format. However, perhaps we do not need to expose this fact in the `Debug` implementation. An idea here could be to use the same format as our new `matrix!` macro. In that case, the one-line output of `Debug` for the above matrix would read:
```text
[1.0, 2.0; 3.0, 4.0]
```
whereas with a pretty-print specifier (`"{:#?}"`) we could print it formatted with line breaks:
```text
[1.0, 2.0;
3.0, 4.0]
```

This issue led to some considerable confusion lately in #893 as a user wanted to port some code from `numpy`, and looking at the debug output it appeared that the output matrices were transposed.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.