From 7b88a6f7692a929af3149fd3c5069ca8c8e8b465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Fri, 27 Dec 2024 15:31:02 +0100 Subject: [PATCH] clang-format: reindent using the RemoveParentheses option However do not set that option permanently (and also disable RemoveSemicolon by default), since the clang-format manual states that these options can lead to incorrect formatting and thus their result should be carefully reviewed. --- .clang-format | 9 ++++++- mex/sources/bytecode/Interpreter.cc | 2 +- mex/sources/libkorder/kord/first_order.cc | 4 ++-- mex/sources/libkorder/sylv/QuasiTriangular.cc | 2 +- mex/sources/libkorder/sylv/SylvesterSolver.hh | 2 +- mex/sources/libkorder/sylv/tests/tests.cc | 24 +++++++++---------- mex/sources/libkorder/tl/equivalence.cc | 2 +- mex/sources/libkorder/tl/int_sequence.cc | 4 ++-- mex/sources/libkorder/tl/stack_container.hh | 3 +-- mex/sources/libkorder/tl/tests/tests.cc | 6 ++--- 10 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.clang-format b/.clang-format index d617cd54e..d0165aef3 100644 --- a/.clang-format +++ b/.clang-format @@ -8,6 +8,12 @@ # https://clang.llvm.org/docs/ClangFormatStyleOptions.html # Effective configuration can be obtained with: # clang-format --dump-config + +# The RemoveParentheses and RemoveSemicolon option are not permanently set, +# because the clang-format manual (as of version 19) states that these +# options can lead to incorrect formatting and thus their result should be +# carefully reviewed. + Language: Cpp Standard: c++20 ColumnLimit: 100 @@ -23,7 +29,8 @@ InsertNewlineAtEOF: true PackConstructorInitializers: NextLine PPIndentWidth: 1 PointerAlignment: Left -RemoveSemicolon: true +# RemoveParentheses: ReturnStatement +# RemoveSemicolon: true SpaceAfterTemplateKeyword: false SpaceBeforeParens: ControlStatements SpaceBeforeCpp11BracedList: true diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc index 124955585..a8717615c 100644 --- a/mex/sources/bytecode/Interpreter.cc +++ b/mex/sources/bytecode/Interpreter.cc @@ -2198,7 +2198,7 @@ Interpreter::complete(int beg_t) } mxFree(save_code); mxFree(diff); - return (beg_t); + return beg_t; } void diff --git a/mex/sources/libkorder/kord/first_order.cc b/mex/sources/libkorder/kord/first_order.cc index 9bb49ecb8..23490c115 100644 --- a/mex/sources/libkorder/kord/first_order.cc +++ b/mex/sources/libkorder/kord/first_order.cc @@ -35,8 +35,8 @@ std::mutex FirstOrder::mut; lapack_int FirstOrder::order_eigs(const double* alphar, const double* alphai, const double* beta) { - return (*alphar * *alphar + *alphai * *alphai - < *beta * *beta * qz_criterium_global * qz_criterium_global); + return *alphar * *alphar + *alphai * *alphai + < *beta * *beta * qz_criterium_global * qz_criterium_global; } /* Here we solve the linear approximation. The result are the matrices diff --git a/mex/sources/libkorder/sylv/QuasiTriangular.cc b/mex/sources/libkorder/sylv/QuasiTriangular.cc index 12d4f151f..1e116c451 100644 --- a/mex/sources/libkorder/sylv/QuasiTriangular.cc +++ b/mex/sources/libkorder/sylv/QuasiTriangular.cc @@ -306,7 +306,7 @@ Diagonal::print() const bool Diagonal::isZero(double p) { - return (std::abs(p) < EPS); + return std::abs(p) < EPS; } QuasiTriangular::const_col_iter diff --git a/mex/sources/libkorder/sylv/SylvesterSolver.hh b/mex/sources/libkorder/sylv/SylvesterSolver.hh index d5de5cb23..cc7700091 100644 --- a/mex/sources/libkorder/sylv/SylvesterSolver.hh +++ b/mex/sources/libkorder/sylv/SylvesterSolver.hh @@ -42,7 +42,7 @@ private: static bool zeroPad(const SchurDecompZero& kdecomp) { - return ((kdecomp.getZeroCols() * 3 < kdecomp.getDim() * 2) || (kdecomp.getZeroCols() < 10)); + return (kdecomp.getZeroCols() * 3 < kdecomp.getDim() * 2) || (kdecomp.getZeroCols() < 10); } public: diff --git a/mex/sources/libkorder/sylv/tests/tests.cc b/mex/sources/libkorder/sylv/tests/tests.cc index 4235c0e37..20fc267b6 100644 --- a/mex/sources/libkorder/sylv/tests/tests.cc +++ b/mex/sources/libkorder/sylv/tests/tests.cc @@ -142,7 +142,7 @@ TestRunnable::quasi_solve(bool trans, const std::string& mname, const std::strin xx.add(1.0, x); double norm = xx.getNorm(); std::cout << "\terror norm = " << norm << std::endl; - return (norm < eps_norm); + return norm < eps_norm; } bool @@ -174,7 +174,7 @@ TestRunnable::mult_kron(bool trans, const std::string& mname, const std::string& c.add(-1.0, v); double norm = c.getNorm(); std::cout << "\terror norm = " << norm << std::endl; - return (norm < eps_norm); + return norm < eps_norm; } bool @@ -208,7 +208,7 @@ TestRunnable::level_kron(bool trans, const std::string& mname, const std::string x.add(-1, c); double norm = x.getNorm(); std::cout << "\terror norm = " << norm << std::endl; - return (norm < eps_norm); + return norm < eps_norm; } bool @@ -241,7 +241,7 @@ TestRunnable::kron_power(const std::string& m1name, const std::string& m2name, x.add(-1, c); double norm = x.getNorm(); std::cout << "\terror norm = " << norm << std::endl; - return (norm < eps_norm); + return norm < eps_norm; } bool @@ -282,7 +282,7 @@ TestRunnable::lin_eval(const std::string& m1name, const std::string& m2name, double norm1 = x1.getNorm(); double norm2 = x2.getNorm(); std::cout << "\terror norm1 = " << norm1 << "\n\terror norm2 = " << norm2 << '\n'; - return (norm1 * norm1 + norm2 * norm2 < eps_norm * eps_norm); + return norm1 * norm1 + norm2 * norm2 < eps_norm * eps_norm; } bool @@ -323,7 +323,7 @@ TestRunnable::qua_eval(const std::string& m1name, const std::string& m2name, double norm1 = x1.getNorm(); double norm2 = x2.getNorm(); std::cout << "\terror norm1 = " << norm1 << "\n\terror norm2 = " << norm2 << std::endl; - return (norm1 * norm1 + norm2 * norm2 < 100 * eps_norm * eps_norm); // relax norm + return norm1 * norm1 + norm2 * norm2 < 100 * eps_norm * eps_norm; // relax norm } bool @@ -362,7 +362,7 @@ TestRunnable::tri_sylv(const std::string& m1name, const std::string& m2name, double max = dcheck.getMax(); double xmax = v.getMax(); std::cout << "\trel. error max = " << max / xmax << std::endl; - return (norm < xnorm * eps_norm); + return norm < xnorm * eps_norm; } bool @@ -388,8 +388,8 @@ TestRunnable::gen_sylv(const std::string& aname, const std::string& bname, const gs.check(mmd.getData()); const SylvParams& pars = gs.getParams(); pars.print("\t"); - return (*(pars.mat_err1) < eps_norm && *(pars.mat_errI) < eps_norm && *(pars.mat_errF) < eps_norm - && *(pars.vec_err1) < eps_norm && *(pars.vec_errI) < eps_norm); + return *(pars.mat_err1) < eps_norm && *(pars.mat_errI) < eps_norm && *(pars.mat_errF) < eps_norm + && *(pars.vec_err1) < eps_norm && *(pars.vec_errI) < eps_norm; } bool @@ -424,7 +424,7 @@ TestRunnable::eig_bubble(const std::string& aname, int from, int to) << "\tabs. error∞ = " << normInf << std::endl << "\trel. error1 = " << norm1 / onorm1 << std::endl << "\trel. error∞ = " << normInf / onormInf << std::endl; - return (norm1 < eps_norm * onorm1 && normInf < eps_norm * onormInf); + return norm1 < eps_norm * onorm1 && normInf < eps_norm * onormInf; } bool @@ -463,7 +463,7 @@ TestRunnable::block_diag(const std::string& aname, double log10norm) std::cout << "\terror Q·Q⁻¹:" << std::endl << "\tabs. error1 = " << nor1 << std::endl << "\tabs. error∞ = " << norInf << std::endl; - return (norm1 < eps_norm * pow(10, log10norm) * onorm1); + return norm1 < eps_norm * pow(10, log10norm) * onorm1; } bool @@ -503,7 +503,7 @@ TestRunnable::iter_sylv(const std::string& m1name, const std::string& m2name, double max = dcheck.getMax(); double xmax = v.getMax(); std::cout << "\trel. error max = " << max / xmax << std::endl; - return (cnorm < xnorm * eps_norm); + return cnorm < xnorm * eps_norm; } /**********************************************************/ diff --git a/mex/sources/libkorder/tl/equivalence.cc b/mex/sources/libkorder/tl/equivalence.cc index 3b560bfd3..bc7f4a325 100644 --- a/mex/sources/libkorder/tl/equivalence.cc +++ b/mex/sources/libkorder/tl/equivalence.cc @@ -57,7 +57,7 @@ OrdSequence::operator==(const OrdSequence& s) const while (i < length() && operator[](i) == s[i]) i++; - return (i == length()); + return i == length(); } /* The first add() adds a given integer to the class, the second diff --git a/mex/sources/libkorder/tl/int_sequence.cc b/mex/sources/libkorder/tl/int_sequence.cc index 6d2ffc0f1..f08e40cae 100644 --- a/mex/sources/libkorder/tl/int_sequence.cc +++ b/mex/sources/libkorder/tl/int_sequence.cc @@ -117,7 +117,7 @@ IntSequence::lessEq(const IntSequence& s) const int i = 0; while (i < size() && operator[](i) <= s[i]) i++; - return (i == size()); + return i == size(); } bool @@ -128,7 +128,7 @@ IntSequence::less(const IntSequence& s) const int i = 0; while (i < size() && operator[](i) < s[i]) i++; - return (i == size()); + return i == size(); } void diff --git a/mex/sources/libkorder/tl/stack_container.hh b/mex/sources/libkorder/tl/stack_container.hh index 30a2e9806..e15cef729 100644 --- a/mex/sources/libkorder/tl/stack_container.hh +++ b/mex/sources/libkorder/tl/stack_container.hh @@ -208,8 +208,7 @@ public: isZero(int i, const Symmetry& s) const override { TL_RAISE_IF(i < 0 || i >= numStacks(), "Wrong index to stack in StackContainer::isZero."); - return (getType(i, s) == itype::zero - || (getType(i, s) == itype::matrix && !conts[i]->check(s))); + return getType(i, s) == itype::zero || (getType(i, s) == itype::matrix && !conts[i]->check(s)); } [[nodiscard]] const _Ttype& diff --git a/mex/sources/libkorder/tl/tests/tests.cc b/mex/sources/libkorder/tl/tests/tests.cc index e146ddbd1..8c837bf20 100644 --- a/mex/sources/libkorder/tl/tests/tests.cc +++ b/mex/sources/libkorder/tl/tests/tests.cc @@ -450,7 +450,7 @@ TestRunnable::folded_contraction(int r, int nv, int dim) << "\terror normMax: " << v.getMax() << '\n' << "\terror norm1: " << v.getNorm1() << '\n'; - return (v.getMax() < 1.e-10); + return v.getMax() < 1.e-10; } bool @@ -485,7 +485,7 @@ TestRunnable::unfolded_contraction(int r, int nv, int dim) << "\terror normMax: " << v.getMax() << '\n' << "\terror norm1: " << v.getNorm1() << '\n'; - return (v.getMax() < 1.e-10); + return v.getMax() < 1.e-10; } bool @@ -542,7 +542,7 @@ TestRunnable::poly_eval(int r, int nv, int maxdim) << "\tfolded horner error norm max: " << max_fh << '\n' << "\tunfolded horner error norm max: " << max_uh << '\n'; - return (max_ft + max_fh + max_uh < 1.0e-10); + return max_ft + max_fh + max_uh < 1.0e-10; } /****************************************************/ -- GitLab