From b81bc479b3a4c01e8cbfdfde7150445f0caec9c5 Mon Sep 17 00:00:00 2001 From: Wai-Shing Luk Date: Sun, 1 Dec 2024 03:14:24 +0000 Subject: [PATCH] apply fix-format --- .github/workflows/style.yml | 40 +++++++++++++++++++++++ include/ellalgo/cutting_plane.hpp | 18 +++++----- include/ellalgo/ell_calc_core.hpp | 20 ++++++------ include/ellalgo/oracles/profit_oracle.hpp | 4 +-- source/ell_calc.cpp | 10 +++--- source/ell_calc_core.cpp | 7 ++-- source/profit_oracle.cpp | 4 +-- 7 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/style.yml diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 0000000..4f25e74 --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,40 @@ +name: Style + +on: + push: + branches: + - master + - main + pull_request: + branches: + - master + - main + +env: + CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/cache@v3 + with: + path: "**/cpm_modules" + key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} + + - name: Before Install + run: | + sudo apt-get install g++-10 + sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 90 + + - name: Install format dependencies + run: pip3 install clang-format==18.1.2 cmake_format==0.6.13 pyyaml + + - name: configure + run: cmake -Stest -Bbuild + + - name: check style + run: cmake --build build --target check-format diff --git a/include/ellalgo/cutting_plane.hpp b/include/ellalgo/cutting_plane.hpp index 8911c2b..da650e7 100644 --- a/include/ellalgo/cutting_plane.hpp +++ b/include/ellalgo/cutting_plane.hpp @@ -47,9 +47,10 @@ template inline auto invalid_value() -> * @param[in] options maximum iteration and error tolerance etc. * @return Information of Cutting-plane method */ -template inline auto cutting_plane_feas( - OracleFeas &omega, SearchSpace &space, - const Options &options = Options()) -> std::tuple, size_t> { +template +inline auto cutting_plane_feas(OracleFeas &omega, SearchSpace &space, + const Options &options = Options()) + -> std::tuple, size_t> { for (auto niter = 0U; niter != options.max_iters; ++niter) { const auto cut = omega.assess_feas(space.xc()); if (!cut) { // feasible sol'n obtained @@ -90,9 +91,10 @@ template inline auto cutting_plane_f * @param[in] options maximum iteration and error tolerance etc. * @return Information of Cutting-plane method */ -template inline auto cutting_plane_optim( - OracleOptim &omega, SearchSpace &space, Num &gamma, - const Options &options = Options()) -> std::tuple, size_t> { +template +inline auto cutting_plane_optim(OracleOptim &omega, SearchSpace &space, Num &gamma, + const Options &options = Options()) + -> std::tuple, size_t> { auto x_best = invalid_value>(); for (auto niter = 0U; niter < options.max_iters; ++niter) { const auto __result1 = omega.assess_optim(space.xc(), gamma); @@ -243,8 +245,8 @@ class BSearchAdaptor { * @return CInfo */ template -inline auto bsearch(Oracle &omega, const std::pair &intvl, - const Options &options = Options()) -> std::tuple { +inline auto bsearch(Oracle &omega, const std::pair &intvl, const Options &options = Options()) + -> std::tuple { // assume monotone // auto& [lower, upper] = intvl; auto lower = intvl.first; diff --git a/include/ellalgo/ell_calc_core.hpp b/include/ellalgo/ell_calc_core.hpp index 9587c8b..2df8ee2 100644 --- a/include/ellalgo/ell_calc_core.hpp +++ b/include/ellalgo/ell_calc_core.hpp @@ -88,8 +88,8 @@ class EllCalcCore { * @return The function `calc_parallel_cut` returns a tuple containing three values: `rho`, * `sigma`, and `delta`. */ - auto calc_parallel_cut(const double &beta0, const double &beta1, - const double &tsq) const -> std::tuple { + auto calc_parallel_cut(const double &beta0, const double &beta1, const double &tsq) const + -> std::tuple { auto b0b1 = beta0 * beta1; auto eta = tsq + this->_n_f * b0b1; return this->calc_parallel_cut_fast(beta0, beta1, tsq, b0b1, eta); @@ -110,8 +110,8 @@ class EllCalcCore { * @return Tuple containing computed rho, sigma and delta. */ auto calc_parallel_cut_fast(const double &beta0, const double &beta1, const double &tsq, - const double &b0b1, - const double &eta) const -> std::tuple; + const double &b0b1, const double &eta) const + -> std::tuple; /** * Calculates ellipsoid parameters after parallel central cuts. @@ -131,8 +131,8 @@ class EllCalcCore { * @param[in] tsq Square of tau parameter. * @return Tuple containing computed rho, sigma and delta. */ - auto calc_parallel_central_cut(const double &beta1, - const double &tsq) const -> std::tuple; + auto calc_parallel_central_cut(const double &beta1, const double &tsq) const + -> std::tuple; /** * Calculates new ellipsoid parameters after bias cut. @@ -153,8 +153,8 @@ class EllCalcCore { * * @return The function `calc_bias_cut` returns a tuple containing the following values: */ - auto calc_bias_cut(const double &beta, - const double &tau) const -> std::tuple { + auto calc_bias_cut(const double &beta, const double &tau) const + -> std::tuple { return this->calc_bias_cut_fast(beta, tau, tau + this->_n_f * beta); } @@ -169,8 +169,8 @@ class EllCalcCore { * It takes the bias parameter beta, tau, and eta as inputs and returns a * tuple containing the computed rho, sigma, delta values. */ - auto calc_bias_cut_fast(const double &beta, const double &tau, - const double &eta) const -> std::tuple; + auto calc_bias_cut_fast(const double &beta, const double &tau, const double &eta) const + -> std::tuple; /** * Calculates new ellipsoid parameters after applying a central cut. diff --git a/include/ellalgo/oracles/profit_oracle.hpp b/include/ellalgo/oracles/profit_oracle.hpp index c8e7f09..6481f38 100644 --- a/include/ellalgo/oracles/profit_oracle.hpp +++ b/include/ellalgo/oracles/profit_oracle.hpp @@ -188,6 +188,6 @@ class ProfitOracleQ { * * @see cutting_plane_optim_q */ - auto assess_optim_q(const Vec &y, double &gamma, - bool retry) -> std::tuple; + auto assess_optim_q(const Vec &y, double &gamma, bool retry) + -> std::tuple; }; diff --git a/source/ell_calc.cpp b/source/ell_calc.cpp index b528c93..81dbdb6 100644 --- a/source/ell_calc.cpp +++ b/source/ell_calc.cpp @@ -23,8 +23,9 @@ * 3. sigma: A double value representing the calculated sigma. * 4. delta: A double value representing the calculated delta. */ -auto EllCalc::calc_parallel_bias_cut(const double &beta0, const double &beta1, const double &tsq) - const -> std::tuple> { +auto EllCalc::calc_parallel_bias_cut(const double &beta0, const double &beta1, + const double &tsq) const + -> std::tuple> { if (beta1 < beta0) { return {CutStatus::NoSoln, {0.0, 0.0, 0.0}}; // no sol'n } @@ -137,8 +138,9 @@ auto EllCalc::calc_central_cut(const double &tsq) const * @return The function `calc_parallel_bias_cut_q` returns a tuple of type `std::tuple>`. */ -auto EllCalc::calc_parallel_bias_cut_q(const double &beta0, const double &beta1, const double &tsq) - const -> std::tuple> { +auto EllCalc::calc_parallel_bias_cut_q(const double &beta0, const double &beta1, + const double &tsq) const + -> std::tuple> { if (beta1 < beta0) { return {CutStatus::NoSoln, {0.0, 0.0, 0.0}}; // no sol'n } diff --git a/source/ell_calc_core.cpp b/source/ell_calc_core.cpp index a6b5b3e..6093156 100644 --- a/source/ell_calc_core.cpp +++ b/source/ell_calc_core.cpp @@ -28,9 +28,10 @@ * @return The function `calc_parallel_cut` returns a tuple containing three values: `rho`, `sigma`, * and `delta`. */ -auto EllCalcCore::calc_parallel_cut_fast( - const double& beta0, const double& beta1, const double& tsq, const double& b0b1, - const double& eta) const -> std::tuple { +auto EllCalcCore::calc_parallel_cut_fast(const double& beta0, const double& beta1, + const double& tsq, const double& b0b1, + const double& eta) const + -> std::tuple { auto bavg = 0.5 * (beta0 + beta1); auto bavgsq = bavg * bavg; auto h = 0.5 * (tsq + b0b1) + this->_n_f * bavgsq; diff --git a/source/profit_oracle.cpp b/source/profit_oracle.cpp index 7a3d9e8..49d3f64 100644 --- a/source/profit_oracle.cpp +++ b/source/profit_oracle.cpp @@ -103,8 +103,8 @@ auto ProfitOracle::assess_optim(const Vec &y, double &gamma) -> std::tuple std::tuple { +auto ProfitOracleQ::assess_optim_q(const Vec &y, double &gamma, bool retry) + -> std::tuple { if (!retry) { auto cut = this->_P.assess_feas(y, gamma); if (cut) {