Skip to content

Commit

Permalink
Merge pull request #500 from NOAA-FIMS/format-c++-code
Browse files Browse the repository at this point in the history
format C++ code with clang format
  • Loading branch information
ChristineStawitz-NOAA authored Nov 1, 2023
2 parents f8e9b06 + 8f803f1 commit 35b055d
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 59 deletions.
23 changes: 12 additions & 11 deletions inst/include/common/fims_math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace fims_math {
/**
* @brief The exponential function.
*
* @param x value to exponentiate. Please use fims_math::exp<double>(x) if x is an
* integer.
* @param x value to exponentiate. Please use fims_math::exp<double>(x) if x is
* an integer.
* @return the exponentiated value
*/
template <class Type>
Expand All @@ -37,8 +37,8 @@ inline const Type exp(const Type &x) {

/**
* @brief The natural log function (base e)
* @param x the value to take the log of. Please use fims_math::log<double>(x) if x
* is an integer.
* @param x the value to take the log of. Please use fims_math::log<double>(x)
* if x is an integer.
* @return
*/
template <class Type>
Expand All @@ -54,8 +54,8 @@ inline const Type log(const Type &x) {
* @brief The exponential function.
* The code cannot be tested using the compilation flag
* -DTMB_MODEL through CMake and Google Test
* @param x value to exponentiate. Please use fims_math::exp<double>(x) if x is an
* integer.
* @param x value to exponentiate. Please use fims_math::exp<double>(x) if x is
* an integer.
* @return the exponentiated value
*/
template <class Type>
Expand All @@ -73,8 +73,8 @@ inline const double exp(const double &x) {
* @brief The natural log function (base e)
* The code cannot be tested using the compilation flag
* -DTMB_MODEL through CMake and Google Test.
* @param x the value to take the log of. Please use fims_math::log<double>(x) if x
* is an integer.
* @param x the value to take the log of. Please use fims_math::log<double>(x)
* if x is an integer.
* @return the log of the value
*/
template <class Type>
Expand All @@ -100,7 +100,8 @@ inline const double log(const double &x) {
* @return
*/
template <class Type>
inline const Type logistic(const Type &median, const Type &slope, const Type &x) {
inline const Type logistic(const Type &median, const Type &slope,
const Type &x) {
return (1.0) / (1.0 + exp(-1.0 * slope * (x - median)));
}

Expand Down Expand Up @@ -155,8 +156,8 @@ inline const Type inv_logit(const Type &a, const Type &b, const Type &logit_x) {

template <class Type>
inline const Type double_logistic(const Type &median_asc, const Type &slope_asc,
const Type &median_desc, const Type &slope_desc,
const Type &x) {
const Type &median_desc,
const Type &slope_desc, const Type &x) {
return (1.0) / (1.0 + exp(-1.0 * slope_asc * (x - median_asc))) *
(1.0 - (1.0) / (1.0 + exp(-1.0 * slope_desc * (x - median_desc))));
}
Expand Down
50 changes: 26 additions & 24 deletions inst/include/common/information.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Information {
size_t nages; /**< number of ages>*/

static std::shared_ptr<Information<Type> >
fims_information; /**< singleton instance >*/
fims_information; /**< singleton instance >*/
std::vector<Type*> parameters; /**< list of all estimated parameters >*/
std::vector<Type*>
random_effects_parameters; /**< list of all random effects parameters >*/
Expand All @@ -46,42 +46,40 @@ class Information {
// data objects
std::map<uint32_t, std::shared_ptr<fims_data_object::DataObject<Type> > >
data_objects; /*!< map that holds data objects >*/
typedef typename std::map<uint32_t,
std::shared_ptr<fims_data_object::DataObject<Type> > >::iterator
typedef typename std::map<
uint32_t, std::shared_ptr<fims_data_object::DataObject<Type> > >::iterator
data_iterator; /**< iterator for the data objects */

// life history modules
std::map<uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type> > >
recruitment_models; /*!<hash map to link each object to its shared
location in memory*/
typedef
typename std::map<uint32_t,
std::shared_ptr<fims_popdy::RecruitmentBase<Type> > >::iterator
recruitment_models_iterator;
typedef typename std::map<
uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type> > >::iterator
recruitment_models_iterator;
/**< iterator for recruitment objects>*/

std::map<uint32_t, std::shared_ptr<fims_popdy::SelectivityBase<Type> > >
selectivity_models; /*!<hash map to link each object to its shared
location in memory*/
typedef
typename std::map<uint32_t,
std::shared_ptr<fims_popdy::SelectivityBase<Type> > >::iterator
selectivity_models_iterator;
typedef typename std::map<
uint32_t, std::shared_ptr<fims_popdy::SelectivityBase<Type> > >::iterator
selectivity_models_iterator;
/**< iterator for selectivity objects>*/

std::map<uint32_t, std::shared_ptr<fims_popdy::GrowthBase<Type> > >
growth_models; /*!<hash map to link each object to its shared location in
memory*/
typedef typename std::map<uint32_t,
std::shared_ptr<fims_popdy::GrowthBase<Type> > >::iterator
typedef typename std::map<
uint32_t, std::shared_ptr<fims_popdy::GrowthBase<Type> > >::iterator
growth_models_iterator;
/**< iterator for growth objects>*/

std::map<uint32_t, std::shared_ptr<fims_popdy::MaturityBase<Type> > >
maturity_models; /*!<hash map to link each object to its shared location
in memory*/
typedef typename std::map<uint32_t,
std::shared_ptr<fims_popdy::MaturityBase<Type> > >::iterator
typedef typename std::map<
uint32_t, std::shared_ptr<fims_popdy::MaturityBase<Type> > >::iterator
maturity_models_iterator;
/**< iterator for maturity objects>*/

Expand All @@ -90,27 +88,29 @@ class Information {
fleets; /*!<hash map to link each object to its shared location in
memory*/
typedef
typename std::map<uint32_t, std::shared_ptr<fims_popdy::Fleet<Type> > >::iterator
typename std::map<uint32_t,
std::shared_ptr<fims_popdy::Fleet<Type> > >::iterator
fleet_iterator;
/**< iterator for fleet objects>*/

// populations
std::map<uint32_t, std::shared_ptr<fims_popdy::Population<Type> > >
populations; /*!<hash map to link each object to its shared location in
memory*/
typedef typename std::map<uint32_t,
std::shared_ptr<fims_popdy::Population<Type> > >::iterator
typedef typename std::map<
uint32_t, std::shared_ptr<fims_popdy::Population<Type> > >::iterator
population_iterator;
/**< iterator for population objects>*/

// distributions
std::map<uint32_t, std::shared_ptr<fims_distributions::DistributionsBase<Type> > >
std::map<uint32_t,
std::shared_ptr<fims_distributions::DistributionsBase<Type> > >
distribution_models; /*!<hash map to link each object to its shared
location in memory*/
typedef
typename std::map<uint32_t,
std::shared_ptr<fims_distributions::DistributionsBase<Type> > >::iterator
distribution_models_iterator;
typedef typename std::map<
uint32_t,
std::shared_ptr<fims_distributions::DistributionsBase<Type> > >::iterator
distribution_models_iterator;
/**< iterator for distribution objects>*/

Information() {}
Expand All @@ -135,7 +135,9 @@ class Information {
*
* @param p
*/
void RegisterParameter(Type& p) { this->fixed_effects_parameters.push_back(&p); }
void RegisterParameter(Type& p) {
this->fixed_effects_parameters.push_back(&p);
}

/**
* Register a random effect as estimable.
Expand Down
4 changes: 2 additions & 2 deletions inst/include/distributions/functors/tmb_distributions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ template <typename Type>
struct Dnorm : public DistributionsBase<Type> {
Type x; /*!< observation */
Type mean; /*!< mean of the normal distribution */
Type sd; /*!< standard deviation of the normal distribution, must be strictly
positive.*/
Type sd; /*!< standard deviation of the normal distribution, must be strictly
positive.*/

Dnorm() : DistributionsBase<Type>() {}

Expand Down
3 changes: 2 additions & 1 deletion inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class AgeCompDataInterface : public DataInterfaceBase {
template <typename Type>
bool add_to_fims_tmb_internal() {
std::shared_ptr<fims_data_object::DataObject<Type>> age_comp_data =
std::make_shared<fims_data_object::DataObject<Type>>(this->ymax, this->amax);
std::make_shared<fims_data_object::DataObject<Type>>(this->ymax,
this->amax);

age_comp_data->id = this->id;
for (int y = 0; y < ymax; y++) {
Expand Down
7 changes: 4 additions & 3 deletions inst/include/population_dynamics/fleet/fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ struct Fleet : public fims_model_object::FIMSObject<Type> {
size_t dims = this->observed_agecomp_data->get_imax() *
this->observed_agecomp_data->get_jmax();
if (dims != this->catch_numbers_at_age.size()) {
fims::fims_log::get("fleet.log") << "Error: observed age comp is of size "
<< dims << " and expected is of size "
<< this->age_composition.size() << std::endl;
fims::fims_log::get("fleet.log")
<< "Error: observed age comp is of size " << dims
<< " and expected is of size " << this->age_composition.size()
<< std::endl;
} else {
for (size_t y = 0; y < this->nyears; y++) {
// EigenVector declares a vector type from the Eigen library, which is
Expand Down
2 changes: 1 addition & 1 deletion inst/include/population_dynamics/growth/functors/ewaa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ struct EWAAgrowth : public GrowthBase<Type> {
return ret;
}
};
} // namespace fims
} // namespace fims_popdy
#endif /* POPULATION_DYNAMICS_GROWTH_EWAA_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ struct GrowthBase : public fims_model_object::FIMSObject<Type> {
template <typename Type>
uint32_t GrowthBase<Type>::id_g = 0;

} // namespace fims
} // namespace fims_popdy

#endif /* POPULATION_DYNAMICS_GROWTH_BASE_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ struct LogisticMaturity : public MaturityBase<Type> {
* @param x The independent variable in the logistic function (e.g., age or
* size at maturity).
*/
virtual const Type evaluate(const Type & x) {
virtual const Type evaluate(const Type& x) {
return fims_math::logistic<Type>(median, slope, x);
}
};

} // namespace fims
} // namespace fims_popdy

#endif /* POPULATION_DYNAMICS_MATURITY_LOGISTIC_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ struct MaturityBase : public fims_model_object::FIMSObject<Type> {
template <typename Type>
uint32_t MaturityBase<Type>::id_g = 0;

} // namespace fims
} // namespace fims_popdy

#endif /* POPULATION_DYNAMICS_MATURITY_BASE_HPP */
12 changes: 7 additions & 5 deletions inst/include/population_dynamics/population/population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ directly?)
template <typename Type>
struct Population : public fims_model_object::FIMSObject<Type> {
using ParameterVector =
typename fims::ModelTraits<Type>::ParameterVector; /*!< the vector of population
parameters*/
typename fims::ModelTraits<Type>::ParameterVector; /*!< the vector of
population parameters*/
static uint32_t id_g; /*!< reference id for population object*/
size_t nyears; /*!< total number of years in the fishery*/
size_t nseasons; /*!< total number of seasons in the fishery*/
Expand Down Expand Up @@ -106,12 +106,14 @@ struct Population : public fims_model_object::FIMSObject<Type> {

// Define objective function object to be able to REPORT and ADREPORT
#ifdef TMB_MODEL
::objective_function<Type> *of; // :: references global namespace, defined in src/FIMS.cpp, available anywhere in the R package
::objective_function<Type>
*of; // :: references global namespace, defined in src/FIMS.cpp,
// available anywhere in the R package
#endif

// this -> means you're referring to a class member (member of self)

Population() { this->id = Population::id_g++; }
Population() { this->id = Population::id_g++; }

/**
* @brief Initialize values. Called once at the start of model run.
Expand Down Expand Up @@ -692,6 +694,6 @@ struct Population : public fims_model_object::FIMSObject<Type> {
template <class Type>
uint32_t Population<Type>::id_g = 0;

} // namespace fims
} // namespace fims_popdy

#endif /* FIMS_POPULATION_DYNAMICS_POPULATION_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ namespace fims_popdy {
template <typename Type>
class Subpopulation {};

} // namespace fims
} // namespace fims_popdy

#endif /* FIMS_POPULATION_DYNAMICS_POPULATION_SUBPOPULATION_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ struct RecruitmentBase : public fims_model_object::FIMSObject<Type> {

template <class Type>
uint32_t RecruitmentBase<Type>::id_g = 0;
} // namespace fims
} // namespace fims_popdy

#endif /* FIMS_POPULATION_DYNAMICS_RECRUITMENT_BASE_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ struct SRBevertonHolt : public RecruitmentBase<Type> {
}
};

} // namespace fims
} // namespace fims_popdy

#endif /* FIMS_POPULATION_DYNAMICS_RECRUITMENT_SR_BEVERTON_HOLT_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ struct DoubleLogisticSelectivity : public SelectivityBase<Type> {
*/
virtual const Type evaluate(const Type &x) {
return fims_math::double_logistic<Type>(median_asc, slope_asc, median_desc,
slope_desc, x);
slope_desc, x);
}
};

} // namespace fims
} // namespace fims_popdy

#endif /* POPULATION_DYNAMICS_SELECTIVITY_DOUBLE_LOGISTIC_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ struct LogisticSelectivity : public SelectivityBase<Type> {
}
};

} // namespace fims
} // namespace fims_popdy

#endif /* POPULATION_DYNAMICS_SELECTIVITY_LOGISTIC_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ struct SelectivityBase : public fims_model_object::FIMSObject<Type> {
template <typename Type>
uint32_t SelectivityBase<Type>::id_g = 0;

} // namespace fims
} // namespace fims_popdy

#endif /* POPULATION_DYNAMICS_SELECTIVITY_BASE_HPP */
3 changes: 2 additions & 1 deletion tests/gtest/test_population_test_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class PopulationPrepareTestFixture : public testing::Test {
// Does Fmort need to be in side of the year loop like log_q?
for (int i = 0; i < nfleets; i++) {
auto fleet = std::make_shared<fims_popdy::Fleet<double>>();
auto selectivity = std::make_shared<fims_popdy::LogisticSelectivity<double>>();
auto selectivity =
std::make_shared<fims_popdy::LogisticSelectivity<double>>();
selectivity->median = 7;
selectivity->slope = 0.5;

Expand Down

0 comments on commit 35b055d

Please sign in to comment.