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

STY: xsf: apply clang-format #21640

Closed
wants to merge 3 commits into from

Conversation

lucascolley
Copy link
Member

Reference issue

A more sensible first step towards gh-21024.

What does this implement/fix?

Apply clang-format to scipy/special/xsf, excluding /third_party.

Additional information

It was a bit ambitious to try to start applying clang-format across the repo immediately. As noted in #21024 (comment), we should probably only do this for non-legacy (and non-vendored) code.

There are a few potential complications (#21024 (comment)), so easier to take this slow and steady. Here is a start for just xsf.

Hopefully this PR will be a good point to make sure we are happy with the config before applying it elsewhere.

cc @izaid @steppi

@github-actions github-actions bot added scipy.special C/C++ Items related to the internal C/C++ code base labels Sep 30, 2024
@lucascolley lucascolley changed the title STY: clang-format: preserve include blocks STY: xsf: apply clang-format Sep 30, 2024
@lucascolley lucascolley added the maintenance Items related to regular maintenance tasks label Sep 30, 2024
Copy link
Contributor

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

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

I don't have strong views on it, but it may be worth considering an entry in .git-blame-ignore-revs for a formatting diff this large?

Copy link
Contributor

@fancidev fancidev left a comment

Choose a reason for hiding this comment

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

Looks good to me overall. I just leave a few comments about my personal preference.

Can I ask what is the "screen width" configured for the auto format? It seems to have an impact on the wrappings done. (I'm personally a fan of 80 width, but I understand that many people prefer wider.)

XSF_HOST_DEVICE inline float binom(float n, float k) {
return binom(static_cast<double>(n), static_cast<double>(k));
}
XSF_HOST_DEVICE inline float binom(float n, float k) { return binom(static_cast<double>(n), static_cast<double>(k)); }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to leave single-line function body as is than to merging it in the same line as function signature, so that if we add more lines into the function body later, we don't have to "undo" the merge and cause spurious diff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you know how to change the config file to get what you are looking for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for checking. It seems the new option would convert an existing single-line function body into multiple lines. I feel this is unnecessary if the function body is indeed a simple wrapper.

It would have been best if clang-format provided a "preserve" option that leaves single-line/multi-line function body unchanged, but seems there's no such option. I think I like the previous behavior better (i.e. merging short one-liner into the line of {) as it creates fewer "bad" choices (according to my preference) than the new option.

}
m = 20 + (int)(80.0/x);
m = 20 + (int) (80.0 / x);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer not to insert a blank between (int) and (80.0 / x), because (int) (reinterpret cast) acts like a function, and function names are usually not separated from the opening parenthesis. Similarly e.g. for (std::max)(1.0, 2.0).

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you know how to change the config file to get what you are looking for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this an instance of SpaceAfterCStyleCast: true?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Setting it to false should achieve what I have in mind.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we hold up guys? I'm not keen on this particular change, for instance. More broadly, there is a plan to actually move xsf out of special and I think that is likely to happen soon.

-9.0954017145829042233E-2, 1.0009945751278180853E-1, -1.1133426586956469049E-1, 1.2550966952474304242E-1,
-1.4404989676884611812E-1, 1.6955717699740818995E-1, -2.0738555102867398527E-1, 2.7058080842778454788E-1,
-4.0068563438653142847E-1, 8.2246703342411321824E-1, -5.7721566490153286061E-1};
double coeffs[] = {-4.3478266053040259361E-2, 4.5454556293204669442E-2, -4.7619070330142227991E-2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does clang-format move the first line of numbers into the same line as { here? I noticed that in some places clang-format leaves the numbers in their own line. Do you by chance know what is the rule?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe Cpp11BracedListStyle: true

@lucascolley
Copy link
Member Author

.git-blame-ignore-revs

Yes I was planning to add that at the end.

Can I ask what is the "screen width" configured for the auto format?

I believe @izaid chose ColumnLimit: 120.

@ev-br
Copy link
Member

ev-br commented Oct 1, 2024

There's a format file in xsf folder:

https://github.com/scipy/scipy/blob/main/scipy/special/xsf/.clang-format

@lucascolley
Copy link
Member Author

There's a format file in xsf folder:

Yep, that's what I'm using here.

@lucascolley lucascolley marked this pull request as draft October 1, 2024 10:59
@lucascolley
Copy link
Member Author

Continued at scipy/xsf#5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C/C++ Items related to the internal C/C++ code base maintenance Items related to regular maintenance tasks scipy.special
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants