Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions inst/include/common/fims_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#define FIMS_VECTOR_HPP

#include "../interface/interface.hpp"
#include <ostream>
#include <iomanip>
#include <ostream>
#include <string>

namespace fims {

Expand Down Expand Up @@ -82,6 +83,8 @@ class Vector {
for (size_t i = 0; i < this->vec_m.size(); i++) {
this->vec_m[i] = other[i];
}
this->tag_m = other.tag_m;
this->variable_name_m = other.variable_name_m;
}

/**
Expand Down Expand Up @@ -142,7 +145,7 @@ class Vector {
*/
inline Type &operator[](size_t pos) {
if (pos >= this->size()) {
throw std::invalid_argument("fims::Vector out of bounds");
throw std::invalid_argument(this->get_out_of_bounds_error_message(pos));
}
return this->vec_m[pos];
}
Expand All @@ -153,7 +156,7 @@ class Vector {
*/
inline const Type &operator[](size_t n) const {
if (n >= this->size()) {
throw std::invalid_argument("fims::Vector out of bounds");
throw std::invalid_argument(this->get_out_of_bounds_error_message(n));
}
return this->vec_m[n];
}
Expand Down Expand Up @@ -480,8 +483,30 @@ class Vector {
*/
void set_tag(const std::string &tag) { this->tag_m = tag; }

/**
* @brief Gets the variable name for the vector.
* @return The variable name.
*/
std::string get_variable_name() const { return this->variable_name_m; }

/**
* @brief Sets the variable name for the vector.
*/
void set_variable_name(const std::string &name) { this->variable_name_m = name; }

private:
std::string get_out_of_bounds_error_message(size_t pos) const {
std::string error_msg = "fims::Vector out of bounds";
if (!this->variable_name_m.empty()) {
error_msg += " for " + this->variable_name_m;
}
error_msg += ": index " + std::to_string(pos + 1) + " >= size " +
std::to_string(this->size());
return error_msg;
}

std::string tag_m; /*!< The tag for the vector. */
std::string variable_name_m; /*!< The name of the variable represented by the vector. */
}; // end fims::Vector class

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase {
distribution->expected_values[i] =
this->expected_values[i].initial_value_m;
}
ss.str("");
ss << "dnorm." << this->id_m << ".log_sd";
distribution->log_sd.set_variable_name(ss.str());
distribution->log_sd.resize(this->log_sd.size());
for (size_t i = 0; i < this->log_sd.size(); i++) {
distribution->log_sd[i] = this->log_sd[i].initial_value_m;
Expand All @@ -487,6 +490,9 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase {
info->variable_map[this->log_sd.id_m] = &(distribution)->log_sd;

distribution->use_mean = this->use_mean_m.get();
ss.str("");
ss << "dnorm." << this->id_m << ".expected_mean";
distribution->expected_mean.set_variable_name(ss.str());
distribution->expected_mean.resize(this->expected_mean.size());
for (size_t i = 0; i < this->expected_mean.size(); i++) {
distribution->expected_mean[i] = this->expected_mean[i].initial_value_m;
Expand Down Expand Up @@ -810,6 +816,9 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase {
distribution->expected_values[i] =
this->expected_values[i].initial_value_m;
}
ss.str("");
ss << "dlnorm." << this->id_m << ".log_sd";
distribution->log_sd.set_variable_name(ss.str());
distribution->log_sd.resize(this->log_sd.size());
for (size_t i = 0; i < this->log_sd.size(); i++) {
distribution->log_sd[i] = this->log_sd[i].initial_value_m;
Expand Down
9 changes: 9 additions & 0 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ class FleetInterface : public FleetInterfaceBase {

fleet->fleet_selectivity_id_m = interface_selectivity_id_m.get();

ss.str("");
ss << "Fleet." << this->id << ".log_q";
fleet->log_q.set_variable_name(ss.str());
fleet->log_q.resize(this->log_q.size());
for (size_t i = 0; i < this->log_q.size(); i++) {
fleet->log_q[i] = this->log_q[i].initial_value_m;
Expand Down Expand Up @@ -484,6 +487,9 @@ class FleetInterface : public FleetInterfaceBase {
fims::to_string(this->n_years.get()));
}
fleet->log_Fmort.resize(static_cast<size_t>(this->log_Fmort.size()));
ss.str("");
ss << "Fleet." << this->id << ".log_Fmort";
fleet->log_Fmort.set_variable_name(ss.str());
for (size_t i = 0; i < log_Fmort.size(); i++) {
fleet->log_Fmort[i] = this->log_Fmort[i].initial_value_m;

Expand All @@ -504,6 +510,9 @@ class FleetInterface : public FleetInterfaceBase {
info->variable_map[this->log_Fmort.id_m] = &(fleet)->log_Fmort;

if (this->n_lengths.get() > 0) {
ss.str("");
ss << "Fleet." << this->id << ".age_to_length_conversion";
fleet->age_to_length_conversion.set_variable_name(ss.str());
fleet->age_to_length_conversion.resize(
this->age_to_length_conversion.size());

Expand Down
6 changes: 6 additions & 0 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ class LogisticMaturityInterface : public MaturityInterfaceBase {
// set relative info
maturity->id = this->id;
std::stringstream ss;
ss.str("");
ss << "Maturity." << this->id << ".inflection_point";
maturity->inflection_point.set_variable_name(ss.str());
maturity->inflection_point.resize(this->inflection_point.size());
for (size_t i = 0; i < this->inflection_point.size(); i++) {
maturity->inflection_point[i] = this->inflection_point[i].initial_value_m;
Expand All @@ -247,6 +250,9 @@ class LogisticMaturityInterface : public MaturityInterfaceBase {
}
}

ss.str("");
ss << "Maturity." << this->id << ".slope";
maturity->slope.set_variable_name(ss.str());
maturity->slope.resize(this->slope.size());
for (size_t i = 0; i < this->slope.size(); i++) {
maturity->slope[i] = this->slope[i].initial_value_m;
Expand Down
Loading