sharkdp / dbg-macro

A dbg(…) macro for C++
MIT License
3k stars 258 forks source link

Fails with Eigen matrices #131

Open roger- opened 1 year ago

roger- commented 1 year ago

When trying to print Eigen::MatrixXd objects I get an assertion. Eigen::VectorXd objects work though.

Any ideas?

winwinashwin commented 1 year ago

@roger- Could you please share a minimal example to reproduce the issue?

roger- commented 1 year ago

Sure:

Eigen::MatrixXd X(2, 2);
X.setIdentity();

dbg(X);
winwinashwin commented 1 year ago

@roger- I am unable to reproduce the issue. It might be specific to your arch/compiler/c++ std/eigen version. Here is my attempt - https://godbolt.org/z/Gc8Y1WhMr Could you try reproducing your issue in godbolt and share it here?

roger- commented 12 months ago

Looks like it fails with Eigen 3.4: https://godbolt.org/z/o8vYzGnWo

sharkdp commented 10 months ago

Thank you for reporting this. The problem seems to be that we treat the Eigen matrix as a container via this piece of code:

https://github.com/sharkdp/dbg-macro/blob/1aaa8805ca0a4852c009805e49074cc3dedf058e/dbg.h#L382-L389

I guess that would need to be adapted in order to fix the Eigen matrix case.

winwinashwin commented 10 months ago

@sharkdp What should be the approach here? From what I understand we have two options,

  1. Eigen is not part of the std library. We should fail when trying to dbg(...) Eigen objects and expect the user to add overloads in such scenarios
  2. Add support for Eigen

I would go with (1) if given the option

sharkdp commented 9 months ago

It's kind of Eigen's fault, in my opinion. They provide .begin() and .end() for Eigen::MatrixXd, but you're not allowed to use them (will result in a static assertion failing). This makes it hard to detect with meta programming. We could maybe forward-declare and special-case it somehow, but I'm not sure if that's a scalable approach.