Skip to content

Commit

Permalink
enforce formatting of C++ code (#76)
Browse files Browse the repository at this point in the history
* add clang format

* add github action check

* indent

* move around

* run make format-cpp

* pin clang-format version?

* try 18

* pin version

* Revert "run make format-cpp"

This reverts commit 576f925.

* run `make format-cpp`

* remove a few pragma messages

* run format

* add includes
  • Loading branch information
shapiromatron authored Nov 4, 2024
1 parent 8646354 commit 4b2cde6
Show file tree
Hide file tree
Showing 98 changed files with 28,148 additions and 28,336 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BasedOnStyle: Google
IndentWidth: 2
UseTab: Never
ColumnLimit: 100
IndentPPDirectives: AfterHash
AlignAfterOpenBracket: BlockIndent
5 changes: 5 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ jobs:
- name: Install dependencies
run: |
source ./tools/linux_ci_setup.sh
- name: Run clang-format
run: |
pip install clang-format==19.1.3
make format-cpp
git diff --exit-code --compact-summary || { echo "Code formatting failed; run 'make format-cpp'"; exit 1; }
- name: Build bmdscore
run: |
source ./tools/linux_ci_env.sh
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean lint format test coverage build dist docs docs-docx docs-serve docs-clean loc
.PHONY: clean lint format format-cpp test coverage build dist docs docs-docx docs-serve docs-clean loc
.DEFAULT_GOAL := help

define PRINT_HELP_PYSCRIPT
Expand All @@ -24,6 +24,9 @@ lint: ## Check for python formatting issues
format: ## Modify python code where possible
@ruff format . && ruff check . --fix --show-fixes

format-cpp: ## Format C++ code
@find src -name "*.cpp" -o -name "*.h" | xargs clang-format -i

test: ## Run unit tests
@py.test

Expand Down
9 changes: 9 additions & 0 deletions docs/source/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ make coverage
make run_tests_with_coverage
```

Code formatting is also enforced in the C++ codebase. To run the formatter, use the following command:

```bash
pip install clang-format==19.1.3
make format-cpp
```

A specific version of clang-format is pinned for reproducibility on all platforms.

## Build and testing `bmds-ui` (BMDS Desktop)

See [documentation](https://github.com/USEPA/BMDS-UI/blob/main/docs/development.md) in the BMDS-UI repository.
Expand Down
72 changes: 36 additions & 36 deletions src/bmdscore/DichGammaBMD_NC.cpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
#include "DichGammaBMD_NC.h"

#ifdef R_COMPILATION
//necessary things to run in R
#include <RcppGSL.h>
#include <RcppEigen.h>
// necessary things to run in R
# include <RcppEigen.h>
# include <RcppGSL.h>
#else
#include <Eigen/Dense>
# include <Eigen/Dense>
#endif

#include <gsl/gsl_blas.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_ieee_utils.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_test.h>
#include <gsl/gsl_ieee_utils.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_cdf.h>

double GAMMA_BMD_EXTRA_NC_INEQUALITY(Eigen::MatrixXd theta, void* data){
log_gamma_inequality *M = (log_gamma_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double g = GAMMA_G(theta(0, 0));
double a = GAMMA_A(theta(1, 0));
double Z = GAMMA_EXTRA_Z(g, a, BMR); //note BMD is a placeholder
Z = Z/BMD;
double rV = 0.0;
rV = (geq) ? inequality - Z : Z - inequality;
return rV;
double GAMMA_BMD_EXTRA_NC_INEQUALITY(Eigen::MatrixXd theta, void* data) {
log_gamma_inequality* M = (log_gamma_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double g = GAMMA_G(theta(0, 0));
double a = GAMMA_A(theta(1, 0));
double Z = GAMMA_EXTRA_Z(g, a, BMR); // note BMD is a placeholder
Z = Z / BMD;
double rV = 0.0;
rV = (geq) ? inequality - Z : Z - inequality;
return rV;
}

double GAMMA_BMD_ADDED_NC_INEQUALITY(Eigen::MatrixXd theta, void* data) {
log_gamma_inequality *M = (log_gamma_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;
log_gamma_inequality* M = (log_gamma_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double g = GAMMA_G(theta(0, 0));
double a = GAMMA_A(theta(1, 0));
double g = GAMMA_G(theta(0, 0));
double a = GAMMA_A(theta(1, 0));

double Z = GAMMA_ADDED_Z(g, a, BMR);
Z = Z / BMD;
double rV = 0.0;
double Z = GAMMA_ADDED_Z(g, a, BMR);
Z = Z / BMD;
double rV = 0.0;

rV = (geq)? inequality - Z: Z - inequality;
rV = (geq) ? inequality - Z : Z - inequality;

return rV;
return rV;
}
64 changes: 31 additions & 33 deletions src/bmdscore/DichLogProbitBMD_NC.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
#define STRICT_R_HEADERS

#include "DichLogProbitBMD_NC.h"

#include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h>
#include "DichLogProbitBMD_NC.h"

#ifdef R_COMPILATION
//necessary things to run in R
#include <RcppGSL.h>
#include <RcppEigen.h>
// necessary things to run in R
# include <RcppEigen.h>
# include <RcppGSL.h>
#else
#include <Eigen/Dense>
# include <Eigen/Dense>
#endif


double logProbit_BMD_EXTRA_NC_INEQUALITY(Eigen::MatrixXd theta, void* data){
log_probit_inequality *M = (log_probit_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double g = LOGPROBIT_G(theta(0, 0));
double a = LOGPROBIT_A(theta(1, 0));
double Z = LOGPROBIT_EXTRA_Z(g, a, BMR); //note BMD is a placeholder
Z = Z / log(BMD);
double rV = 0.0;
rV = (geq) ? inequality - Z : Z - inequality;
return rV;
double logProbit_BMD_EXTRA_NC_INEQUALITY(Eigen::MatrixXd theta, void* data) {
log_probit_inequality* M = (log_probit_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double g = LOGPROBIT_G(theta(0, 0));
double a = LOGPROBIT_A(theta(1, 0));
double Z = LOGPROBIT_EXTRA_Z(g, a, BMR); // note BMD is a placeholder
Z = Z / log(BMD);
double rV = 0.0;
rV = (geq) ? inequality - Z : Z - inequality;
return rV;
}

double logProbit_BMD_ADDED_NC_INEQUALITY(Eigen::MatrixXd theta, void* data) {
log_probit_inequality *M = (log_probit_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double g = LOGPROBIT_G(theta(0, 0));
double a = LOGPROBIT_A(theta(1, 0));
log_probit_inequality* M = (log_probit_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double g = LOGPROBIT_G(theta(0, 0));
double a = LOGPROBIT_A(theta(1, 0));

double Z = LOGPROBIT_ADDED_Z(g, a, BMR);
Z = Z / log(BMD);
double rV = 0.0;
double Z = LOGPROBIT_ADDED_Z(g, a, BMR);
Z = Z / log(BMD);
double rV = 0.0;

rV = (geq)? inequality - Z: Z - inequality;
rV = (geq) ? inequality - Z : Z - inequality;

return rV;
return rV;
}
55 changes: 27 additions & 28 deletions src/bmdscore/DichLogisticBMD_NC.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
#include "DichLogisticBMD_NC.h"

#ifdef R_COMPILATION
//necessary things to run in R
#include <RcppGSL.h>
#include <RcppEigen.h>
// necessary things to run in R
# include <RcppEigen.h>
# include <RcppGSL.h>
#else
#include <Eigen/Dense>
# include <Eigen/Dense>
#endif

double LOGISTIC_BMD_EXTRA_NC_INEQUALITY(Eigen::MatrixXd theta, void* data) {
logistic_inequality *M = (logistic_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double a = LOGISTIC_A(theta(0, 0));
double Z = LOGISTIC_EXTRA_Z(a, BMR); //note BMD is a placeholder
Z = Z / BMD;
double rV = 0.0;
rV = (geq) ? inequality - Z : Z - inequality;
return rV;
logistic_inequality* M = (logistic_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double a = LOGISTIC_A(theta(0, 0));
double Z = LOGISTIC_EXTRA_Z(a, BMR); // note BMD is a placeholder
Z = Z / BMD;
double rV = 0.0;
rV = (geq) ? inequality - Z : Z - inequality;
return rV;
}

double LOGISTIC_BMD_ADDED_NC_INEQUALITY(Eigen::MatrixXd theta, void* data) {
logistic_inequality *M = (logistic_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;
logistic_inequality* M = (logistic_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double a = LOGISTIC_A(theta(0, 0));
double Z = LOGISTIC_ADDED_Z(a, BMR);
Z = pow(Z, a) / pow(BMD, a);
double rV = 0.0;
double a = LOGISTIC_A(theta(0, 0));
double Z = LOGISTIC_ADDED_Z(a, BMR);
Z = pow(Z, a) / pow(BMD, a);
double rV = 0.0;

rV = (geq) ? inequality - Z : Z - inequality;
rV = (geq) ? inequality - Z : Z - inequality;

return rV;
return rV;
}

54 changes: 27 additions & 27 deletions src/bmdscore/DichProbitBMD_NC.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#include "DichProbitBMD_NC.h"

#ifdef R_COMPILATION
//necessary things to run in R
#include <RcppGSL.h>
#include <RcppEigen.h>
// necessary things to run in R
# include <RcppEigen.h>
# include <RcppGSL.h>
#else
#include <Eigen/Dense>
# include <Eigen/Dense>
#endif

#include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h>

double PROBIT_BMD_EXTRA_NC_INEQUALITY(Eigen::MatrixXd theta, void* data) {
probit_inequality *M = (probit_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double a = PROBIT_A(theta(0, 0));
double Z = PROBIT_EXTRA_Z(a, BMR); //note BMD is a placeholder
Z = Z / BMD;
double rV = 0.0;
rV = (geq) ? inequality - Z : Z - inequality;
return rV;
probit_inequality* M = (probit_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double a = PROBIT_A(theta(0, 0));
double Z = PROBIT_EXTRA_Z(a, BMR); // note BMD is a placeholder
Z = Z / BMD;
double rV = 0.0;
rV = (geq) ? inequality - Z : Z - inequality;
return rV;
}

double PROBIT_BMD_ADDED_NC_INEQUALITY(Eigen::MatrixXd theta, void* data) {
probit_inequality *M = (probit_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;
probit_inequality* M = (probit_inequality*)data;
double inequality = M->inequality;
double BMD = M->BMD;
double BMR = M->BMR;
bool geq = M->geq;

double a = PROBIT_A(theta(0, 0));
double Z = PROBIT_ADDED_Z(a, BMR);
Z = pow(Z, a) / pow(BMD, a);
double rV = 0.0;
double a = PROBIT_A(theta(0, 0));
double Z = PROBIT_ADDED_Z(a, BMR);
Z = pow(Z, a) / pow(BMD, a);
double rV = 0.0;

rV = (geq) ? inequality - Z : Z - inequality;
rV = (geq) ? inequality - Z : Z - inequality;

return rV;
return rV;
}
Loading

0 comments on commit 4b2cde6

Please sign in to comment.