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

Clang compliance #90

Merged
merged 9 commits into from
Oct 16, 2024
Merged

Clang compliance #90

merged 9 commits into from
Oct 16, 2024

Conversation

The9Cat
Copy link
Contributor

@The9Cat The9Cat commented Oct 16, 2024

Summary
This addresses all the warnings generated by clang++ from PR #85 and includes that PR.

There are three types of fixes:

  1. Remove arrays with non-constant dimensions at compile time. These are fixed in one of two ways: either a std::vector<T> or a std::unique_ptr<T[]> to automatically manage memory.
  2. Dereferencing a std::shared_ptr to do a dynamic cast for a type was flagged by the compiler as "expressions with side-effects", even though I think they are probably okay . These were switched to dynamic casts to pointers to types, with no "side effects".
  3. Fixed a bunch of C-code headers without proper signatures.

The compiled code passes ctest -L long tests. Several of these changes are in expui code. While I do not think that the likelihood of breaking code is low (since most of these changes are in memory management for buffers), I might be good to check this code against the pyEXP-examples/Tutorials notebooks for verification.

Copy link
Member

@michael-petersen michael-petersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very explicit definitions now, I like it!

Not sure how this will play with pybind11fix. I'm tempted to try merging this into pybind11fix first?

@@ -188,13 +188,13 @@ public:
virtual double get_dpot2(const double) = 0;
virtual void get_pot_dpot(const double, double&, double&) = 0;

double get_mass(const double x1, const double x2, const double x3)
double get_mass(const double x1, const double x2, const double x3) override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice -- I didn't know about override before. Definitely reduces the warnings!

double a[NUMR], b[NUMR], c[NUMR];
fftw_complex A[NUMR], B[NUMR], C[NUMR];
std::vector<double> a(NUMR), b(NUMR), c(NUMR);
std::vector<fftw_complex> A(NUMR), B(NUMR), C(NUMR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was causing problems for me:

error: object expression of non-scalar type 'double[2]' cannot be used in a pseudo-destructor expression

I think this is because typedef double fftw_complex[2]; is the under-the-hood definition in FFTW, which is causing a problem when passed to std::vector as MacOS handles it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be handled using a std::unique_ptr<fftw_complex> instead. But a bit surprised that Mac and Linux would be different here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From RTFM, fftw knows about C complex, so I think we can get rid of fftw_complex in favor of std::complex which is compatible with C complex. That is, std::vector<std::complex<double>> rather than std::vector<fftw_complex>. I'll try it now...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this passes CI, it seems unlikely it will cause trouble for anyone else. I think it's appropriate to try a merge of this PR after someone else checks that these changes make sense.

@michael-petersen
Copy link
Member

Now also addressing #53.

@michael-petersen michael-petersen mentioned this pull request Oct 16, 2024
@The9Cat
Copy link
Contributor Author

The9Cat commented Oct 16, 2024

This branch has pybind11fix as its parent. So it should contain everything up to that point, unless the branches start to diverge.

@The9Cat
Copy link
Contributor Author

The9Cat commented Oct 16, 2024

Please try the latest refactoring on your Mac, when you have a chance. TL;DR: I agree with the use of reinterpret_cast to to handle the map to fftw_complex, but simplifies a lot to use std::vector<std::complex<double>> in the C++ code.

Copy link
Member

@michael-petersen michael-petersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks out for me, thanks!

@michael-petersen michael-petersen changed the base branch from main to pybind11fix October 16, 2024 15:53
@The9Cat
Copy link
Contributor Author

The9Cat commented Oct 16, 2024

All pyEXP-examples/Tutorials notebooks run as expected. Okay to merge...

@The9Cat The9Cat merged commit 9c6a72d into pybind11fix Oct 16, 2024
4 checks passed
@The9Cat The9Cat deleted the ClangCompliance branch October 16, 2024 16:33
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

Successfully merging this pull request may close these issues.

2 participants