From f08cdbf1265181a604f1b9dd4532b3c4244c3545 Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Fri, 2 Aug 2024 19:23:10 +0000 Subject: [PATCH] fix warnings --- inst/include/common/information.hpp | 2 +- .../functors/density_components_base.hpp | 2 +- .../functors/multinomial_lpmf.hpp | 14 +++---- .../rcpp/rcpp_objects/rcpp_fleet.hpp | 2 +- .../rcpp/rcpp_objects/rcpp_interface_base.hpp | 4 +- .../rcpp/rcpp_objects/rcpp_population.hpp | 4 +- .../rcpp_objects/rcpp_tmb_distribution.hpp | 38 +++++++++---------- 7 files changed, 31 insertions(+), 35 deletions(-) diff --git a/inst/include/common/information.hpp b/inst/include/common/information.hpp index 92a1adbf9..4460c0776 100644 --- a/inst/include/common/information.hpp +++ b/inst/include/common/information.hpp @@ -272,7 +272,7 @@ class Information { INFO_LOG << "Checking for available density components data objects." << std::endl; //set data objects - if(d->input_type == "data" & d->observed_data_id_m != -999){ + if((d->input_type == "data") & (d->observed_data_id_m != -999)){ uint32_t observed_data_id = static_cast(d->observed_data_id_m); data_iterator it = this->data_objects.find(observed_data_id); INFO_LOG << "Input data id = " << observed_data_id << "." << std::endl; diff --git a/inst/include/distributions/functors/density_components_base.hpp b/inst/include/distributions/functors/density_components_base.hpp index 60a8b944c..6e8011294 100644 --- a/inst/include/distributions/functors/density_components_base.hpp +++ b/inst/include/distributions/functors/density_components_base.hpp @@ -35,7 +35,7 @@ struct DensityComponentBase : public fims_model_object::FIMSObject { // Assigning each one its own ID is a way to keep track of // all the instances of the DensityComponentBase class. static uint32_t id_g; /**< global unique identifier for distribution modules */ - size_t observed_data_id_m = -999; /*!< id of observed data component*/ + uint32_t observed_data_id_m = -999; /*!< id of observed data component*/ std::shared_ptr> observed_values; /**< observed data*/ fims::Vector x; /**< input value of distribution function for proirs or random effects*/ diff --git a/inst/include/distributions/functors/multinomial_lpmf.hpp b/inst/include/distributions/functors/multinomial_lpmf.hpp index d84fa5437..bf5604e81 100644 --- a/inst/include/distributions/functors/multinomial_lpmf.hpp +++ b/inst/include/distributions/functors/multinomial_lpmf.hpp @@ -73,20 +73,16 @@ namespace fims_distributions #ifdef TMB_MODEL for (size_t j = 0; j < dims[1]; j++){ - if (this->observed_values->at(i, j) != + if (this->observed_values->at(i, j) == this->observed_values->na_value) { - size_t idx = (i * dims[1]) + j; - } else { containsNA = true; break; } - } if(!containsNA){ - for (size_t j = 0; j < dims[1]; j++){ - size_t idx = (i * dims[1]) + j; - x_vector[j] = this->observed_values->at(i, j); - prob_vector[j] = this->expected_values[idx]; - } + size_t idx = (i * dims[1]) + j; + x_vector[j] = this->observed_values->at(i, j); + prob_vector[j] = this->expected_values[idx]; + } this->lpdf_vec[i] = dmultinom((vector)x_vector, (vector)prob_vector, true); diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp index 0d667925d..25400c50a 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp @@ -108,7 +108,7 @@ class FleetInterface : public FleetInterfaceBase { } fleet->log_Fmort.resize(this->log_Fmort.size()); - for (int i = 0; i < log_Fmort.size(); i++) { + for (size_t i = 0; i < log_Fmort.size(); i++) { fleet->log_Fmort[i] = this->log_Fmort[i].value_m; if (this->log_Fmort[i].estimated_m) { diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp index e219e9e70..01b256246 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp @@ -212,7 +212,7 @@ class ParameterVector{ * @param value The value to be assigned */ void fill_min(double value){ - for(size_t i = 0; i < this->storage_m.size(); i++){ + for(int i = 0; i < this->storage_m.size(); i++){ Parameter p = Rcpp::as(this->storage_m[i]); p.min_m = value; this->storage_m[i] = Rcpp::wrap(p); @@ -225,7 +225,7 @@ class ParameterVector{ * @param value The value to be assigned */ void fill_max(double value){ - for(size_t i = 0; i < this->storage_m.size(); i++){ + for(int i = 0; i < this->storage_m.size(); i++){ Parameter p = Rcpp::as(this->storage_m[i]); p.max_m = value; this->storage_m[i] = Rcpp::wrap(p); diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp index c4f33ee0a..8f8b1086d 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp @@ -130,7 +130,7 @@ class PopulationInterface : public PopulationInterfaceBase { population->maturity_id = this->maturity_id; population->log_M.resize(this->log_M.size()); population->log_init_naa.resize(this->log_init_naa.size()); - for (int i = 0; i < log_M.size(); i++) { + for (size_t i = 0; i < log_M.size(); i++) { population->log_M[i] = this->log_M[i].value_m; if (this->log_M[i].estimated_m) { info->RegisterParameter(population->log_M[i]); @@ -138,7 +138,7 @@ class PopulationInterface : public PopulationInterfaceBase { } info->variable_map[this->log_M.id_m] = &(population)->log_M; - for (int i = 0; i < log_init_naa.size(); i++) { + for (size_t i = 0; i < log_init_naa.size(); i++) { population->log_init_naa[i] = this->log_init_naa[i].value_m; if (this->log_init_naa[i].estimated_m) { info->RegisterParameter(population->log_init_naa[i]); diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index f9daa094b..517835ede 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -113,7 +113,7 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { virtual void set_distribution_links(std::string input_type, Rcpp::IntegerVector ids){ this->input_type_m = input_type; this->key_m.resize(ids.size()); - for(size_t i; ikey_m[i] = ids[i]; } } @@ -130,13 +130,13 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { dnorm.x.resize(this->x.size()); dnorm.expected_values.resize(this->expected_values.size()); dnorm.log_sd.resize(this->log_sd.size()); - for(int i=0; ix[i].value_m; } - for(int i=0; iexpected_values[i].value_m; } - for(int i=0; ilog_sd[i].value_m; } return dnorm.evaluate(); @@ -161,16 +161,16 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { distribution->id = this->id_m; distribution->x.resize(this->x.size()); - for(int i=0; ix.size(); i++){ + for(size_t i=0; ix.size(); i++){ distribution->x[i] = this->x[i].value_m; } // set relative info distribution->expected_values.resize(this->expected_values.size()); - for(int i=0; iexpected_values.size(); i++){ + for(size_t i=0; iexpected_values.size(); i++){ distribution->expected_values[i] = this->expected_values[i].value_m; } distribution->log_sd.resize(this->log_sd.size()); - for(int i=0; ilog_sd.size(); i++){ + for(size_t i=0; ilog_sd.size(); i++){ distribution->log_sd[i] = this->log_sd[i].value_m; } @@ -235,7 +235,7 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase { virtual void set_distribution_links(std::string input_type, Rcpp::IntegerVector ids){ this->input_type_m = input_type; this->key_m.resize(ids.size()); - for(size_t i; ikey_m[i] = ids[i]; } } @@ -253,13 +253,13 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase { dlnorm.x.resize(this->x.size()); dlnorm.expected_values.resize(this->expected_values.size()); dlnorm.log_logsd.resize(this->log_logsd.size()); - for(int i=0; ix[i].value_m; } - for(int i=0; iexpected_values[i].value_m; } - for(int i=0; ilog_logsd[i].value_m; } return dlnorm.evaluate(); @@ -281,16 +281,16 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase { interface_observed_data_id_m; distribution->input_type = this->input_type; distribution->x.resize(this->x.size()); - for(int i=0; ix.size(); i++){ + for(size_t i=0; ix.size(); i++){ distribution->x[i] = this->x[i].value_m; } // set relative info distribution->expected_values.resize(this->expected_values.size()); - for(int i=0; iexpected_values.size(); i++){ + for(size_t i=0; iexpected_values.size(); i++){ distribution->expected_values[i] = this->expected_values[i].value_m; } distribution->log_logsd.resize(this->log_logsd.size()); - for(int i=0; ilog_logsd.size(); i++){ + for(size_t i=0; ilog_logsd.size(); i++){ distribution->log_logsd[i] = this->log_logsd[i].value_m; } @@ -354,7 +354,7 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { virtual void set_distribution_links(std::string input_type, Rcpp::IntegerVector ids){ this->input_type_m = input_type; this->key_m.resize(ids.size()); - for(size_t i; ikey_m[i] = ids[i]; } } @@ -371,10 +371,10 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { // Declare TMBVector in this scope dmultinom.x.resize(this->x.size()); dmultinom.expected_values.resize(this->expected_values.size()); - for(int i=0; ix[i].value_m; } - for(int i=0; iexpected_values[i].value_m; } dmultinom.dims.resize(2); @@ -397,12 +397,12 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { distribution->observed_data_id_m = interface_observed_data_id_m; distribution->x.resize(this->x.size()); - for(int i=0; ix.size(); i++){ + for(size_t i=0; ix.size(); i++){ distribution->x[i] = this->x[i].value_m; } // set relative info distribution->expected_values.resize(this->expected_values.size()); - for(int i=0; iexpected_values.size(); i++){ + for(size_t i=0; iexpected_values.size(); i++){ distribution->expected_values[i] = this->expected_values[i].value_m; } distribution->dims.resize(2);