Skip to content

Commit

Permalink
add interface for length composition data to rcpp_data
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristineStawitz-NOAA committed Sep 12, 2024
1 parent 13455a5 commit 149fdef
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,73 @@ class AgeCompDataInterface : public DataInterfaceBase {
#endif
};

/**
* @brief Rcpp interface for length comp data as an S4 object. To instantiate
* from R:
* acomp <- new(LengthComp)
*/
class LengthCompDataInterface : public DataInterfaceBase {
public:
int lmax; /**< first dimension of the data */
int ymax; /**< second dimension of the data */
Rcpp::NumericVector length_comp_data; /**<the length composition data*/

/**
* @brief constructor
*/
LengthCompDataInterface(int ymax = 0, int lmax = 0) : DataInterfaceBase() {
this->lmax = lmax;
this->ymax = ymax;
}

/**
* @brief destructor
*/
virtual ~LengthCompDataInterface() {}

/** @brief get the ID of the interface base object
*/
virtual uint32_t get_id() { return this->id; }

#ifdef TMB_MODEL

template <typename Type>
bool add_to_fims_tmb_internal() {
std::shared_ptr<fims_data_object::DataObject<Type>> length_comp_data =
std::make_shared<fims_data_object::DataObject<Type>>(this->ymax,
this->lmax);

length_comp_data->id = this->id;
for (int y = 0; y < ymax; y++) {
for (int l = 0; l < lmax; l++) {
int i_length_year = y * lmax + l;
length_comp_data->at(y, a) = this->length_comp_data[i_length_year];
}
}

std::shared_ptr<fims_info::Information<Type>> info =
fims_info::Information<Type>::GetInstance();

info->data_objects[this->id] = length_comp_data;

return true;
}

/**
* @brief adds parameters to the model
*/
virtual bool add_to_fims_tmb() {
this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
this->add_to_fims_tmb_internal<TMB_FIMS_FIRST_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_SECOND_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_THIRD_ORDER>();

return true;
}

#endif
};

/**
* @brief Rcpp interface for data as an S4 object. To instantiate
* from R:
Expand Down

0 comments on commit 149fdef

Please sign in to comment.