-
Notifications
You must be signed in to change notification settings - Fork 125
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
Fix: apply clang-tidy fixes #4015
Conversation
According to Commit message guidelines, I think using keyword |
This PR makes actual changes to the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked through dozens of files, most of them look good to me. Howver, I don't understand some modifications, as can be seen with my comments.
@@ -117,7 +117,7 @@ void scaled_sum(std::complex <double> c1, const ComplexArray &cd1, | |||
ComplexArray &cd3); | |||
|
|||
/// out[i] = a1[i] * in2[i] | |||
void point_mult(ComplexArray &a1, ComplexArray &in2, ComplexArray &out); | |||
void point_mult(ComplexArray &in1, ComplexArray &in2, ComplexArray &out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel the meaning has been changed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is changed in consistent with that in complexarray.cpp
.
double *e{}; | ||
int lwork{}; | ||
std::complex<double> *work2{}; | ||
double* rwork{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use nullptr here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using {}
is identical, as it initializes the pointer to nullptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not looking identical ways of writing C++ codes, I just consider this new way of initializing variables make reading more difficult for some people, we should have a unified way. For example, double *rwork = nullptr;
namespace ModuleBase { | ||
|
||
template <typename FPTYPE> | ||
__inline__ | ||
FPTYPE __fact(const int n) { | ||
FPTYPE _fact(const int n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any special reason to change the function name from __ to _
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The C++ standard reserves names starting with __.
@@ -187,7 +187,7 @@ class Chebyshev | |||
|
|||
public: | |||
//Members: | |||
int norder; // order of Chebyshev expansion | |||
int norder{}; // order of Chebyshev expansion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not initialize it will 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will, please see https://en.cppreference.com/w/cpp/language/zero_initialization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, why not write the code "int norder = 0" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, why not write the code "int norder = 0" ?
Using bracelet is the only supported grammar for this fix initializing members in declaration. There is another fix available in your expected grammar, but the modifications will be much more.
bool&, | ||
double&, | ||
double&); | ||
extern /* Subroutine */ void dcstep(double& /*stx*/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks strange here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add variable names according to declaration to improve code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't recommend writing "/* */"
I went through the files in module_base, module_basis and module_cell. Apart from the mistaken removal of some gpu code in pw_basis_sup.cpp (which has been fixed in a commit), clang-tidy indeed tidies up a lot of code. Here's a brief list of what I record:
which can be simply
with
I think this is another matter of style which I have no particular preference. However, if both branches return something, I personally prefer the ternary operator:
For the three modules I was assigned, I think the changes made by this PR looks good (with some style issue that may or may not need discussion). The only real issue is that this PR messes up quite a few indentation, which might be fixed by another PR of clang-format, I guess? |
Running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed files in module_hamilt_pw, module_io, module_psi.
There are mainly several kinds of code polishment I have observed:
- change "pass by value" to "pass by ref" or "pass by value then swap".
- add
static
keyword ahead of function that does not rely on member variables. - delete useless
return
in void function. - change some
0
and1
tofalse
ortrue
, correspondingly, avoid implicit type conversion - use list initialization on PART of member variables.
- remove the use of operator
?:
in some boolean assignment cases. - add annotation behind namespace.
- make nomenclature of varialbles consistent.
- delete redundant
if not nullptr
sentence before deallocating one pointer - change the default initialization value
NULL
for pointer tonullptr
However,
- it (clang-tidy) indeed removed some annotation by mistake especially at the end of functions.
- the indent seems to be not well-treated, but I guess it is because the mixed use of Tab and whitespaces
- not fully change the if-else logic, like in psi_initializer_atomic.cpp:
std::complex<double> phase_factor(double arg, int mode)
{
if(mode == 1) return std::complex<double>(cos(arg),0);
if (mode == -1) return std::complex<double>(0, sin(arg));
else if (mode == 0) return std::complex<double>(cos(arg), sin(arg));
// can also be `if` instead of `else if`
else return std::complex<double>(1,0);
// can directly `return`
}
@@ -26,7 +26,7 @@ class Meta<OperatorPW<T, Device>> : public OperatorPW<T, Device> | |||
private: | |||
using Real = typename GetTypeReal<T>::type; | |||
public: | |||
Meta(Real tpiba2_in, | |||
Meta(Real tpiba_in, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure but it seems tpiba
is not equivalent with tpiba2
, the latter seems to be square of the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
@@ -35,8 +35,8 @@ class Velocity | |||
*/ | |||
void act(const psi::Psi<std::complex<double>>* psi_in, | |||
const int n_npwx, | |||
const std::complex<double>* tmpsi_in, | |||
std::complex<double>* tmhpsi, | |||
const std::complex<double>* psi0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems not a good idea...
Hi @mohanchen @kirk0830 , |
Hi Cun, though most of the updates look good to me. However, I am deeply concerned about some modifications that change the parameter names, and the amount of modifications of codes is huge (522 files!). In addition, although I ask some questions, I don't get the answers I want (not the explanations for C++ grammar). |
Hi @mohanchen , |
Thanks, I understand your thoughts better now. How about we close this PR but we label it as 'Useful Information', then we can use this as a reference for further discussion of how to make changes as we expect. @caic99 |
Hi all,
I've removed this rule removing else after a return statement. This is indeed optional, and will making incomplete changes.
This is the job of clang-format, and we may discuss it with another issue. However, I still insist that some fixes are necessary, which we've also discussed above (and I kept them unresolved to show more details):
By consolidating a rule and applying them on each PR, the code quality is able to be assured and improved during refactor. |
* CI: add pre-commit.ci to apply clang-format and clang-tidy fixes * do pre-commit fixes first * install clang utils * apply fixes only on changed files * fetch historical commits to get the changed files * test if pre-commit could fix sabotaged format * update pre-commit config * apply fixes * commit changes after apply them * commit changes using pre-commit.ci lite * try to fix SSL error using pre-commit.ci lite * [pre-commit.ci lite] apply automatic fixes * format arguments * add docs on pre-commit hook * Update clang-format config. ABACUS uses some functions with a long function name and a long parameter list. Current setup will generates ugly parameter list with each parameters indented by many spaces. Plus, it is unable to use a customized layout for e.g. putting x, y, and z value in the same line. After discussion, we agree to disable those settings, leaving developers free to chose their own flavor. * Update clang-tidy config. #4015 * [pre-commit.ci lite] apply automatic fixes * Update .pre-commit-config.yaml * Update .clang-tidy according to the meeting --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Mohan Chen <mohan.chen.chen.mohan@gmail.com> Co-authored-by: Haozhi Han <haozhi.han@outlook.com>
Reminder
Linked Issue
Fix #3915
Unit Tests and/or Case Tests for my changes
What's changed?
This PR applies clang-tidy rules on existing codes to improve code quality. I've carefully reviewed the modifications.