Skip to content

Commit

Permalink
apply fix-format
Browse files Browse the repository at this point in the history
  • Loading branch information
luk036 committed Dec 1, 2024
1 parent 4edc44b commit b81bc47
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 29 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 10 additions & 8 deletions include/ellalgo/cutting_plane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ template <typename T> inline auto invalid_value() ->
* @param[in] options maximum iteration and error tolerance etc.
* @return Information of Cutting-plane method
*/
template <typename OracleFeas, typename SearchSpace> inline auto cutting_plane_feas(
OracleFeas &omega, SearchSpace &space,
const Options &options = Options()) -> std::tuple<CuttingPlaneArrayType<SearchSpace>, size_t> {
template <typename OracleFeas, typename SearchSpace>
inline auto cutting_plane_feas(OracleFeas &omega, SearchSpace &space,
const Options &options = Options())
-> std::tuple<CuttingPlaneArrayType<SearchSpace>, 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
Expand Down Expand Up @@ -90,9 +91,10 @@ template <typename OracleFeas, typename SearchSpace> inline auto cutting_plane_f
* @param[in] options maximum iteration and error tolerance etc.
* @return Information of Cutting-plane method
*/
template <typename OracleOptim, typename SearchSpace, typename Num> inline auto cutting_plane_optim(
OracleOptim &omega, SearchSpace &space, Num &gamma,
const Options &options = Options()) -> std::tuple<CuttingPlaneArrayType<SearchSpace>, size_t> {
template <typename OracleOptim, typename SearchSpace, typename Num>
inline auto cutting_plane_optim(OracleOptim &omega, SearchSpace &space, Num &gamma,
const Options &options = Options())
-> std::tuple<CuttingPlaneArrayType<SearchSpace>, size_t> {
auto x_best = invalid_value<CuttingPlaneArrayType<SearchSpace>>();
for (auto niter = 0U; niter < options.max_iters; ++niter) {
const auto __result1 = omega.assess_optim(space.xc(), gamma);
Expand Down Expand Up @@ -243,8 +245,8 @@ class BSearchAdaptor {
* @return CInfo
*/
template <typename Oracle, typename T>
inline auto bsearch(Oracle &omega, const std::pair<T, T> &intvl,
const Options &options = Options()) -> std::tuple<T, size_t> {
inline auto bsearch(Oracle &omega, const std::pair<T, T> &intvl, const Options &options = Options())
-> std::tuple<T, size_t> {
// assume monotone
// auto& [lower, upper] = intvl;
auto lower = intvl.first;
Expand Down
20 changes: 10 additions & 10 deletions include/ellalgo/ell_calc_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double, double, double> {
auto calc_parallel_cut(const double &beta0, const double &beta1, const double &tsq) const
-> std::tuple<double, double, double> {
auto b0b1 = beta0 * beta1;
auto eta = tsq + this->_n_f * b0b1;
return this->calc_parallel_cut_fast(beta0, beta1, tsq, b0b1, eta);
Expand All @@ -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<double, double, double>;
const double &b0b1, const double &eta) const
-> std::tuple<double, double, double>;

/**
* Calculates ellipsoid parameters after parallel central cuts.
Expand All @@ -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<double, double, double>;
auto calc_parallel_central_cut(const double &beta1, const double &tsq) const
-> std::tuple<double, double, double>;

/**
* Calculates new ellipsoid parameters after bias cut.
Expand All @@ -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<double, double, double> {
auto calc_bias_cut(const double &beta, const double &tau) const
-> std::tuple<double, double, double> {
return this->calc_bias_cut_fast(beta, tau, tau + this->_n_f * beta);
}

Expand All @@ -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<double, double, double>;
auto calc_bias_cut_fast(const double &beta, const double &tau, const double &eta) const
-> std::tuple<double, double, double>;

/**
* Calculates new ellipsoid parameters after applying a central cut.
Expand Down
4 changes: 2 additions & 2 deletions include/ellalgo/oracles/profit_oracle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ class ProfitOracleQ {
*
* @see cutting_plane_optim_q
*/
auto assess_optim_q(const Vec &y, double &gamma,
bool retry) -> std::tuple<Cut, bool, Vec, bool>;
auto assess_optim_q(const Vec &y, double &gamma, bool retry)
-> std::tuple<Cut, bool, Vec, bool>;
};
10 changes: 6 additions & 4 deletions source/ell_calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CutStatus, std::tuple<double, double, double>> {
auto EllCalc::calc_parallel_bias_cut(const double &beta0, const double &beta1,
const double &tsq) const
-> std::tuple<CutStatus, std::tuple<double, double, double>> {
if (beta1 < beta0) {
return {CutStatus::NoSoln, {0.0, 0.0, 0.0}}; // no sol'n
}
Expand Down Expand Up @@ -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<CutStatus,
* std::tuple<double, double, double>>`.
*/
auto EllCalc::calc_parallel_bias_cut_q(const double &beta0, const double &beta1, const double &tsq)
const -> std::tuple<CutStatus, std::tuple<double, double, double>> {
auto EllCalc::calc_parallel_bias_cut_q(const double &beta0, const double &beta1,
const double &tsq) const
-> std::tuple<CutStatus, std::tuple<double, double, double>> {
if (beta1 < beta0) {
return {CutStatus::NoSoln, {0.0, 0.0, 0.0}}; // no sol'n
}
Expand Down
7 changes: 4 additions & 3 deletions source/ell_calc_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double, double, double> {
auto EllCalcCore::calc_parallel_cut_fast(const double& beta0, const double& beta1,
const double& tsq, const double& b0b1,
const double& eta) const
-> std::tuple<double, double, double> {
auto bavg = 0.5 * (beta0 + beta1);
auto bavgsq = bavg * bavg;
auto h = 0.5 * (tsq + b0b1) + this->_n_f * bavgsq;
Expand Down
4 changes: 2 additions & 2 deletions source/profit_oracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ auto ProfitOracle::assess_optim(const Vec &y, double &gamma) -> std::tuple<Cut,
*
* @return The function `assess_optim_q` returns a tuple containing the following elements:
*/
auto ProfitOracleQ::assess_optim_q(const Vec &y, double &gamma,
bool retry) -> std::tuple<Cut, bool, Vec, bool> {
auto ProfitOracleQ::assess_optim_q(const Vec &y, double &gamma, bool retry)
-> std::tuple<Cut, bool, Vec, bool> {
if (!retry) {
auto cut = this->_P.assess_feas(y, gamma);
if (cut) {
Expand Down

0 comments on commit b81bc47

Please sign in to comment.