Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning: advanced initialization in Eigen might confuse #429

Closed
uukhas opened this issue Apr 25, 2022 · 7 comments
Closed

warning: advanced initialization in Eigen might confuse #429

uukhas opened this issue Apr 25, 2022 · 7 comments

Comments

@uukhas
Copy link
Member

uukhas commented Apr 25, 2022

There is the following way to initialize an array:

Eigen::Array<double,2,1> a;
a << 1, 2;
std::cout << a << "\n";

And the output is as one would assume:

1
2

So, I have immediately concluded that << acts as =, i.e. the right side is calculated at the same time and only then the substitution is done. This is WRONG:

Eigen::Array<double,2,1> a;
a << 1, 2;
a << a[0] + a[1], a[0];
std::cout << a << "\n";

returns

3
3

and not 3 1. So that every comma-separated element is calculated right after the update in corresponding a element.

@Expander
Copy link
Member

You are right, this is a potential pitfall. Did this cause problems in some parts of the code?

@uukhas
Copy link
Member Author

uukhas commented Apr 25, 2022

@Expander, this caused a problem for l_i->3l_j decays in the code which is not fully merged in FlexibleSUSY.
About other places I do not know yet.

@pathron
Copy link
Member

pathron commented Apr 25, 2022

This is just eigen though, not sure what we can do other than not use the << incorrectly . Is it documented somewhere in eigen that it works this way?

@uukhas
Copy link
Member Author

uukhas commented Apr 25, 2022

Dear @pathron, here they do not use things similar to a << a[0] + a[1], a[0];.

What we can do is to make sure that we know about this "tricky" behavior (maybe contact eigen developers as well and ask them to add this case in the linked page).

We can add this warning to our developer wiki.

@Expander
Copy link
Member

@uukhas I like your idea to tell the Eigen developers to put a brief note into their documentation to make the users aware of this issue. Formally, however, this is not a FS bug or similar. It's just something we need to be aware of.

@pathron
Copy link
Member

pathron commented Apr 27, 2022

Yes I also agree with that. I also agree with @uukhas that putting a note in our wiki here to warn other FS people about it is also helpful.

@Expander
Copy link
Member

Expander commented Jan 3, 2023

I have created the wiki page https://github.com/FlexibleSUSY/FlexibleSUSY/wiki/Eigen-library to warn us about this issue.

@Expander Expander closed this as completed Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants